Commit 24aea3e30a28f9f93e33db3f743208aeafb96975
1 parent
7c940854
【代码优化】INFRA: vue3_vben5_antd schema 单表和树表代码生成模版优化
Showing
3 changed files
with
24 additions
and
42 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben_next/schema/views/data.ts.vm
| @@ -9,6 +9,7 @@ import { get${simpleClassName}List } from '#/api/${table.moduleName}/${simpleCla | @@ -9,6 +9,7 @@ import { get${simpleClassName}List } from '#/api/${table.moduleName}/${simpleCla | ||
| 9 | import { handleTree } from '#/utils/tree'; | 9 | import { handleTree } from '#/utils/tree'; |
| 10 | #end | 10 | #end |
| 11 | import { DICT_TYPE, getDictOptions } from '#/utils/dict'; | 11 | import { DICT_TYPE, getDictOptions } from '#/utils/dict'; |
| 12 | +import { getRangePickerDefaultProps } from '#/utils/date'; | ||
| 12 | import { useAccess } from '@vben/access'; | 13 | import { useAccess } from '@vben/access'; |
| 13 | 14 | ||
| 14 | const { hasAccessByCodes } = useAccess(); | 15 | const { hasAccessByCodes } = useAccess(); |
| @@ -196,6 +197,7 @@ export function useGridFormSchema(): VbenFormSchema[] { | @@ -196,6 +197,7 @@ export function useGridFormSchema(): VbenFormSchema[] { | ||
| 196 | #elseif($column.htmlType == "datetime") | 197 | #elseif($column.htmlType == "datetime") |
| 197 | component: 'RangePicker', | 198 | component: 'RangePicker', |
| 198 | componentProps: { | 199 | componentProps: { |
| 200 | + ...getRangePickerDefaultProps(), | ||
| 199 | allowClear: true, | 201 | allowClear: true, |
| 200 | }, | 202 | }, |
| 201 | #end | 203 | #end |
| @@ -237,7 +239,7 @@ export function useGridColumns( | @@ -237,7 +239,7 @@ export function useGridColumns( | ||
| 237 | field: 'operation', | 239 | field: 'operation', |
| 238 | title: '操作', | 240 | title: '操作', |
| 239 | minWidth: 200, | 241 | minWidth: 200, |
| 240 | - align: 'right', | 242 | + align: 'center', |
| 241 | fixed: 'right', | 243 | fixed: 'right', |
| 242 | headerAlign: 'center', | 244 | headerAlign: 'center', |
| 243 | showOverflow: false, | 245 | showOverflow: false, |
| @@ -251,7 +253,7 @@ export function useGridColumns( | @@ -251,7 +253,7 @@ export function useGridColumns( | ||
| 251 | options: [ | 253 | options: [ |
| 252 | #if (${table.templateType} == 2)## 树表特有操作 | 254 | #if (${table.templateType} == 2)## 树表特有操作 |
| 253 | { | 255 | { |
| 254 | - code: 'add_child', | 256 | + code: 'append', |
| 255 | text: '新增下级', | 257 | text: '新增下级', |
| 256 | show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']), | 258 | show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']), |
| 257 | }, | 259 | }, |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben_next/schema/views/form.vue.vm
| @@ -64,49 +64,25 @@ const [Modal, modalApi] = useVbenModal({ | @@ -64,49 +64,25 @@ const [Modal, modalApi] = useVbenModal({ | ||
| 64 | if (!isOpen) { | 64 | if (!isOpen) { |
| 65 | return; | 65 | return; |
| 66 | } | 66 | } |
| 67 | + | ||
| 67 | // 加载数据 | 68 | // 加载数据 |
| 68 | -#if (${table.templateType} == 2)## 树表处理传入的父ID | ||
| 69 | let data = modalApi.getData<${simpleClassName}Api.${simpleClassName}>(); | 69 | let data = modalApi.getData<${simpleClassName}Api.${simpleClassName}>(); |
| 70 | -#else## 标准表直接获取 | ||
| 71 | - const data = modalApi.getData<${simpleClassName}Api.${simpleClassName}>(); | ||
| 72 | -#end | ||
| 73 | if (!data) { | 70 | if (!data) { |
| 74 | return; | 71 | return; |
| 75 | } | 72 | } |
| 76 | 73 | ||
| 77 | -#if (${table.templateType} == 2)## 树表特有:处理新增下级的情况 | ||
| 78 | - // 处理新增下级的情况 | ||
| 79 | - if (!data.id && data.${treeParentColumn.javaField}) { | ||
| 80 | - parentId.value = data.${treeParentColumn.javaField}; | ||
| 81 | - formData.value = { ${treeParentColumn.javaField}: parentId.value } as ${simpleClassName}Api.${simpleClassName}; | ||
| 82 | - await formApi.setValues(formData.value); | ||
| 83 | - return; | ||
| 84 | - } | ||
| 85 | -#end | ||
| 86 | - | ||
| 87 | if (data.id) { | 74 | if (data.id) { |
| 88 | // 编辑 | 75 | // 编辑 |
| 89 | modalApi.lock(); | 76 | modalApi.lock(); |
| 90 | try { | 77 | try { |
| 91 | -#if (${table.templateType} == 2)## 树表获取数据后重新赋值 | ||
| 92 | data = await get${simpleClassName}(data.id); | 78 | data = await get${simpleClassName}(data.id); |
| 93 | - formData.value = data; | ||
| 94 | -#else## 标准表设置表单数据 | ||
| 95 | - formData.value = await get${simpleClassName}(data.id as number); | ||
| 96 | -#end | ||
| 97 | - await formApi.setValues(formData.value); | ||
| 98 | } finally { | 79 | } finally { |
| 99 | modalApi.lock(false); | 80 | modalApi.lock(false); |
| 100 | } | 81 | } |
| 101 | - } else { | ||
| 102 | - // 新增 | ||
| 103 | -#if (${table.templateType} == 2)## 树表特有:设置顶级ID | ||
| 104 | - formData.value = { ${treeParentColumn.javaField}: 0 } as ${simpleClassName}Api.${simpleClassName}; | ||
| 105 | -#else## 标准表:设置空值 | ||
| 106 | - formData.value = data; | ||
| 107 | -#end | ||
| 108 | - await formApi.setValues(formData.value || {}); | ||
| 109 | } | 82 | } |
| 83 | + // 设置到 values | ||
| 84 | + formData.value = data; | ||
| 85 | + await formApi.setValues(formData.value); | ||
| 110 | }, | 86 | }, |
| 111 | }); | 87 | }); |
| 112 | </script> | 88 | </script> |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben_next/schema/views/index.vue.vm
| @@ -7,7 +7,7 @@ import { Button, message } from 'ant-design-vue'; | @@ -7,7 +7,7 @@ import { Button, message } from 'ant-design-vue'; | ||
| 7 | import { Download, Plus } from '@vben/icons'; | 7 | import { Download, Plus } from '@vben/icons'; |
| 8 | import Form from './modules/form.vue'; | 8 | import Form from './modules/form.vue'; |
| 9 | 9 | ||
| 10 | -import { ref } from 'vue'; | 10 | +import { ref, h } from 'vue'; |
| 11 | import { $t } from '#/locales'; | 11 | import { $t } from '#/locales'; |
| 12 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; | 12 | import { useVbenVxeGrid } from '#/adapter/vxe-table'; |
| 13 | #if (${table.templateType} == 2)## 树表接口 | 13 | #if (${table.templateType} == 2)## 树表接口 |
| @@ -56,7 +56,7 @@ function onEdit(row: ${simpleClassName}Api.${simpleClassName}) { | @@ -56,7 +56,7 @@ function onEdit(row: ${simpleClassName}Api.${simpleClassName}) { | ||
| 56 | 56 | ||
| 57 | #if (${table.templateType} == 2)## 树表特有:新增下级 | 57 | #if (${table.templateType} == 2)## 树表特有:新增下级 |
| 58 | /** 新增下级${table.classComment} */ | 58 | /** 新增下级${table.classComment} */ |
| 59 | -function onAddChild(row: ${simpleClassName}Api.${simpleClassName}) { | 59 | +function onAppend(row: ${simpleClassName}Api.${simpleClassName}) { |
| 60 | formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open(); | 60 | formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open(); |
| 61 | } | 61 | } |
| 62 | #end | 62 | #end |
| @@ -86,20 +86,20 @@ function onActionClick({ | @@ -86,20 +86,20 @@ function onActionClick({ | ||
| 86 | row, | 86 | row, |
| 87 | }: OnActionClickParams<${simpleClassName}Api.${simpleClassName}>) { | 87 | }: OnActionClickParams<${simpleClassName}Api.${simpleClassName}>) { |
| 88 | switch (code) { | 88 | switch (code) { |
| 89 | - case 'edit': { | ||
| 90 | - onEdit(row); | 89 | + #if (${table.templateType} == 2)## 树表特有:新增下级 |
| 90 | + case 'append': { | ||
| 91 | + onAppend(row); | ||
| 91 | break; | 92 | break; |
| 92 | } | 93 | } |
| 94 | + #end | ||
| 93 | case 'delete': { | 95 | case 'delete': { |
| 94 | onDelete(row); | 96 | onDelete(row); |
| 95 | break; | 97 | break; |
| 96 | } | 98 | } |
| 97 | -#if (${table.templateType} == 2)## 树表特有:新增下级 | ||
| 98 | - case 'add_child': { | ||
| 99 | - onAddChild(row); | 99 | + case 'edit': { |
| 100 | + onEdit(row); | ||
| 100 | break; | 101 | break; |
| 101 | } | 102 | } |
| 102 | -#end | ||
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| @@ -167,12 +167,16 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -167,12 +167,16 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 167 | {{ isExpanded ? '收缩' : '展开' }} | 167 | {{ isExpanded ? '收缩' : '展开' }} |
| 168 | </Button> | 168 | </Button> |
| 169 | #end | 169 | #end |
| 170 | - <Button type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> | ||
| 171 | - <Plus class="size-5" /> | 170 | + <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> |
| 172 | {{ $t('ui.actionTitle.create', ['${table.classComment}']) }} | 171 | {{ $t('ui.actionTitle.create', ['${table.classComment}']) }} |
| 173 | </Button> | 172 | </Button> |
| 174 | - <Button type="primary" class="ml-2" @click="onExport" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:export']"> | ||
| 175 | - <Download class="size-5" /> | 173 | + <Button |
| 174 | + :icon="h(Download)" | ||
| 175 | + type="primary" | ||
| 176 | + class="ml-2" | ||
| 177 | + @click="onExport" | ||
| 178 | + v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:export']" | ||
| 179 | + > | ||
| 176 | {{ $t('ui.actionTitle.export') }} | 180 | {{ $t('ui.actionTitle.export') }} |
| 177 | </Button> | 181 | </Button> |
| 178 | </template> | 182 | </template> |