ソースを参照

fix:表单发布增加主键ID字段 ,修复动态表单时间搜索控件,修复子表控件回显问题

zcuishan 4 ヶ月 前
コミット
0ec6accdc6

+ 4 - 0
src/components/CreateCodeStep/src/ViewDesignStep.vue

@@ -1182,6 +1182,10 @@
       label: '创建时间',
       value: 'create_date',
     });
+    list.unshift({
+      label: t('主键ID'),
+      value: 'id',
+    });
     return list;
   });
 

+ 3 - 0
src/components/Designer/src/components/componentProperty/PropertyOption.vue

@@ -336,6 +336,9 @@
           <a-select-option value="YYYY" />
         </a-select>
       </a-form-item>
+      <a-form-item :label="t('显示时间')" v-if="hasKey('showTime') && (data.type == 'date-range')">
+        <a-switch v-model:checked="data.options.showTime"></a-switch>
+      </a-form-item>
 
       <template v-if="data.type === 'time'">
         <a-form-item :label="t('默认值')">

+ 10 - 0
src/components/Form/src/components/SubForm.vue

@@ -110,7 +110,11 @@
         :datasourceType="preloadType"
         :dicOptions="dicOptions"
         :apiConfig="apiConfig"
+        :labelField="labelField"
+        :valueField="valueField"
         :isSubFormUse="true"
+        :uniqueKey="uniqueKey"
+        v-model:selectedDataSource="selectedDataSourceVal"
         @submit="renderSubFormList"
         popupType="preload"
       />
@@ -141,6 +145,7 @@
   const MultipleSelectRef = ref();
   //const prereloadData = ref<Recordable[] | undefined>(undefined);
   const multipleDialog = ref<boolean>(false);
+  const selectedDataSourceVal = ref<any[]>([]);
   const emit = defineEmits(['change', 'update:value']);
 
   const props = defineProps({
@@ -179,6 +184,9 @@
       type: Boolean,
       default: false,
     },
+    // 格式化标题
+    labelField: { type: String, default: 'label' },
+    valueField: { type: String, default: 'value' },
     /**
      * 预加载数据为api时使用
      */
@@ -276,6 +284,7 @@
       //要保证在预加载之后在emit  不然预加载数据不会绑定到表单数据中
       emit('change', unref(data));
       emit('update:value', unref(data));
+      selectedDataSourceVal.value = data.value;
     },
     { deep: true },
   );
@@ -387,6 +396,7 @@
         data.value.push(dataObj);
       }
     });
+    console.log(data.value, 'valeu');
     emit('change', unref(data));
     emit('update:value', unref(data));
   };

+ 0 - 2
src/components/MultiplePopup/src/MultiplePopup.vue

@@ -130,11 +130,9 @@
         }
       });
     });
-
     showValueArr = selectedDataSourceVal.value?.map((item: any) => {
       return item[props.labelField!];
     });
-
     popupValue.value = showValueArr.length ? showValueArr.join(',') : props.value!;
   };
 

+ 22 - 11
src/components/MultiplePopup/src/components/MultipleSelect.vue

@@ -110,6 +110,7 @@
       type: Array as PropType<any[]>,
       default: () => [],
     },
+    uniqueKey: { type: String },
     dicOptions: { type: Array as PropType<any[]> },
     //数据来源 默认为空  如果不为空
     datasourceType: String,
@@ -216,17 +217,30 @@
       if (!state.dataSourceList.length) return;
       selectedList.value = [];
       state.selectedRowKeys = [];
