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 @@ crud/vueImport.xml category-ref:dao + crud/vueFormChildList.xml @@ -31,17 +32,25 @@ crud/vueForm.xml crud/vueIndex.xml crud/vueImport.xml + + crud/vueFormChildList.xml + category-ref:crud_only_vue + + crud/vueFormChildList.xml + crud/vueApi.xml crud/vueList.xml - crud/vueFormRoute.xml crud/vueIndex.xml crud/vueImport.xml + + crud/vueFormChildList.xml + category-ref:crud @@ -55,6 +64,7 @@ crud/vueSelect.xml category-ref:dao + crud/vueFormChildList.xml @@ -83,6 +93,7 @@ crud/vueImport.xml category-ref:dao_cloud + crud/vueFormChildList.xml @@ -97,6 +108,7 @@ crud/vueSelect.xml category-ref:dao_cloud + crud/vueFormChildList.xml 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){ %> - - <% if(table.tplCategory != 'query'){ %> - - {{ t('新增') }} - - <% } %> + <% } %> @@ -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 @@ + + + + vueFormChildList + ${frontDir}/src/views/${urlPrefix} + form${@StringUtils.cap(table.classNameSimple)}List.vue + + + + + <% if(table.tplCategory != 'query'){ %> + + {{ t('新增') }} + + <% } %> + + + +<% %> +]]> + + \ 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 @@ - formImport + vueFormImport ${frontDir}/src/views/${urlPrefix} formImport.vue + <% if(toBoolean(table.optionMap['isHaveDisableEnable'])){ %> import { ${className}Disable, ${className}Enable } 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(modalOrDrawer == 'Drawer' && !@StringUtils.contains(table.tplCategory, '_route')){ %> + <% } %> + <% if(modalOrDrawer == 'Drawer' && !@StringUtils.contains(table.tplCategory, '_route')){ %> import { useDrawer } from '/@/components/Drawer'; -<% } %> -<% if(modalOrDrawer == 'Modal' || (toBoolean(table.optionMap['isBpmForm']) + <% } %> + <% if(modalOrDrawer == 'Modal' || (toBoolean(table.optionMap['isBpmForm']) || toBoolean(table.optionMap['isImportExport']))){ %> import { useModal } from '/@/components/Modal'; -<% } %> -<% if(toBoolean(table.optionMap['isBpmForm'])){ %> + <% } %> + <% if(toBoolean(table.optionMap['isBpmForm'])){ %> import { BpmRuntimeTrace } from '/@/components/Bpm'; -<% } %> + <% } %> import { FormProps } from '/@/components/Form'; -<% if(!@StringUtils.contains(table.tplCategory, '_route')) { %> + <% if(!@StringUtils.contains(table.tplCategory, '_route')) { %> import InputForm from './form.vue'; -<% } %> -<% if(toBoolean(table.optionMap['isImportExport'])){ %> + <% } %> + <% if(toBoolean(table.optionMap['isImportExport'])){ %> import FormImport from './formImport.vue'; -<% } %> -<% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])){ %> + <% } %> + <% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])){ %> const props = defineProps({ treeCode: String, }); -<% } %> -<% if(@StringUtils.contains(table.tplCategory, '_route')) { %> + <% } %> + <% if(@StringUtils.contains(table.tplCategory, '_route')) { %> const emitter = useEmitter(); -<% } %> + <% } %> const { t } = useI18n('${moduleName}${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${className}'); const { showMessage } = useMessage(); @@ -176,9 +176,9 @@ for(c in table.columnList){ icon: meta.icon || 'i-ant-design:book-outlined', value: meta.title || t('${functionNameSimple}管理'), }; -<% if(toBoolean(table.optionMap['isImportExport'])){ %> + <% if(toBoolean(table.optionMap['isImportExport'])){ %> const loading = ref(false); -<% } %> + <% } %> const searchForm: FormProps = { baseColProps: { md: 8, lg: 6 }, @@ -409,9 +409,6 @@ for(c in table.columnList){ ], }; - <% if(!@StringUtils.contains(table.tplCategory, '_route')) { %> - const [register${modalOrDrawer}, { open${modalOrDrawer} }] = use${modalOrDrawer}(); - <% } %> const [registerTable, { reload<% if(table.isTreeEntity){ %>, expandAll, collapseAll, expandCollapse<% } %><% if (table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk']) || toBoolean(table.optionMap['isImportExport'])){ %>, getForm<% } %> }] = useTable({ @@ -430,7 +427,11 @@ for(c in table.columnList){ <% } %> canResize: true, }); -<% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])){ %> + + <% if(!@StringUtils.contains(table.tplCategory, '_route')) { %> + const [register${modalOrDrawer}, { open${modalOrDrawer} }] = use${modalOrDrawer}(); + <% } %> + <% if(table.isTreeEntity || isNotBlank(table.optionMap['leftTreeRightTableFk'])){ %> watch( () => props.treeCode, @@ -447,15 +448,15 @@ for(c in table.columnList){ reload(); }, ); -<% } %> -<% if(table.isTreeEntity){ %> + <% } %> + <% if(table.isTreeEntity){ %> function fetchSuccess() { if (props.treeCode) { nextTick(expandAll); } } -<% } %> + <% } %> function handleForm(record: Recordable) { <% if(!@StringUtils.contains(table.tplCategory, '_route')) { %> @@ -467,7 +468,7 @@ for(c in table.columnList){ }); <% } %> } -<% if(toBoolean(table.optionMap['isImportExport'])){ %> + <% if(toBoolean(table.optionMap['isImportExport'])){ %> async function handleExport() { loading.value = true; @@ -484,8 +485,8 @@ for(c in table.columnList){ function handleImport() { importModal(true, {}); } -<% } %> -<% if(toBoolean(table.optionMap['isHaveDisableEnable'])){ %> + <% } %> + <% if(toBoolean(table.optionMap['isHaveDisableEnable'])){ %> async function handleDisable(record: Recordable) { const params = { ${idParam} }; @@ -500,7 +501,7 @@ for(c in table.columnList){ showMessage(res.message); handleSuccess(record); } -<% } %> + <% } %> async function handleDelete(record: Recordable) { const params = { ${idParam} };