zs
2025-04-28 adbd9157eeff10b3212417550525d8ff3102edae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { defineComponent, Fragment, ref } from 'vue'
import BaseDialog from '../BaseDialog/BaseDialog'
import { useVModel } from '@vueuse/core'
import styles from './ProjectConfig.module.scss'
import { getProjectConfig, createWidget } from '@/api/project-api'
import { menu, menuMap } from '@/config/menu'
import Icon from '../Icon/Icon'
import IconButton from '../IconButton/IconButton'
import DyForm from '../DyForm/DyForm'
import { ElLoading, ElMessage } from 'element-plus'
 
export default defineComponent({
  name: 'project',
  props: {
    modelValue: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, { emit }) {
    const visible = useVModel(props, 'modelValue', emit)
    const baseVisible = ref(false)
    const build = ref([])
    const local = ref([])
    const formData = ref({})
    const formRef = ref()
    const openType = ref(1)
    const onOpenDialog = async () => {
      const buildProd = await getProjectConfig('.build.prod')
      const localProd = await getProjectConfig('.build.local')
      if (buildProd) {
        try {
          build.value = (
            (buildProd.data && buildProd.data.split('\n')) ||
            []
          ).filter((v) => v)
          local.value = (
            (localProd.data && localProd.data.split('\n')) ||
            []
          ).filter((v) => v)
        } catch (error) {
          console.error(error)
        }
      }
    }
    const onConfirm = () => {
      visible.value = false
    }
    const onClose = () => {
      visible.value = false
    }
    const onAddWidget = (type: number) => {
      baseVisible.value = true
      openType.value = type
    }
    const onBaseConfirm = async () => {
      await formRef.value.validate()
      const loading = ElLoading.service({
        lock: true,
        text: '创建中,请稍后...',
        background: 'rgba(0, 0, 0, 0.7)',
      })
      loading.close()
      await createWidget({
        ...formData.value,
        type: openType.value,
        menu,
        menuMap,
      })
 
      onBaseClose()
    }
    const onBaseClose = () => {
      baseVisible.value = false
    }
    return () => {
      return (
        <Fragment>
          <BaseDialog
            onOpen={onOpenDialog}
            width="700px"
            title="项目配置"
            v-model={visible.value}
            onConfirm={onConfirm}
            onClose={onClose}
          >
            <div class={styles.projectConfig}>
              <div class={styles.leftPane}>
                <div class={styles.header}>
                  <h3 style="margin:0;">业务组件</h3>
                  <IconButton
                    onClick={() => onAddWidget(1)}
                    icon="add-p"
                    status="add"
                  >
                    添加
                  </IconButton>
                </div>
                <div class={styles.list}>
                  {local.value.length ? (
                    local.value.map((item) => (
                      <div class={styles.item}>
                        <div class={styles.itemContent}>
                          <span class={styles.span}>{menuMap[item]?.name}</span>
                        </div>
                        <el-tag>{item}</el-tag>
                      </div>
                    ))
                  ) : (
                    <el-empty style="margin-left: 39%;" />
                  )}
                </div>
              </div>
            </div>
          </BaseDialog>
          <BaseDialog
            title="添加组件"
            v-model={baseVisible.value}
            onConfirm={onBaseConfirm}
            onClose={onBaseClose}
          >
            <DyForm
              v-model:formData={formData.value}
              ref={formRef}
              formItemProps={[
                {
                  prop: 'widgetName',
                  label: '组件名称',
                  el: 'input',
                  placeholder: '请输入组件名称',
                  rules: [
                    {
                      required: true,
                      message: '请输入组件名称',
                    },
                  ],
                },
                {
                  prop: 'widgetId',
                  label: '组件ID',
                  placeholder: 'ProcessManagement',
                  el: 'input',
                  rules: [
                    {
                      required: true,
                      message: '请输入组件ID',
                    },
                    {
                      message: '首字母必须为大写,不能有数字和特殊符号',
                      pattern: /^[A-Z][A-Za-z]*$/,
                      trigger: 'blur',
                    },
                  ],
                },
              ]}
            ></DyForm>
          </BaseDialog>
        </Fragment>
      )
    }
  },
})