-      state.dataSourceList.map((data: any, index: number) => {
-        data.key = index + 1;
-        if (props.value) {
+      if (!props.isSubFormUse) {
+        state.dataSourceList.map((data: any, index: number) => {
+          data.key = index + 1;
+          if (props.value) {
+            props.selectedDataSource.map((select: any) => {
+              if (data.key === select.key) {
+                selectedList.value.push(data);
+                state.selectedRowKeys.push(data.key);
+              }
+            });
+          }
+        });
+      }
+      if (props.isSubFormUse) {
+        state.dataSourceList.map((data: any, index: number) => {
+          data.key = index + 1;
           props.selectedDataSource.map((select: any) => {
-            if (data.key === select.key) {
+            if (select[props.uniqueKey!] === data[props.valueField!]) {
               selectedList.value.push(data);
               state.selectedRowKeys.push(data.key);
             }
           });
-        }
-      });
+        });
+      }
     },
     {
       deep: true,
@@ -389,18 +403,15 @@
   };
 
   const onSelectChange = (rowKeys, selectedRows) => {
-    if (!props.multiple){
+    if (!props.multiple) {
       selectedRows = selectedRows.slice(selectedRows.length - 1);
       rowKeys = rowKeys.slice(rowKeys.length - 1);
       state.selectedRowKeys = rowKeys;
       selectedList.value = selectedRows;
-
-    }
-    else {
+    } else {
       state.selectedRowKeys = rowKeys;
       selectedList.value = selectedRows;
     }
-
   };
 
   const deleteSelected = (record, index) => {

+ 2 - 2
src/utils/helper/exportHelper.ts

@@ -219,7 +219,7 @@ export const handleSearchForm = (option, schema, item, isNeedTrans, convertCamel
       ? `{
       field: '${camelCaseString(item.fieldName)}',
       label: '${schema!.label}',
-      component: 'RangePicker',
+      component: 'DatePicker',
       componentProps:{
         format:'${option.format}',
         style: { width: '100%' },
@@ -231,7 +231,7 @@ export const handleSearchForm = (option, schema, item, isNeedTrans, convertCamel
       : {
           field: item.fieldName,
           label: schema!.label,
-          component: 'RangePicker',
+          component: 'DatePicker',
           componentProps: {
             format: option.format,
             style: { width: '100%' },

+ 88 - 90
src/views/form/template/index.vue

@@ -323,80 +323,78 @@
   const [registerImportModal, { openModal: openImportModal }] = useModal();
   const [registerRuleUserModal, { openModal: openRuleUserModal }] = useModal();
 
-  const [
-    registerTable,
-    { reload, setProps, setSelectedRowKeys, getRawDataSource, setColumns },
-  ] = useTable({
-    title: '',
-    columns,
-    formConfig: {
-      rowProps: {
-        gutter: 16,
+  const [registerTable, { reload, setProps, setSelectedRowKeys, getRawDataSource, setColumns }] =
+    useTable({
+      title: '',
+      columns,
+      formConfig: {
+        rowProps: {
+          gutter: 16,
+        },
+        schemas: searchFormSchema,
       },
-      schemas: searchFormSchema,
-    },
-    beforeFetch: (pageParams) => {
-      //发送请求默认新增  左边树结构所选机构id
-      const newParams = {
-        releaseId: menuId.value,
-        params: pageParams,
-        order: pageParams.order,
-        field: pageParams.field,
-      };
-      pageParamsInfo.value = {
-        releaseId: menuId.value,
-        params: pageParams,
-      };
-      //如果有左侧菜单 需要加上左侧树 所选项  作为参数
-      if (listConfig.value.isLeftMenu) {
-        newParams[listConfig.value.leftMenuConfig?.listFieldName as string] =
-          pageParams[listConfig.value.leftMenuConfig?.listFieldName as string] || selectId.value;
-      }
-      newParams['headers'] = {
-        FormId: formIdComputedRef.value,
-        PK: pkField.value,
-      };
-      return newParams;
-    },
-    afterFetch: (res) => {
-      filterColumns.value.map((column: any) => {
-        if (column.onFilter) {
-          const info = res.map((item) => item[column.dataIndex!]);
-          column.filters = [...new Set(info)].map((item) => {
-            return {
-              text: item,
-              value: item,
-            };
-          });
-          column.customHeaderCell = () => {
-            return {
-              onmouseenter: () => {
-                isShowFilter.value = true;
-                showColumnIndex.value = column.dataIndex;
-                clickColumnIndex.value = '';
-              },
-              onmouseleave: () => {
-                isShowFilter.value = false;
-                showColumnIndex.value = '';
-              },
-            };
-          };
+      beforeFetch: (pageParams) => {
+        //发送请求默认新增  左边树结构所选机构id
+        const newParams = {
+          releaseId: menuId.value,
+          params: pageParams,
+          order: pageParams.order,
+          field: pageParams.field,
+        };
+        pageParamsInfo.value = {
+          releaseId: menuId.value,
+          params: pageParams,
+        };
+        //如果有左侧菜单 需要加上左侧树 所选项  作为参数
+        if (listConfig.value.isLeftMenu) {
+          newParams[listConfig.value.leftMenuConfig?.listFieldName as string] =
+            pageParams[listConfig.value.leftMenuConfig?.listFieldName as string] || selectId.value;
         }
-      });
-      setColumns(filterColumns.value);
-    },
-    useSearchForm: true,
-    showTableSetting: true,
-    striped: false,
-    isFilterByDataSoure: true,
-    actionColumn: {
-      width: 160,
-      title: t('操作'),
-      dataIndex: 'action',
-      slots: { customRender: 'action' },
-    },
-    customRow,
-  });
+        newParams['headers'] = {
+          FormId: formIdComputedRef.value,
+          PK: pkField.value,
+        };
+        return newParams;
+      },
+      afterFetch: (res) => {
+        filterColumns.value.map((column: any) => {
+          if (column.onFilter) {
+            const info = res.map((item) => item[column.dataIndex!]);
+            column.filters = [...new Set(info)].map((item) => {
+              return {
+                text: item,
+                value: item,
+              };
+            });
+            column.customHeaderCell = () => {
+              return {
+                onmouseenter: () => {
+                  isShowFilter.value = true;
+                  showColumnIndex.value = column.dataIndex;
+                  clickColumnIndex.value = '';
+                },
+                onmouseleave: () => {
+                  isShowFilter.value = false;
+                  showColumnIndex.value = '';
+                },
+              };
+            };
+          }
+        });
+        setColumns(filterColumns.value);
+      },
+      useSearchForm: true,
+      showTableSetting: true,
+      striped: false,
+      isFilterByDataSoure: true,
+      actionColumn: {
+        width: 160,
+        title: t('操作'),
+        dataIndex: 'action',
+        slots: { customRender: 'action' },
+      },
+      customRow,
+    });
 
   function handleFilterClick(column) {
     clickColumnIndex.value = column.dataIndex;
@@ -789,15 +787,15 @@
       formConfig: {
         labelWidth: 100,
         schemas: searchFormSchema,
-        fieldMapToTime: searchDate.map((date) => {
-          return [
-            date.fieldName!,
-            [date.fieldName + 'Start', date.fieldName + 'End'],
-            date.format,
-            true,
-          ];
-          // [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM-DD']],
-        }),
+        // fieldMapToTime: searchDate.map((date) => {
+        //   return [
+        //     date.fieldName!,
+        //     [date.fieldName + 'Start', date.fieldName + 'End'],
+        //     date.format,
+        //     true,
+        //   ];
+        //   // [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM-DD']],
+        // }),
       },
     });
     reload();
@@ -881,20 +879,18 @@
   async function fetchLeftData() {
     //如果是数据字典
     if (listConfig.value.leftMenuConfig?.datasourceType === 'dic') {
-      treeData.value =
-        ((await getDicDetailList({
-          itemId: listConfig.value.leftMenuConfig.dictionaryItemId,
-        })) as
-          unknown) as
-        TreeItem[];
+      treeData.value = (await getDicDetailList({
+        itemId: listConfig.value.leftMenuConfig.dictionaryItemId,
+      })) as unknown as TreeItem[];
     } else if (listConfig.value.leftMenuConfig?.datasourceType === 'static') {
       //如果是静态数据
       treeData.value = listConfig.value.leftMenuConfig.staticData!;
     } else if (listConfig.value.leftMenuConfig?.datasourceType === 'api') {
       //如果是api
-      treeData.value =
-        ((await apiConfigFunc(listConfig.value.leftMenuConfig?.apiConfig, false)) as unknown) as
-        TreeItem[];
+      treeData.value = (await apiConfigFunc(
+        listConfig.value.leftMenuConfig?.apiConfig,
+        false,
+      )) as unknown as TreeItem[];
     }
     addRenderIcon(treeData.value);
   }
@@ -931,6 +927,8 @@
 
       return handleSearchForm(option, schema, config, isNeedTrans, false) as FormSchema;
     });
+    console.log(searchFormSchema);
+
     return [searchFormSchema, searchDate];
   }