ソースを参照

feat: 新增路由编号下拉多选

马大波 3 年 前
コミット
92a702e621
1 ファイル変更93 行追加55 行削除
  1. 93 55
      custom-form/src/components/DynamicForm/DynamicFormItem.jsx

+ 93 - 55
custom-form/src/components/DynamicForm/DynamicFormItem.jsx

@@ -6,6 +6,7 @@ moment.locale('zh-cn')
 
 export default {
   name: 'DynamicFormItem',
+  inject: ['getProcess'],
   props: {
     value: Object,
     form: Object
@@ -20,61 +21,98 @@ export default {
     let inputElement = (
       <a-input v-model={form[value.name]} maxLength={config.maxLength} />
     )
-    switch (uiType) {
-      case WidgetType.SELECT:
-        inputElement = (
-          <a-select v-model={form[value.name]}>
-            {value.config.option.map(o => (
-              <a-select-option value={o.value}>
-                {o.text}
-              </a-select-option>
-            ))}
-          </a-select>
-        )
-        break
-      case WidgetType.MULTI_SELECT:
-        inputElement = (
-          <a-select v-model={form[value.name]} mode="multiple">
-            {value.config.option.map(o => (
-              <a-select-option value={o.value}>
-                {o.text}
-              </a-select-option>
-            ))}
-          </a-select>
-        )
-        break
-      case WidgetType.CHECKBOX:
-        inputElement = (
-          <a-checkbox-group v-model={form[value.name]}>
-            {value.config.option.map(o => (
-              <a-checkbox value={o.value}>
-                {o.text}
-              </a-checkbox>
-            ))}
-          </a-checkbox-group>
-        )
-        break
-      case WidgetType.DATE:
-        inputElement = (
-          <a-date-picker
-            type="date"
-            showTime={true}
-            valueFormat={config.content || 'YYYY-MM-DD HH:mm:ss'}
-            format={config.content || 'YYYY-MM-DD HH:mm:ss'}
-            value={form[value.name] ? moment(form[value.name]) : null}
-            onChange={date => form[value.name] = date}
-          />
-        )
-        break
-      case WidgetType.TEXT_AREA:
-        inputElement = (
-          <a-textarea
-            v-model={form[value.name]}
-            rows={4}
-            maxLength={config.maxLength}
-          />
-        )
-        break
+    const isPlaceholder = typeof config.content === 'string' && config.content === '${cmptRouter.code}'
+    if (isPlaceholder && typeof this.getProcess === 'function') {
+      const process = this.getProcess()
+      const routeCodeList = process.filter(
+        item => item.type === 'cmpt'
+          && item.options.payload
+          && item.options.payload.cmptCategory === 'ROUTER'
+      ).map(
+        item => {
+          const { customForm, name } = item.options.payload
+          return {customForm, name}
+        }
+      ).filter(({ customForm }) => {
+        try {
+          const formObj = JSON.parse(customForm)
+          return typeof formObj.code === 'string'
+        } catch (e) {
+          return false
+        }
+      }).map(({ name, customForm }) => {
+        const { code } = JSON.parse(customForm)
+        return {
+          value: code,
+          label: `${code}(${name})`
+        }
+      })
+      inputElement = (
+        <a-select v-model={form[value.name]} mode="multiple">
+          {routeCodeList.map(o => (
+            <a-select-option value={o.value}>
+              {o.label}
+            </a-select-option>
+          ))}
+        </a-select>
+      )
+    } else {
+      switch (uiType) {
+        case WidgetType.SELECT:
+          inputElement = (
+            <a-select v-model={form[value.name]}>
+              {value.config.option.map(o => (
+                <a-select-option value={o.value}>
+                  {o.text}
+                </a-select-option>
+              ))}
+            </a-select>
+          )
+          break
+        case WidgetType.MULTI_SELECT:
+          inputElement = (
+            <a-select v-model={form[value.name]} mode="multiple">
+              {value.config.option.map(o => (
+                <a-select-option value={o.value}>
+                  {o.text}
+                </a-select-option>
+              ))}
+            </a-select>
+          )
+          break
+        case WidgetType.CHECKBOX:
+          inputElement = (
+            <a-checkbox-group v-model={form[value.name]}>
+              {value.config.option.map(o => (
+                <a-checkbox value={o.value}>
+                  {o.text}
+                </a-checkbox>
+              ))}
+            </a-checkbox-group>
+          )
+          break
+        case WidgetType.DATE:
+          inputElement = (
+            <a-date-picker
+              type="date"
+              showTime={true}
+              valueFormat={config.content || 'YYYY-MM-DD HH:mm:ss'}
+              format={config.content || 'YYYY-MM-DD HH:mm:ss'}
+              value={form[value.name] ? moment(form[value.name]) : null}
+              onChange={date => form[value.name] = date}
+            />
+          )
+          break
+        case WidgetType.TEXT_AREA:
+          inputElement = (
+            <a-textarea
+              v-model={form[value.name]}
+              rows={4}
+              maxLength={config.maxLength}
+            />
+          )
+          break
+      }
     }
     if (uiType !== WidgetType.INPUT && uiType !== WidgetType.TEXT_AREA) {
       verbText = '请选择'