Commit f3aa501e94e9fe00f8d8701a44eb8808815cc737
1 parent
da248cd1
【代码优化】代码生成: vue3_vben5_antd schema 主子表模版优化
Showing
4 changed files
with
71 additions
and
74 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm
| @@ -4,6 +4,26 @@ import { requestClient } from '#/api/request'; | @@ -4,6 +4,26 @@ import { requestClient } from '#/api/request'; | ||
| 4 | #set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") | 4 | #set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") |
| 5 | 5 | ||
| 6 | export namespace ${simpleClassName}Api { | 6 | export namespace ${simpleClassName}Api { |
| 7 | +## 特殊:主子表专属逻辑 | ||
| 8 | +#foreach ($subTable in $subTables) | ||
| 9 | + #set ($index = $foreach.count - 1) | ||
| 10 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 11 | + #set ($subColumns = $subColumnsList.get($index))##当前字段数组 | ||
| 12 | + /** ${subTable.classComment}信息 */ | ||
| 13 | + export interface ${subSimpleClassName} { | ||
| 14 | + #foreach ($column in $subColumns) | ||
| 15 | + #if ($column.createOperation || $column.updateOperation) | ||
| 16 | + #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | ||
| 17 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment} | ||
| 18 | + #elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime") | ||
| 19 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: Date; // ${column.columnComment} | ||
| 20 | + #else | ||
| 21 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment} | ||
| 22 | + #end | ||
| 23 | + #end | ||
| 24 | + #end | ||
| 25 | + } | ||
| 26 | +#end | ||
| 7 | /** ${table.classComment}信息 */ | 27 | /** ${table.classComment}信息 */ |
| 8 | export interface ${simpleClassName} { | 28 | export interface ${simpleClassName} { |
| 9 | #foreach ($column in $columns) | 29 | #foreach ($column in $columns) |
| @@ -33,26 +53,6 @@ export namespace ${simpleClassName}Api { | @@ -33,26 +53,6 @@ export namespace ${simpleClassName}Api { | ||
| 33 | #end | 53 | #end |
| 34 | #end | 54 | #end |
| 35 | } | 55 | } |
| 36 | -## 特殊:主子表专属逻辑 | ||
| 37 | -#foreach ($subTable in $subTables) | ||
| 38 | - #set ($index = $foreach.count - 1) | ||
| 39 | - #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | ||
| 40 | - #set ($subColumns = $subColumnsList.get($index))##当前字段数组 | ||
| 41 | - /** ${subTable.classComment}信息 */ | ||
| 42 | - export interface ${subSimpleClassName} { | ||
| 43 | - #foreach ($column in $subColumns) | ||
| 44 | - #if ($column.createOperation || $column.updateOperation) | ||
| 45 | - #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | ||
| 46 | - ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment} | ||
| 47 | - #elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime") | ||
| 48 | - ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: Date; // ${column.columnComment} | ||
| 49 | - #else | ||
| 50 | - ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment} | ||
| 51 | - #end | ||
| 52 | - #end | ||
| 53 | - #end | ||
| 54 | - } | ||
| 55 | -#end | ||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | #if ( $table.templateType != 2 ) | 58 | #if ( $table.templateType != 2 ) |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm
| @@ -167,13 +167,13 @@ export function useGridFormSchema(): VbenFormSchema[] { | @@ -167,13 +167,13 @@ export function useGridFormSchema(): VbenFormSchema[] { | ||
| 167 | { | 167 | { |
| 168 | fieldName: '${javaField}', | 168 | fieldName: '${javaField}', |
| 169 | label: '${comment}', | 169 | label: '${comment}', |
| 170 | - #if ($column.htmlType == "input") | 170 | + #if ($column.htmlType == "input" || $column.htmlType == "textarea" || $column.htmlType == "editor") |
| 171 | component: 'Input', | 171 | component: 'Input', |
| 172 | componentProps: { | 172 | componentProps: { |
| 173 | allowClear: true, | 173 | allowClear: true, |
| 174 | placeholder: '请输入${comment}', | 174 | placeholder: '请输入${comment}', |
| 175 | }, | 175 | }, |
| 176 | - #elseif ($column.htmlType == "select") | 176 | + #elseif ($column.htmlType == "select" || $column.htmlType == "radio") |
| 177 | component: 'Select', | 177 | component: 'Select', |
| 178 | componentProps: { | 178 | componentProps: { |
| 179 | allowClear: true, | 179 | allowClear: true, |
| @@ -184,16 +184,6 @@ export function useGridFormSchema(): VbenFormSchema[] { | @@ -184,16 +184,6 @@ export function useGridFormSchema(): VbenFormSchema[] { | ||
| 184 | #end | 184 | #end |
| 185 | placeholder: '请选择${comment}', | 185 | placeholder: '请选择${comment}', |
| 186 | }, | 186 | }, |
| 187 | - #elseif ($column.htmlType == "radio") | ||
| 188 | - component: 'Select', | ||
| 189 | - componentProps: { | ||
| 190 | - allowClear: true, | ||
| 191 | - #if ("" != $dictType)## 设置了 dictType 数据字典的情况 | ||
| 192 | - options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'), | ||
| 193 | - #else## 未设置 dictType 数据字典的情况 | ||
| 194 | - options: [], | ||
| 195 | - #end | ||
| 196 | - }, | ||
| 197 | #elseif($column.htmlType == "datetime") | 187 | #elseif($column.htmlType == "datetime") |
| 198 | component: 'RangePicker', | 188 | component: 'RangePicker', |
| 199 | componentProps: { | 189 | componentProps: { |
| @@ -400,7 +390,7 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] { | @@ -400,7 +390,7 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] { | ||
| 400 | /** 列表的字段 */ | 390 | /** 列表的字段 */ |
| 401 | export function use${subSimpleClassName}GridColumns( | 391 | export function use${subSimpleClassName}GridColumns( |
| 402 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, | 392 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, |
| 403 | -): VxeTableGridOptions<${subSimpleClassName}Api.${subSimpleClassName}>['columns'] { | 393 | +): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { |
| 404 | return [ | 394 | return [ |
| 405 | #foreach($column in $subColumns) | 395 | #foreach($column in $subColumns) |
| 406 | #if ($column.listOperationResult) | 396 | #if ($column.listOperationResult) |
| @@ -471,37 +461,39 @@ export function use${subSimpleClassName}GridColumns( | @@ -471,37 +461,39 @@ export function use${subSimpleClassName}GridColumns( | ||
| 471 | /** 列表的字段 */ | 461 | /** 列表的字段 */ |
| 472 | export function use${subSimpleClassName}GridColumns( | 462 | export function use${subSimpleClassName}GridColumns( |
| 473 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, | 463 | onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, |
| 474 | - ): VxeTableGridOptions<${subSimpleClassName}Api.${subSimpleClassName}>['columns'] { | 464 | + ): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] { |
| 475 | return [ | 465 | return [ |
| 476 | #foreach($column in $subColumns) | 466 | #foreach($column in $subColumns) |
| 477 | - #if (!$column.primaryKey && $column.listOperationResult && $column.id != $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | ||
| 478 | - #set ($dictType = $column.dictType) | ||
| 479 | - #set ($javaField = $column.javaField) | ||
| 480 | - #set ($comment = $column.columnComment) | ||
| 481 | - #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | ||
| 482 | - #set ($dictMethod = "number") | ||
| 483 | - #elseif ($javaType == "String") | ||
| 484 | - #set ($dictMethod = "string") | ||
| 485 | - #elseif ($javaType == "Boolean") | ||
| 486 | - #set ($dictMethod = "boolean") | ||
| 487 | - #end | ||
| 488 | - { | ||
| 489 | - field: '${javaField}', | ||
| 490 | - title: '${comment}', | ||
| 491 | - minWidth: 120, | ||
| 492 | - slots: { default: '${javaField}' }, | ||
| 493 | - #if ($column.htmlType == "select" || $column.htmlType == "checkbox" || $column.htmlType == "radio") | ||
| 494 | - #if ("" != $dictType)## 有数据字典 | ||
| 495 | - params: { | ||
| 496 | - options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'), | ||
| 497 | - }, | ||
| 498 | - #else | ||
| 499 | - params: { | ||
| 500 | - options: [], | 467 | + #if ($column.createOperation || $column.updateOperation) |
| 468 | + #if (!$column.primaryKey && $column.listOperationResult && $column.id != $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | ||
| 469 | + #set ($dictType = $column.dictType) | ||
| 470 | + #set ($javaField = $column.javaField) | ||
| 471 | + #set ($comment = $column.columnComment) | ||
| 472 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | ||
| 473 | + #set ($dictMethod = "number") | ||
| 474 | + #elseif ($javaType == "String") | ||
| 475 | + #set ($dictMethod = "string") | ||
| 476 | + #elseif ($javaType == "Boolean") | ||
| 477 | + #set ($dictMethod = "boolean") | ||
| 478 | + #end | ||
| 479 | + { | ||
| 480 | + field: '${javaField}', | ||
| 481 | + title: '${comment}', | ||
| 482 | + minWidth: 120, | ||
| 483 | + slots: { default: '${javaField}' }, | ||
| 484 | + #if ($column.htmlType == "select" || $column.htmlType == "checkbox" || $column.htmlType == "radio") | ||
| 485 | + #if ("" != $dictType)## 有数据字典 | ||
| 486 | + params: { | ||
| 487 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'), | ||
| 488 | + }, | ||
| 489 | + #else | ||
| 490 | + params: { | ||
| 491 | + options: [], | ||
| 492 | + }, | ||
| 493 | + #end | ||
| 494 | + #end | ||
| 501 | }, | 495 | }, |
| 502 | #end | 496 | #end |
| 503 | - #end | ||
| 504 | - }, | ||
| 505 | #end | 497 | #end |
| 506 | #end | 498 | #end |
| 507 | { | 499 | { |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/form.vue.vm
| @@ -57,8 +57,7 @@ const subTabsName = ref('$subClassNameVars.get(0)') | @@ -57,8 +57,7 @@ const subTabsName = ref('$subClassNameVars.get(0)') | ||
| 57 | #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | 57 | #set ($subSimpleClassName = $subSimpleClassNames.get($index)) |
| 58 | #set ($subClassNameVar = $subClassNameVars.get($index)) | 58 | #set ($subClassNameVar = $subClassNameVars.get($index)) |
| 59 | #if ($subTable.subJoinMany) ## 一对多 | 59 | #if ($subTable.subJoinMany) ## 一对多 |
| 60 | -/** {$subTable.classComment}表格配置 */ | ||
| 61 | -const [${subSimpleClassName}Grid, {$subClassNameVar}GridApi] = useVbenVxeGrid({ | 60 | +const [${subSimpleClassName}Grid, ${subClassNameVar}GridApi] = useVbenVxeGrid({ |
| 62 | gridOptions: { | 61 | gridOptions: { |
| 63 | columns: use${subSimpleClassName}GridColumns(), | 62 | columns: use${subSimpleClassName}GridColumns(), |
| 64 | border: true, | 63 | border: true, |
| @@ -77,9 +76,9 @@ const [${subSimpleClassName}Grid, {$subClassNameVar}GridApi] = useVbenVxeGrid({ | @@ -77,9 +76,9 @@ const [${subSimpleClassName}Grid, {$subClassNameVar}GridApi] = useVbenVxeGrid({ | ||
| 77 | }, | 76 | }, |
| 78 | }); | 77 | }); |
| 79 | #else | 78 | #else |
| 80 | -const [${subSimpleClassName}Form, {$subClassNameVar}FormApi] = useVbenForm({ | 79 | +const [${subSimpleClassName}Form, ${subClassNameVar}FormApi] = useVbenForm({ |
| 81 | layout: 'horizontal', | 80 | layout: 'horizontal', |
| 82 | - schema: useFormSchema(), | 81 | + schema: use${subSimpleClassName}FormSchema(), |
| 83 | showDefaultActions: false | 82 | showDefaultActions: false |
| 84 | }); | 83 | }); |
| 85 | #end | 84 | #end |
| @@ -107,12 +106,15 @@ const [Modal, modalApi] = useVbenModal({ | @@ -107,12 +106,15 @@ const [Modal, modalApi] = useVbenModal({ | ||
| 107 | #foreach ($subTable in $subTables) | 106 | #foreach ($subTable in $subTables) |
| 108 | #set ($index = $foreach.count - 1) | 107 | #set ($index = $foreach.count - 1) |
| 109 | #set ($subClassNameVar = $subClassNameVars.get($index)) | 108 | #set ($subClassNameVar = $subClassNameVars.get($index)) |
| 110 | - try { | ||
| 111 | - await ${subClassNameVar}FormRef.value.validate() | ||
| 112 | - } catch (e) { | ||
| 113 | - subTabsName.value = '${subClassNameVar}' | ||
| 114 | - return | ||
| 115 | - } | 109 | + #if ($subTable.subJoinMany) ## 一对多 |
| 110 | + | ||
| 111 | + #else | ||
| 112 | + const { valid: ${subClassNameVar}Valid } = await ${subClassNameVar}FormApi.validate(); | ||
| 113 | + if (!${subClassNameVar}Valid) { | ||
| 114 | + subTabsName.value = '${subClassNameVar}'; | ||
| 115 | + return; | ||
| 116 | + } | ||
| 117 | + #end | ||
| 116 | #end | 118 | #end |
| 117 | #end | 119 | #end |
| 118 | #end | 120 | #end |
| @@ -126,7 +128,11 @@ const [Modal, modalApi] = useVbenModal({ | @@ -126,7 +128,11 @@ const [Modal, modalApi] = useVbenModal({ | ||
| 126 | #foreach ($subTable in $subTables) | 128 | #foreach ($subTable in $subTables) |
| 127 | #set ($index = $foreach.count - 1) | 129 | #set ($index = $foreach.count - 1) |
| 128 | #set ($subClassNameVar = $subClassNameVars.get($index)) | 130 | #set ($subClassNameVar = $subClassNameVars.get($index)) |
| 129 | - data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData() | 131 | + #if ($subTable.subJoinMany) |
| 132 | + data.${subClassNameVar}s = ${subClassNameVar}GridApi.grid.getData(); | ||
| 133 | + #else | ||
| 134 | + data.${subClassNameVar} = await ${subClassNameVar}FormApi.getValues(); | ||
| 135 | + #end | ||
| 130 | #end | 136 | #end |
| 131 | #end | 137 | #end |
| 132 | #end | 138 | #end |
| @@ -238,7 +244,7 @@ const [Modal, modalApi] = useVbenModal({ | @@ -238,7 +244,7 @@ const [Modal, modalApi] = useVbenModal({ | ||
| 238 | #end | 244 | #end |
| 239 | #end | 245 | #end |
| 240 | #end | 246 | #end |
| 241 | - </Grid> | 247 | + </${subSimpleClassName}Grid> |
| 242 | #else | 248 | #else |
| 243 | <${subSimpleClassName}Form class="mx-4" /> | 249 | <${subSimpleClassName}Form class="mx-4" /> |
| 244 | #end | 250 | #end |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm
| @@ -134,12 +134,11 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -134,12 +134,11 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 134 | }, | 134 | }, |
| 135 | #else## 标准表数据加载 | 135 | #else## 标准表数据加载 |
| 136 | query: async ({ page }, formValues) => { | 136 | query: async ({ page }, formValues) => { |
| 137 | - const { items, total } = await get${simpleClassName}Page({ | 137 | + return await get${simpleClassName}Page({ |
| 138 | pageNo: page.currentPage, | 138 | pageNo: page.currentPage, |
| 139 | pageSize: page.pageSize, | 139 | pageSize: page.pageSize, |
| 140 | ...formValues, | 140 | ...formValues, |
| 141 | }); | 141 | }); |
| 142 | - return { items, total }; | ||
| 143 | }, | 142 | }, |
| 144 | #end | 143 | #end |
| 145 | }, | 144 | }, |