From 7d9b643edf4db4d4a97e7db4f8606fda04238844 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Tue, 8 Oct 2024 14:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=96=B0=E5=A2=9Evue=E5=AD=90=E8=A1=A8=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=E7=BB=84=E4=BB=B6=E7=9A=84=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/modules/gen/config.xml | 14 +- .../templates/modules/gen/crud/vueForm.xml | 280 +++--------------- .../modules/gen/crud/vueFormChildList.xml | 250 ++++++++++++++++ .../modules/gen/crud/vueFormRoute.xml | 2 +- .../templates/modules/gen/crud/vueImport.xml | 4 +- .../templates/modules/gen/crud/vueList.xml | 105 +++---- 6 files changed, 364 insertions(+), 291 deletions(-) create mode 100644 modules/core/src/main/resources/templates/modules/gen/crud/vueFormChildList.xml diff --git a/modules/core/src/main/resources/templates/modules/gen/config.xml b/modules/core/src/main/resources/templates/modules/gen/config.xml index 8c4a21d9..a7814d56 100644 --- a/modules/core/src/main/resources/templates/modules/gen/config.xml +++ b/modules/core/src/main/resources/templates/modules/gen/config.xml @@ -23,6 +23,7 @@ + @@ -31,17 +32,25 @@ + + + + + + - + + + @@ -55,6 +64,7 @@ + @@ -83,6 +93,7 @@ + @@ -97,6 +108,7 @@ + diff --git a/modules/core/src/main/resources/templates/modules/gen/crud/vueForm.xml b/modules/core/src/main/resources/templates/modules/gen/crud/vueForm.xml index 47845f76..ef316eba 100644 --- a/modules/core/src/main/resources/templates/modules/gen/crud/vueForm.xml +++ b/modules/core/src/main/resources/templates/modules/gen/crud/vueForm.xml @@ -29,15 +29,7 @@ <% for (child in table.childList){ %> <% } %> @@ -70,42 +62,42 @@ import { router } from '/@/router'; import { Icon } from '/@/components/Icon'; import { BasicForm, FormSchema, useForm } from '/@/components/Form'; -<% if (table.childList.~size > 0){ %> - import { BasicTable, useTable } from '/@/components/Table'; -<% } %> import { Basic${modalOrDrawer}, use${modalOrDrawer}Inner } from '/@/components/${modalOrDrawer}'; import { ${ClassName}, ${className}Save, ${className}Form<% if(table.isTreeEntity){ %>, ${className}TreeData<% } %> } from '/@/api/${moduleName}${isNotEmpty(subModuleName)?'/'+subModuleName:''}/${className}'; -<% -var userselectExists = false; -var officeselectExists = false; -var companyselectExists = false; -var areaselectExists = false; -for(c in table.columnList){ - if(c.isQuery == "1" && !c.isTreeEntityColumn){ - if(c.showType == 'userselect'){ - userselectExists = true; - }else if(c.showType == 'officeselect'){ - officeselectExists = true; - }else if(c.showType == 'companyselect'){ - companyselectExists = true; - }else if(c.showType == 'areaselect'){ - areaselectExists = true; + <% + var userselectExists = false; + var officeselectExists = false; + var companyselectExists = false; + var areaselectExists = false; + for(c in table.columnList){ + if(c.isQuery == "1" && !c.isTreeEntityColumn){ + if(c.showType == 'userselect'){ + userselectExists = true; + }else if(c.showType == 'officeselect'){ + officeselectExists = true; + }else if(c.showType == 'companyselect'){ + companyselectExists = true; + }else if(c.showType == 'areaselect'){ + areaselectExists = true; + } } } -} -%> -<% if(userselectExists || officeselectExists) { %> + %> + <% if(userselectExists || officeselectExists) { %> import { officeTreeData } from '/@/api/sys/office'; -<% } %> -<% if(companyselectExists) { %> + <% } %> + <% if(companyselectExists) { %> import { companyTreeData } from '/@/api/sys/company'; -<% } %> -<% if(areaselectExists) { %> + <% } %> + <% if(areaselectExists) { %> import { areaTreeData } from '/@/api/sys/area'; -<% } %> -<% if(toBoolean(table.optionMap['isBpmForm'])){ %> + <% } %> + <% if(toBoolean(table.optionMap['isBpmForm'])){ %> import { BpmButton } from '/@/components/Bpm'; -<% } %> + <% } %> + <% for (child in table.childList){ %> + import Form${@StringUtils.cap(child.classNameSimple)}List from './form${@StringUtils.cap(child.classNameSimple)}List.vue'; + <% } %> const emit = defineEmits(['success', 'register']); @@ -113,9 +105,12 @@ for(c in table.columnList){ const { showMessage } = useMessage(); const { meta } = unref(router.currentRoute); const record = ref<${ClassName}>({} as ${ClassName}); -<% if(toBoolean(table.optionMap['isBpmForm'])){ %> + <% for (child in table.childList){ %> + const form${@StringUtils.cap(child.classNameSimple)}ListRef = ref>(); + <% } %> + <% if(toBoolean(table.optionMap['isBpmForm'])){ %> const loadingRef = ref(false); -<% } %> + <% } %> const getTitle = computed(() => ({ icon: meta.icon || 'i-ant-design:book-outlined', @@ -135,7 +130,7 @@ for(c in table.columnList){ }, colProps: { md: 24, lg: 24 }, }, - <% } +<% } for (c in table.columnList){ if (c.isEdit == '1' && c.showType != 'hidden'){ // 如果是树结构的字段,则自动忽略 @@ -152,7 +147,7 @@ for (c in table.columnList){ isNewLine = true; } } -%> + %> { label: t('${c.columnLabel}'), field: '${c.attrName}', @@ -316,9 +311,8 @@ for (c in table.columnList){ }, <% } -} - if(toBoolean(table.optionMap['isImageUpload'])){ - %> +} %> + <% if(toBoolean(table.optionMap['isImageUpload'])){ %> { label: t('图片上传'), field: 'dataMap', @@ -333,8 +327,7 @@ for (c in table.columnList){ }, <% } - if(toBoolean(table.optionMap['isFileUpload'])){ - %> + if(toBoolean(table.optionMap['isFileUpload'])){ %> { label: t('附件上传'), field: 'dataMap', @@ -357,10 +350,9 @@ for (c in table.columnList){ colProps: { md: 24, lg: 24 }, slot: '${@StringUtils.uncap(child.classNameSimple)}List', }, -<% + <% } - if(false && toBoolean(table.optionMap['isBpmForm'])){ -%> + if(false && toBoolean(table.optionMap['isBpmForm'])){ %> { label: t('审批意见'), field: 'bpm.comment', @@ -403,9 +395,7 @@ for (c in table.columnList){ selectType: 'empUserSelect', }, }, -<% - } -%> +<% } %> ]; <% var updateSchemas = []; @@ -444,186 +434,6 @@ for (c in table.columnList){ <% var formColNum = table.optionMap['formColNum']; %> baseColProps: { md: 24, lg: ${formColNum=="1"?24:formColNum=="3"?8:12} }, }); -<% for (child in table.childList){ %> - - const [register${child.className}Table, ${@StringUtils.uncap(child.classNameSimple)}Table] = useTable({ - actionColumn: { - width: 60, - actions: (record: Recordable) => [ - { - icon: 'i-ant-design:delete-outlined', - color: 'error', - popConfirm: { - title: '是否确认删除', - confirm: handle${child.className}Delete.bind(this, record), - }, - auth: '${permissionPrefix}:edit', - }, - ], - }, - rowKey: 'id', - pagination: false, - bordered: true, - size: 'small', - inset: true, - }); - - async function set${child.className}TableData(_res: Recordable) { - ${@StringUtils.uncap(child.classNameSimple)}Table.setColumns([ - <% - for (c in child.columnList){ - if (c.isEdit != '1' || c.isPk == '1'){ - continue; - } - if(child.parentExists && child.parentTableFkName == c.columnName){ - continue; - } - %> - { - title: t('${c.columnLabel}'), - dataIndex: '${c.attrName}', - <% if(c.showType == 'datetime'){ %> - width: 215, - <% }else{ %> - width: 130, - <% } %> - <% if ((isNotBlank(c.optionMap['dictType']) || @StringUtils.inString(c.attrType, 'java.util.Date', 'Integer', 'Long'))){ %> - align: 'center', - <% }else if (@StringUtils.inString(c.attrType, 'Float', 'Double')){ %> - align: 'right', - <% }else{ %> - align: 'left', - <% } %> - <% if(c.showType == 'select' || c.showType == 'select_multiple' || c.showType == 'checkbox' || c.showType == 'radio'){ %> - dictType: '${c.optionMap['dictType']}', - <% } %> - editRow: true, - <% if(c.showType == 'input' || c.showType == 'textarea'){ %> - <% if (c.simpleAttrType == 'Integer' && c.attrName == 'treeSort'){ %> - editComponent: 'InputNumber', - editDefaultValue: '30', - <% }else{ %> - editComponent: '${c.showType == 'input' ? 'Input' : 'InputTextArea'}', - <% } %> - <% if (c.dataLength != '0'){ %> - editComponentProps: { - maxlength: ${c.dataLength}, - }, - <% } %> - <% }else if(c.showType == 'select' || c.showType == 'select_multiple' || c.showType == 'radio' || c.showType == 'checkbox'){ - var isMultiple = (c.showType == 'select_multiple'); %> - editComponent: 'Select', - editComponentProps: { - dictType: '${c.optionMap['dictType']}', - allowClear: true, - <% if(isMultiple){ %> - mode: 'multiple', - <% } %> - }, - <% }else if(c.showType == 'date' || c.showType == 'datetime'){ - var isTime = (c.showType == 'datetime'); %> - editComponent: 'DatePicker', - editComponentProps: { - format: 'YYYY-MM-DD${isTime?' HH:mm':''}', - showTime: ${isTime?'{ format: \'HH:mm\' \}':'false'}, - }, - <% }else if(c.showType == 'userselect'){ - if (isNotBlank(c.attrName2)){ %> - dataLabel: '${c.attrName2}', - <% } %> - editComponent: 'TreeSelect', - editComponentProps: { - api: officeTreeData, - params: { isLoadUser: true, userIdPrefix: '' }, - canSelectParent: false, - allowClear: true, - }, - <% }else if(c.showType == 'officeselect'){ - if (isNotBlank(c.attrName2)){ %> - dataLabel: '${c.attrName2}', - <% } %> - editComponent: 'TreeSelect', - editComponentProps: { - api: officeTreeData, - canSelectParent: false, - allowClear: true, - }, - <% }else if(c.showType == 'companyselect'){ - if (isNotBlank(c.attrName2)){ %> - dataLabel: '${c.attrName2}', - <% } %> - editComponent: 'TreeSelect', - editComponentProps: { - api: companyTreeData, - canSelectParent: false, - allowClear: true, - }, - <% }else if(c.showType == 'areaselect'){ - if (isNotBlank(c.attrName2)){ %> - dataLabel: '${c.attrName2}', - <% } %> - editComponent: 'TreeSelect', - editComponentProps: { - api: areaTreeData, - canSelectParent: false, - allowClear: true, - }, - <% }else{ %> - editComponent: 'Input', - <% } %> - editRule: ${c.isRequired == '1'}, - }, - <% - } - %> - ]); - ${@StringUtils.uncap(child.classNameSimple)}Table.setTableData(record.value.${@StringUtils.uncap(child.classNameSimple)}List || []); - } - - function handle${child.className}RowClick(record: Recordable) { - record.onEdit?.(true, false); - } - - function handle${child.className}Add() { - ${@StringUtils.uncap(child.classNameSimple)}Table.insertTableDataRecord({ - id: new Date().getTime(), - isNewRecord: true, - editable: true, - }); - } - - function handle${child.className}Delete(record: Recordable) { - ${@StringUtils.uncap(child.classNameSimple)}Table.deleteTableDataRecord(record); - } - - async function get${child.className}List() { - let ${@StringUtils.uncap(child.classNameSimple)}ListValid = true; - let ${@StringUtils.uncap(child.classNameSimple)}List: Recordable[] = []; - for (const record of ${@StringUtils.uncap(child.classNameSimple)}Table.getDataSource()) { - if (!(await record.onEdit?.(false, true))) { - ${@StringUtils.uncap(child.classNameSimple)}ListValid = false; - } - ${@StringUtils.uncap(child.classNameSimple)}List.push({ - ...record, - id: !!record.isNewRecord ? '' : record.id, - }); - } - for (const record of ${@StringUtils.uncap(child.classNameSimple)}Table.getDelDataSource()) { - if (!!record.isNewRecord) continue; - ${@StringUtils.uncap(child.classNameSimple)}List.push({ - ...record, - status: '1', - }); - } - if (!${@StringUtils.uncap(child.classNameSimple)}ListValid) { - throw { - errorFields: [{ name: ['${@StringUtils.uncap(child.classNameSimple)}List'] }], - message: t('${child.comments}填写有误,请根据提示修正'), - }; - } - return ${@StringUtils.uncap(child.classNameSimple)}List; - } -<% } %> const [register${modalOrDrawer}, { set${modalOrDrawer}Props, close${modalOrDrawer} }] = use${modalOrDrawer}Inner(async (data) => { set${modalOrDrawer}Props({ loading: true }); @@ -639,7 +449,7 @@ for (c in table.columnList){ <% } %> setFieldsValue(record.value); <% for (child in table.childList){ %> - set${child.className}TableData(res); + form${@StringUtils.cap(child.classNameSimple)}ListRef.value?.setTableData(record.value); <% } %> <% if(updateSchemas.~size > 0){ %> updateSchema([ @@ -658,7 +468,7 @@ for (c in table.columnList){ formData(true, data); // 将表单数据传递给 BpmButton } catch (error: any) { if (error && error.errorFields) { - showMessage(t('common.validateError')); + showMessage(error.message || t('common.validateError')); } console.log('error', error); } @@ -688,7 +498,7 @@ for (c in table.columnList){ %> }; <% for (child in table.childList){ %> - data.${@StringUtils.uncap(child.classNameSimple)}List = await get${child.className}List(); + await form${@StringUtils.cap(child.classNameSimple)}ListRef.value?.getTableData(data); <% } %> <% if(table.isTreeEntity){ %> data.oldParentCode = record.value.parentCode; diff --git a/modules/core/src/main/resources/templates/modules/gen/crud/vueFormChildList.xml b/modules/core/src/main/resources/templates/modules/gen/crud/vueFormChildList.xml new file mode 100644 index 00000000..16dd9d44 --- /dev/null +++ b/modules/core/src/main/resources/templates/modules/gen/crud/vueFormChildList.xml @@ -0,0 +1,250 @@ + + + \ No newline at end of file diff --git a/modules/core/src/main/resources/templates/modules/gen/crud/vueFormRoute.xml b/modules/core/src/main/resources/templates/modules/gen/crud/vueFormRoute.xml index f4c133d5..7f46ad2a 100644 --- a/modules/core/src/main/resources/templates/modules/gen/crud/vueFormRoute.xml +++ b/modules/core/src/main/resources/templates/modules/gen/crud/vueFormRoute.xml @@ -713,7 +713,7 @@ for (c in table.columnList){ formData(true, data); // 将表单数据传递给 BpmButton } catch (error: any) { if (error && error.errorFields) { - showMessage(t('common.validateError')); + showMessage(error.message || t('common.validateError')); } console.log('error', error); } diff --git a/modules/core/src/main/resources/templates/modules/gen/crud/vueImport.xml b/modules/core/src/main/resources/templates/modules/gen/crud/vueImport.xml index ddfdc638..9e4962cd 100644 --- a/modules/core/src/main/resources/templates/modules/gen/crud/vueImport.xml +++ b/modules/core/src/main/resources/templates/modules/gen/crud/vueImport.xml @@ -2,7 +2,7 @@