Commit 2d0f989968e953f67aa13aefaf97098a8a142bf8
1 parent
b3a40af2
【功能新增】代码生成: vue3_vben5_antd schema 主子表 erp 模板
Showing
4 changed files
with
221 additions
and
203 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm
| @@ -393,6 +393,55 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] { | @@ -393,6 +393,55 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] { | ||
| 393 | ]; | 393 | ]; |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | +/** 列表的搜索表单 */ | ||
| 397 | +export function use${subSimpleClassName}GridFormSchema(): VbenFormSchema[] { | ||
| 398 | + return [ | ||
| 399 | + #foreach($column in $subColumns) | ||
| 400 | + #if ($column.listOperation) | ||
| 401 | + #set ($dictType = $column.dictType) | ||
| 402 | + #set ($javaType = $column.javaType) | ||
| 403 | + #set ($javaField = $column.javaField) | ||
| 404 | + #set ($comment = $column.columnComment) | ||
| 405 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | ||
| 406 | + #set ($dictMethod = "number") | ||
| 407 | + #elseif ($javaType == "String") | ||
| 408 | + #set ($dictMethod = "string") | ||
| 409 | + #elseif ($javaType == "Boolean") | ||
| 410 | + #set ($dictMethod = "boolean") | ||
| 411 | + #end | ||
| 412 | + { | ||
| 413 | + fieldName: '${javaField}', | ||
| 414 | + label: '${comment}', | ||
| 415 | + #if ($column.htmlType == "input" || $column.htmlType == "textarea" || $column.htmlType == "editor") | ||
| 416 | + component: 'Input', | ||
| 417 | + componentProps: { | ||
| 418 | + allowClear: true, | ||
| 419 | + placeholder: '请输入${comment}', | ||
| 420 | + }, | ||
| 421 | + #elseif ($column.htmlType == "select" || $column.htmlType == "radio") | ||
| 422 | + component: 'Select', | ||
| 423 | + componentProps: { | ||
| 424 | + allowClear: true, | ||
| 425 | + #if ("" != $dictType)## 设置了 dictType 数据字典的情况 | ||
| 426 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'), | ||
| 427 | + #else## 未设置 dictType 数据字典的情况 | ||
| 428 | + options: [], | ||
| 429 | + #end | ||
| 430 | + placeholder: '请选择${comment}', | ||
| 431 | + }, | ||
| 432 | + #elseif($column.htmlType == "datetime") | ||
| 433 | + component: 'RangePicker', | ||
| 434 | + componentProps: { | ||
| 435 | + ...getRangePickerDefaultProps(), | ||
| 436 | + allowClear: true, | ||
| 437 | + }, | ||
| 438 | + #end | ||
| 439 | + }, | ||
| 440 | + #end | ||
| 441 | + #end | ||
| 442 | + ]; | ||
| 443 | +} | ||
| 444 | + | ||
| 396 | /** 列表的字段 */ | 445 | /** 列表的字段 */ |
| 397 | export function use${subSimpleClassName}GridColumns( | 446 | export function use${subSimpleClassName}GridColumns( |
| 398 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, | 447 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, |
| @@ -436,11 +485,11 @@ export function use${subSimpleClassName}GridColumns( | @@ -436,11 +485,11 @@ export function use${subSimpleClassName}GridColumns( | ||
| 436 | options: [ | 485 | options: [ |
| 437 | { | 486 | { |
| 438 | code: 'edit', | 487 | code: 'edit', |
| 439 | - show: hasAccessByCodes(['${subTable.moduleName}:${subSimpleClassName_strikeCase}:update']), | 488 | + show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:update']), |
| 440 | }, | 489 | }, |
| 441 | { | 490 | { |
| 442 | code: 'delete', | 491 | code: 'delete', |
| 443 | - show: hasAccessByCodes(['${subTable.moduleName}:${subSimpleClassName_strikeCase}:delete']), | 492 | + show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']), |
| 444 | }, | 493 | }, |
| 445 | ], | 494 | ], |
| 446 | }, | 495 | }, |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm
| @@ -28,9 +28,12 @@ import { downloadByData } from '#/utils/download'; | @@ -28,9 +28,12 @@ import { downloadByData } from '#/utils/download'; | ||
| 28 | 28 | ||
| 29 | import { useGridColumns, useGridFormSchema } from './data'; | 29 | import { useGridColumns, useGridFormSchema } from './data'; |
| 30 | 30 | ||
| 31 | -#if ($table.templateType == 12) ## 内嵌情况 | 31 | +#if ($table.templateType == 12 || $table.templateType == 11) ## 内嵌和erp情况 |
| 32 | /** 子表的列表 */ | 32 | /** 子表的列表 */ |
| 33 | const subTabsName = ref('$subClassNameVars.get(0)') | 33 | const subTabsName = ref('$subClassNameVars.get(0)') |
| 34 | +#if ($table.templateType == 11) | ||
| 35 | +const select${simpleClassName} = ref<${simpleClassName}Api.${simpleClassName}>(); | ||
| 36 | +#end | ||
| 34 | #end | 37 | #end |
| 35 | 38 | ||
| 36 | const [FormModal, formModalApi] = useVbenModal({ | 39 | const [FormModal, formModalApi] = useVbenModal({ |
| @@ -127,7 +130,11 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -127,7 +130,11 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 127 | }, | 130 | }, |
| 128 | gridOptions: { | 131 | gridOptions: { |
| 129 | columns: useGridColumns(onActionClick), | 132 | columns: useGridColumns(onActionClick), |
| 133 | +#if (${table.templateType} == 11) | ||
| 134 | + height: '600px', | ||
| 135 | +#else | ||
| 130 | height: 'auto', | 136 | height: 'auto', |
| 137 | +#end | ||
| 131 | #if (${table.templateType} == 2)## 树表设置 | 138 | #if (${table.templateType} == 2)## 树表设置 |
| 132 | treeConfig: { | 139 | treeConfig: { |
| 133 | parentField: '${treeParentColumn.javaField}', | 140 | parentField: '${treeParentColumn.javaField}', |
| @@ -164,12 +171,22 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -164,12 +171,22 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 164 | rowConfig: { | 171 | rowConfig: { |
| 165 | keyField: 'id', | 172 | keyField: 'id', |
| 166 | isHover: true, | 173 | isHover: true, |
| 174 | +#if (${table.templateType} == 11) | ||
| 175 | + isCurrent: true, | ||
| 176 | +#end | ||
| 167 | }, | 177 | }, |
| 168 | toolbarConfig: { | 178 | toolbarConfig: { |
| 169 | refresh: { code: 'query' }, | 179 | refresh: { code: 'query' }, |
| 170 | search: true, | 180 | search: true, |
| 171 | }, | 181 | }, |
| 172 | } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>, | 182 | } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>, |
| 183 | +#if (${table.templateType} == 11) | ||
| 184 | + gridEvents:{ | ||
| 185 | + cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => { | ||
| 186 | + select${simpleClassName}.value = row; | ||
| 187 | + }, | ||
| 188 | + } | ||
| 189 | +#end | ||
| 173 | }); | 190 | }); |
| 174 | </script> | 191 | </script> |
| 175 | 192 | ||
| @@ -177,6 +194,9 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -177,6 +194,9 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 177 | <Page auto-content-height> | 194 | <Page auto-content-height> |
| 178 | <FormModal @success="onRefresh" /> | 195 | <FormModal @success="onRefresh" /> |
| 179 | 196 | ||
| 197 | +#if ($table.templateType == 11) ## erp情况 | ||
| 198 | + <div> | ||
| 199 | +#end | ||
| 180 | <Grid table-title="${table.classComment}列表"> | 200 | <Grid table-title="${table.classComment}列表"> |
| 181 | #if ($table.templateType == 12) ## 内嵌情况 | 201 | #if ($table.templateType == 12) ## 内嵌情况 |
| 182 | <template #expand_content="{ row }"> | 202 | <template #expand_content="{ row }"> |
| @@ -214,5 +234,21 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -214,5 +234,21 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 214 | </Button> | 234 | </Button> |
| 215 | </template> | 235 | </template> |
| 216 | </Grid> | 236 | </Grid> |
| 237 | + | ||
| 238 | +#if ($table.templateType == 11) ## erp情况 | ||
| 239 | + <!-- 子表的表单 --> | ||
| 240 | + <Tabs v-model:active-key="subTabsName" class="mt-2"> | ||
| 241 | + #foreach ($subTable in $subTables) | ||
| 242 | + #set ($index = $foreach.count - 1) | ||
| 243 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | ||
| 244 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 245 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | ||
| 246 | + <Tabs.TabPane key="$subClassNameVar" tab="${subTable.classComment}" force-render> | ||
| 247 | + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="select${simpleClassName}?.id" /> | ||
| 248 | + </Tabs.TabPane> | ||
| 249 | + #end | ||
| 250 | + </Tabs> | ||
| 251 | + </div> | ||
| 252 | +#end | ||
| 217 | </Page> | 253 | </Page> |
| 218 | </template> | 254 | </template> |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/form_sub_erp.vue.vm
| @@ -2,192 +2,85 @@ | @@ -2,192 +2,85 @@ | ||
| 2 | #set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 | 2 | #set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 |
| 3 | #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | 3 | #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 |
| 4 | #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | 4 | #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) |
| 5 | -#set ($subClassNameVar = $subClassNameVars.get($subIndex)) | ||
| 6 | -#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | ||
| 7 | <script lang="ts" setup> | 5 | <script lang="ts" setup> |
| 8 | import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | 6 | import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; |
| 9 | 7 | ||
| 10 | - import { computed, ref, h, onMounted,watch,nextTick } from 'vue'; | ||
| 11 | - import { $t } from '#/locales'; | ||
| 12 | - | ||
| 13 | -#if ($subTable.subJoinMany) ## 一对多 | ||
| 14 | -import { Plus } from "@vben/icons"; | ||
| 15 | -import { Button, Tabs, Checkbox, Input, Textarea, Select,RadioGroup,CheckboxGroup, DatePicker } from 'ant-design-vue'; | ||
| 16 | -import type { OnActionClickParams } from '#/adapter/vxe-table'; | ||
| 17 | -import { useVbenVxeGrid } from '#/adapter/vxe-table'; | ||
| 18 | -import { use${subSimpleClassName}GridColumns } from '../data'; | ||
| 19 | -import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | ||
| 20 | -#else | ||
| 21 | -import { useVbenForm } from '#/adapter/form'; | ||
| 22 | -import { use${subSimpleClassName}FormSchema } from '../data'; | ||
| 23 | -import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | ||
| 24 | -#end | ||
| 25 | - | ||
| 26 | -const props = defineProps<{ | ||
| 27 | - ${subJoinColumn.javaField}?: any // ${subJoinColumn.columnComment}(主表的关联字段) | ||
| 28 | -}>() | ||
| 29 | - | ||
| 30 | -#if ($subTable.subJoinMany) ## 一对多 | ||
| 31 | -/** 表格操作按钮的回调函数 */ | ||
| 32 | -function onActionClick({ | ||
| 33 | - code, | ||
| 34 | - row, | ||
| 35 | - }: OnActionClickParams<${simpleClassName}Api.${subSimpleClassName}>) { | ||
| 36 | -switch (code) { | ||
| 37 | - case 'delete': { | ||
| 38 | - onDelete(row); | ||
| 39 | - break; | ||
| 40 | - } | ||
| 41 | -} | ||
| 42 | -} | 8 | + import { useVbenModal } from '@vben/common-ui'; |
| 9 | + import { message } from 'ant-design-vue'; | ||
| 43 | 10 | ||
| 44 | -const [${subSimpleClassName}Grid, ${subClassNameVar}GridApi] = useVbenVxeGrid({ | ||
| 45 | -gridOptions: { | ||
| 46 | - columns: use${subSimpleClassName}GridColumns(onActionClick), | ||
| 47 | - border: true, | ||
| 48 | - showOverflow: true, | ||
| 49 | - autoResize: true, | ||
| 50 | - keepSource: true, | ||
| 51 | - rowConfig: { | ||
| 52 | - keyField: 'id', | ||
| 53 | - }, | ||
| 54 | - pagerConfig: { | ||
| 55 | - enabled: false, | ||
| 56 | - }, | ||
| 57 | - toolbarConfig: { | ||
| 58 | - enabled: false, | ||
| 59 | - }, | ||
| 60 | -}, | ||
| 61 | -}); | ||
| 62 | - | ||
| 63 | -/** 删除${subTable.classComment} */ | ||
| 64 | -const onDelete = async (row: ${simpleClassName}Api.${subSimpleClassName}) => { | ||
| 65 | -await ${subClassNameVar}GridApi.grid.remove(row); | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -/** 添加${subTable.classComment} */ | ||
| 69 | -const handleAdd = async () => { | ||
| 70 | -await ${subClassNameVar}GridApi.grid.insertAt({} as ${simpleClassName}Api.${subSimpleClassName}, -1); | ||
| 71 | -} | 11 | + import { computed, ref } from 'vue'; |
| 12 | + import { $t } from '#/locales'; | ||
| 13 | + import { useVbenForm } from '#/adapter/form'; | ||
| 14 | + import { get${subSimpleClassName}, create${subSimpleClassName}, update${subSimpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | ||
| 72 | 15 | ||
| 73 | -/** 提供获取表格数据的方法供父组件调用 */ | ||
| 74 | -defineExpose({ | ||
| 75 | -getData: (): ${simpleClassName}Api.${subSimpleClassName}[] => { | ||
| 76 | - return [ | ||
| 77 | - ...${subClassNameVar}GridApi.grid.getData(), | ||
| 78 | - ...${subClassNameVar}GridApi.grid.getInsertRecords().map((row) => { | ||
| 79 | - delete row.id; | ||
| 80 | - return row; | ||
| 81 | - }), | ||
| 82 | - ]; | ||
| 83 | -}, | ||
| 84 | -}); | 16 | + import { use${subSimpleClassName}FormSchema } from '../data'; |
| 85 | 17 | ||
| 86 | -/** 监听主表的关联字段的变化,加载对应的子表数据 */ | ||
| 87 | -watch( | ||
| 88 | - () => props.${subJoinColumn.javaField}, | ||
| 89 | - async (val) => { | ||
| 90 | - if (!val) { | ||
| 91 | - return; | ||
| 92 | - } | 18 | + const emit = defineEmits(['success']); |
| 19 | + const formData = ref<${simpleClassName}Api.${subSimpleClassName}>(); | ||
| 20 | + const getTitle = computed(() => { | ||
| 21 | + return formData.value?.id | ||
| 22 | + ? $t('ui.actionTitle.edit', ['${subTable.classComment}']) | ||
| 23 | + : $t('ui.actionTitle.create', ['${subTable.classComment}']); | ||
| 24 | + }); | ||
| 93 | 25 | ||
| 94 | - await nextTick(); | ||
| 95 | - await ${subClassNameVar}GridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!)); | ||
| 96 | - }, | ||
| 97 | -); | ||
| 98 | -#else | ||
| 99 | -const [${subSimpleClassName}Form, ${subClassNameVar}FormApi] = useVbenForm({ | ||
| 100 | -layout: 'horizontal', | ||
| 101 | -schema: use${subSimpleClassName}FormSchema(), | ||
| 102 | -showDefaultActions: false | ||
| 103 | -}); | 26 | + const [Form, formApi] = useVbenForm({ |
| 27 | + layout: 'horizontal', | ||
| 28 | + schema: use${subSimpleClassName}FormSchema(), | ||
| 29 | + showDefaultActions: false | ||
| 30 | + }); | ||
| 104 | 31 | ||
| 105 | -/** 暴露出表单校验方法和表单值获取方法 */ | ||
| 106 | -defineExpose({ | ||
| 107 | -validate: async () => { | ||
| 108 | - const { valid } = await ${subClassNameVar}FormApi.validate(); | ||
| 109 | - return valid; | ||
| 110 | -}, | ||
| 111 | -getValues: ${subClassNameVar}FormApi.getValues, | ||
| 112 | -}); | 32 | + const [Modal, modalApi] = useVbenModal({ |
| 33 | + async onConfirm() { | ||
| 34 | + const { valid } = await formApi.validate(); | ||
| 35 | + if (!valid) { | ||
| 36 | + return; | ||
| 37 | + } | ||
| 113 | 38 | ||
| 114 | -/** 监听主表的关联字段的变化,加载对应的子表数据 */ | ||
| 115 | -watch( | ||
| 116 | - () => props.${subJoinColumn.javaField}, | ||
| 117 | - async (val) => { | ||
| 118 | - if (!val) { | ||
| 119 | - return; | ||
| 120 | - } | 39 | + modalApi.lock(); |
| 40 | + // 提交表单 | ||
| 41 | + const data = (await formApi.getValues()) as ${simpleClassName}Api.${subSimpleClassName}; | ||
| 42 | + data.${subJoinColumn.javaField} = formData.value?.${subJoinColumn.javaField}; | ||
| 43 | + try { | ||
| 44 | + await (formData.value?.id ? update${subSimpleClassName}(data) : create${subSimpleClassName}(data)); | ||
| 45 | + // 关闭并提示 | ||
| 46 | + await modalApi.close(); | ||
| 47 | + emit('success'); | ||
| 48 | + message.success({ | ||
| 49 | + content: $t('ui.actionMessage.operationSuccess'), | ||
| 50 | + key: 'action_process_msg', | ||
| 51 | + }); | ||
| 52 | + } finally { | ||
| 53 | + modalApi.lock(false); | ||
| 54 | + } | ||
| 55 | + }, | ||
| 56 | + async onOpenChange(isOpen: boolean) { | ||
| 57 | + if (!isOpen) { | ||
| 58 | + formData.value = undefined; | ||
| 59 | + return; | ||
| 60 | + } | ||
| 121 | 61 | ||
| 122 | - await nextTick(); | ||
| 123 | - await ${subClassNameVar}FormApi.setValues(await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!)); | ||
| 124 | - }, | ||
| 125 | -); | ||
| 126 | -#end | 62 | + // 加载数据 |
| 63 | + let data = modalApi.getData<${simpleClassName}Api.${subSimpleClassName}>(); | ||
| 64 | + if (!data) { | ||
| 65 | + return; | ||
| 66 | + } | ||
| 67 | + if (data.id) { | ||
| 68 | + modalApi.lock(); | ||
| 69 | + try { | ||
| 70 | + data = await get${subSimpleClassName}(data.id); | ||
| 71 | + } finally { | ||
| 72 | + modalApi.lock(false); | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + // 设置到 values | ||
| 76 | + formData.value = data; | ||
| 77 | + await formApi.setValues(formData.value); | ||
| 78 | + }, | ||
| 79 | + }); | ||
| 127 | </script> | 80 | </script> |
| 128 | 81 | ||
| 129 | <template> | 82 | <template> |
| 130 | - #if ($subTable.subJoinMany) ## 一对多 | ||
| 131 | - <${subSimpleClassName}Grid class="mx-4"> | ||
| 132 | - #foreach($column in $subColumns) | ||
| 133 | - #if ($column.createOperation || $column.updateOperation) | ||
| 134 | - #set ($javaField = $column.javaField) | ||
| 135 | - #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | ||
| 136 | - #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | ||
| 137 | - <template #${javaField}="{ row }"> | ||
| 138 | - <Input v-model:value="row.${javaField}" /> | ||
| 139 | - </template> | ||
| 140 | - #elseif($column.htmlType == "imageUpload")## 图片上传 | ||
| 141 | - <template #${javaField}="{ row }"> | ||
| 142 | - <UploadImg v-model:value="row.${javaField}" /> | ||
| 143 | - </template> | ||
| 144 | - #elseif($column.htmlType == "fileUpload")## 文件上传 | ||
| 145 | - <template #${javaField}="{ row }"> | ||
| 146 | - <UploadFile v-model:value="row.${javaField}" /> | ||
| 147 | - </template> | ||
| 148 | - #elseif($column.htmlType == "editor")## 文本编辑器 | ||
| 149 | - <template #${javaField}="{ row }"> | ||
| 150 | - <Textarea v-model:value="row.${javaField}" /> | ||
| 151 | - </template> | ||
| 152 | - #elseif($column.htmlType == "select")## 下拉框 | ||
| 153 | - <template #${javaField}="{ row, column }"> | ||
| 154 | - <Select v-model:value="row.${javaField}" class="w-full"> | ||
| 155 | - <Select.Option v-for="option in column.params.options" :key="option.value" :value="option.value"> | ||
| 156 | - {{ option.label }} | ||
| 157 | - </Select.Option> | ||
| 158 | - </Select> | ||
| 159 | - </template> | ||
| 160 | - #elseif($column.htmlType == "checkbox")## 多选框 | ||
| 161 | - <template #${javaField}="{ row, column }"> | ||
| 162 | - <CheckboxGroup v-model:value="row.${javaField}" :options="column.params.options" /> | ||
| 163 | - </template> | ||
| 164 | - #elseif($column.htmlType == "radio")## 单选框 | ||
| 165 | - <template #${javaField}="{ row, column }"> | ||
| 166 | - <RadioGroup v-model:value="row.${javaField}" :options="column.params.options" /> | ||
| 167 | - </template> | ||
| 168 | - #elseif($column.htmlType == "datetime")## 时间框 | ||
| 169 | - <template #${javaField}="{ row }"> | ||
| 170 | - <DatePicker | ||
| 171 | - v-model:value="row.${javaField}" | ||
| 172 | - :showTime="true" | ||
| 173 | - format="YYYY-MM-DD HH:mm:ss" | ||
| 174 | - valueFormat='x' | ||
| 175 | - /> | ||
| 176 | - </template> | ||
| 177 | - #elseif($column.htmlType == "textarea")## 文本框 | ||
| 178 | - <template #${javaField}="{ row }"> | ||
| 179 | - <Textarea v-model:value="row.${javaField}" /> | ||
| 180 | - </template> | ||
| 181 | - #end | ||
| 182 | - #end | ||
| 183 | - #end | ||
| 184 | - </${subSimpleClassName}Grid> | ||
| 185 | - <div class="flex justify-center"> | ||
| 186 | - <Button :icon="h(Plus)" type="primary" ghost @click="handleAdd" v-access:code="['${subTable.moduleName}:${simpleClassName_strikeCase}:create']"> | ||
| 187 | - {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }} | ||
| 188 | - </Button> | ||
| 189 | - </div> | ||
| 190 | - #else | ||
| 191 | - <${subSimpleClassName}Form class="mx-4" /> | ||
| 192 | - #end | 83 | + <Modal :title="getTitle"> |
| 84 | + <Form class="mx-4" /> | ||
| 85 | + </Modal> | ||
| 193 | </template> | 86 | </template> |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm
| @@ -3,28 +3,33 @@ | @@ -3,28 +3,33 @@ | ||
| 3 | #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | 3 | #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 |
| 4 | #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | 4 | #set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) |
| 5 | #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | 5 | #set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 |
| 6 | -#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index)) | 6 | +#set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($subIndex)) |
| 7 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | 7 | #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 |
| 8 | <script lang="ts" setup> | 8 | <script lang="ts" setup> |
| 9 | import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table'; | 9 | import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table'; |
| 10 | import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | 10 | import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; |
| 11 | 11 | ||
| 12 | +#if ($table.templateType == 11) ## erp | ||
| 13 | + import ${subSimpleClassName}Form from './${subSimpleClassName_strikeCase}-form.vue' | ||
| 14 | +#end | ||
| 12 | import { useVbenModal } from '@vben/common-ui'; | 15 | import { useVbenModal } from '@vben/common-ui'; |
| 13 | import { Button, message } from 'ant-design-vue'; | 16 | import { Button, message } from 'ant-design-vue'; |
| 14 | import { Plus } from '@vben/icons'; | 17 | import { Plus } from '@vben/icons'; |
| 15 | - import { ref, h, nextTick,watch } from 'vue'; | 18 | + import { #if($table.templateType != 11)ref,#end h, nextTick,watch } from 'vue'; |
| 16 | import { $t } from '#/locales'; | 19 | import { $t } from '#/locales'; |
| 17 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; | 20 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; |
| 18 | 21 | ||
| 19 | 22 | ||
| 20 | #if ($table.templateType == 11) ## erp | 23 | #if ($table.templateType == 11) ## erp |
| 21 | - import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue'; | ||
| 22 | -#end | 24 | + import { delete${subSimpleClassName}, get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; |
| 25 | + import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data'; | ||
| 26 | + #else | ||
| 27 | + #if ($subTable.subJoinMany) ## 一对多 | ||
| 28 | + import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | ||
| 29 | + #else | ||
| 30 | + import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | ||
| 31 | + #end | ||
| 23 | import { use${subSimpleClassName}GridColumns } from '../data'; | 32 | import { use${subSimpleClassName}GridColumns } from '../data'; |
| 24 | -#if ($subTable.subJoinMany) ## 一对多 | ||
| 25 | -import { get${subSimpleClassName}ListBy${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | ||
| 26 | -#else | ||
| 27 | -import { get${subSimpleClassName}By${SubJoinColumnName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; | ||
| 28 | #end | 33 | #end |
| 29 | 34 | ||
| 30 | const props = defineProps<{ | 35 | const props = defineProps<{ |
| @@ -39,7 +44,11 @@ const props = defineProps<{ | @@ -39,7 +44,11 @@ const props = defineProps<{ | ||
| 39 | 44 | ||
| 40 | /** 创建${subTable.classComment} */ | 45 | /** 创建${subTable.classComment} */ |
| 41 | function onCreate() { | 46 | function onCreate() { |
| 42 | - formModalApi.setData({}).open(); | 47 | + if (!props.${subJoinColumn.javaField}){ |
| 48 | + message.warning("请先选择一个${table.classComment}!") | ||
| 49 | + return | ||
| 50 | + } | ||
| 51 | + formModalApi.setData({${subJoinColumn.javaField}: props.${subJoinColumn.javaField}}).open(); | ||
| 43 | } | 52 | } |
| 44 | 53 | ||
| 45 | /** 编辑${subTable.classComment} */ | 54 | /** 编辑${subTable.classComment} */ |
| @@ -85,33 +94,64 @@ function onActionClick({ | @@ -85,33 +94,64 @@ function onActionClick({ | ||
| 85 | 94 | ||
| 86 | #end | 95 | #end |
| 87 | const [Grid, gridApi] = useVbenVxeGrid({ | 96 | const [Grid, gridApi] = useVbenVxeGrid({ |
| 97 | +#if ($table.templateType == 11) | ||
| 98 | + formOptions: { | ||
| 99 | + schema: use${subSimpleClassName}GridFormSchema(), | ||
| 100 | + }, | ||
| 101 | +#end | ||
| 88 | gridOptions: { | 102 | gridOptions: { |
| 89 | #if ($table.templateType == 11) | 103 | #if ($table.templateType == 11) |
| 90 | - columns: use${subSimpleClassName}GridColumns(onActionClick), | 104 | + columns: use${subSimpleClassName}GridColumns(onActionClick), |
| 105 | + proxyConfig: { | ||
| 106 | + ajax: { | ||
| 107 | + query: async ({ page }, formValues) => { | ||
| 108 | + if (!props.${subJoinColumn.javaField}){ | ||
| 109 | + return [] | ||
| 110 | + } | ||
| 111 | + return await get${subSimpleClassName}Page({ | ||
| 112 | + pageNo: page.currentPage, | ||
| 113 | + pageSize: page.pageSize, | ||
| 114 | + ${subJoinColumn.javaField}: props.${subJoinColumn.javaField}, | ||
| 115 | + ...formValues, | ||
| 116 | + }); | ||
| 117 | + }, | ||
| 118 | + }, | ||
| 119 | + }, | ||
| 120 | + pagerConfig: { | ||
| 121 | + enabled: true, | ||
| 122 | + }, | ||
| 123 | + toolbarConfig: { | ||
| 124 | + refresh: { code: 'query' }, | ||
| 125 | + search: true, | ||
| 126 | + }, | ||
| 91 | #else | 127 | #else |
| 92 | - columns: use${subSimpleClassName}GridColumns(), | 128 | + columns: use${subSimpleClassName}GridColumns(), |
| 129 | + pagerConfig: { | ||
| 130 | + enabled: false, | ||
| 131 | + }, | ||
| 132 | + toolbarConfig: { | ||
| 133 | + enabled: false, | ||
| 134 | + }, | ||
| 93 | #end | 135 | #end |
| 94 | - height: 'auto', | ||
| 95 | - rowConfig: { | 136 | + height: '600px', |
| 137 | + rowConfig: { | ||
| 96 | keyField: 'id', | 138 | keyField: 'id', |
| 97 | isHover: true, | 139 | isHover: true, |
| 98 | - }, | ||
| 99 | - pagerConfig: { | ||
| 100 | - enabled: false, | ||
| 101 | - }, | ||
| 102 | - toolbarConfig: { | ||
| 103 | - enabled: false, | ||
| 104 | - }, | ||
| 105 | - } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>, | 140 | + }, |
| 141 | + } as VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>, | ||
| 106 | }); | 142 | }); |
| 107 | 143 | ||
| 108 | /** 刷新表格 */ | 144 | /** 刷新表格 */ |
| 109 | const onRefresh = async ()=> { | 145 | const onRefresh = async ()=> { |
| 110 | - #if ($subTable.subJoinMany) ## 一对多 | 146 | +#if ($table.templateType == 11) ## erp |
| 147 | + await gridApi.query(); | ||
| 148 | +#else | ||
| 149 | + #if ($subTable.subJoinMany) ## 一对多 | ||
| 111 | await gridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!)); | 150 | await gridApi.grid.loadData(await get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}!)); |
| 112 | - #else | 151 | + #else |
| 113 | await gridApi.grid.loadData([await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!)]); | 152 | await gridApi.grid.loadData([await get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}!)]); |
| 114 | - #end | 153 | + #end |
| 154 | +#end | ||
| 115 | } | 155 | } |
| 116 | 156 | ||
| 117 | /** 监听主表的关联字段的变化,加载对应的子表数据 */ | 157 | /** 监听主表的关联字段的变化,加载对应的子表数据 */ |
| @@ -133,7 +173,7 @@ const onRefresh = async ()=> { | @@ -133,7 +173,7 @@ const onRefresh = async ()=> { | ||
| 133 | <FormModal @success="onRefresh" /> | 173 | <FormModal @success="onRefresh" /> |
| 134 | <Grid table-title="${subTable.classComment}列表"> | 174 | <Grid table-title="${subTable.classComment}列表"> |
| 135 | <template #toolbar-tools> | 175 | <template #toolbar-tools> |
| 136 | - <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${subTable.moduleName}:${subSimpleClassName_strikeCase}:create']"> | 176 | + <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> |
| 137 | {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }} | 177 | {{ $t('ui.actionTitle.create', ['${subTable.classComment}']) }} |
| 138 | </Button> | 178 | </Button> |
| 139 | </template> | 179 | </template> |