Commit 1f7f06549fbafed9407f2769e3a443f1549d6c40
1 parent
39231898
【代码优化】代码生成: vue3_vben5_antd schema 主子表 api 和 data.ts 模板优化
Showing
2 changed files
with
196 additions
and
10 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm
| ... | ... | @@ -108,31 +108,31 @@ export function export${simpleClassName}(params: any) { |
| 108 | 108 | #if ( $table.templateType == 11 ) |
| 109 | 109 | /** 获得${subTable.classComment}分页 */ |
| 110 | 110 | export function get${subSimpleClassName}Page(params: PageParam) { |
| 111 | - return requestClient.get<PageResult<${simpleClassName}Api.${simpleClassName}>>(`${baseURL}/${subSimpleClassName_strikeCase}/page`, { params }); | |
| 111 | + return requestClient.get<PageResult<${simpleClassName}Api.${subSimpleClassName}>>(`${baseURL}/${subSimpleClassName_strikeCase}/page`, { params }); | |
| 112 | 112 | } |
| 113 | 113 | ## 情况二:非 MASTER_ERP 时,需要列表查询子表 |
| 114 | 114 | #else |
| 115 | 115 | #if ( $subTable.subJoinMany ) |
| 116 | 116 | /** 获得${subTable.classComment}列表 */ |
| 117 | 117 | export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}: number) { |
| 118 | - return requestClient.get<${simpleClassName}Api.${simpleClassName}[]>(`${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`); | |
| 118 | + return requestClient.get<${simpleClassName}Api.${subSimpleClassName}[]>(`${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`); | |
| 119 | 119 | } |
| 120 | 120 | #else |
| 121 | 121 | /** 获得${subTable.classComment} */ |
| 122 | 122 | export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}: number) { |
| 123 | - return requestClient.get<${simpleClassName}Api.${simpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`); | |
| 123 | + return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`); | |
| 124 | 124 | } |
| 125 | 125 | #end |
| 126 | 126 | #end |
| 127 | 127 | ## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作 |
| 128 | 128 | #if ( $table.templateType == 11 ) |
| 129 | 129 | /** 新增${subTable.classComment} */ |
| 130 | -export function create${subSimpleClassName}(data: ${simpleClassName}Api.${simpleClassName}) { | |
| 130 | +export function create${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) { | |
| 131 | 131 | return requestClient.post(`${baseURL}/${subSimpleClassName_strikeCase}/create`, data); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** 修改${subTable.classComment} */ |
| 135 | -export function update${subSimpleClassName}(data: ${simpleClassName}Api.${simpleClassName}) { | |
| 135 | +export function update${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) { | |
| 136 | 136 | return requestClient.put(`${baseURL}/${subSimpleClassName_strikeCase}/update`, data); |
| 137 | 137 | } |
| 138 | 138 | |
| ... | ... | @@ -143,7 +143,7 @@ export function delete${subSimpleClassName}(id: number) { |
| 143 | 143 | |
| 144 | 144 | /** 获得${subTable.classComment} */ |
| 145 | 145 | export function get${subSimpleClassName}(id: number) { |
| 146 | - return requestClient.get<${simpleClassName}Api.${simpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`); | |
| 146 | + return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`); | |
| 147 | 147 | } |
| 148 | 148 | #end |
| 149 | 149 | #end | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm
| ... | ... | @@ -277,7 +277,7 @@ export function useGridColumns( |
| 277 | 277 | ]; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | -// TODO @puhui999: 标准模式和内嵌模式时,主子关系一对一则生成表单schema,一对多则生成列表schema(内嵌模式时表单schema也要生成)。erp 模式时都生成 | |
| 280 | +## 标准模式和内嵌模式时,主子关系一对一则生成表单schema,一对多则生成列表schema(内嵌模式时表单schema也要生成)。erp 模式时都生成 | |
| 281 | 281 | ## 特殊:主子表专属逻辑 |
| 282 | 282 | #foreach ($subTable in $subTables) |
| 283 | 283 | #set ($index = $foreach.count - 1) |
| ... | ... | @@ -285,6 +285,7 @@ export function useGridColumns( |
| 285 | 285 | #set ($subSimpleClassName = $subSimpleClassNames.get($index)) |
| 286 | 286 | #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 |
| 287 | 287 | // ==================== 子表($subTable.classComment) ==================== |
| 288 | +#if ($table.templateType == 11) ## erp 情况 | |
| 288 | 289 | /** 新增/修改的表单 */ |
| 289 | 290 | export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] { |
| 290 | 291 | return [ |
| ... | ... | @@ -402,7 +403,7 @@ export function use${subSimpleClassName}GridColumns( |
| 402 | 403 | ): VxeTableGridOptions<${subSimpleClassName}Api.${subSimpleClassName}>['columns'] { |
| 403 | 404 | return [ |
| 404 | 405 | #foreach($column in $subColumns) |
| 405 | - #if (!$column.primaryKey && $column.listOperationResult && $column.id != $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 406 | + #if ($column.listOperationResult) | |
| 406 | 407 | #set ($dictType = $column.dictType) |
| 407 | 408 | #set ($javaField = $column.javaField) |
| 408 | 409 | #set ($comment = $column.columnComment) |
| ... | ... | @@ -410,14 +411,24 @@ export function use${subSimpleClassName}GridColumns( |
| 410 | 411 | field: '${javaField}', |
| 411 | 412 | title: '${comment}', |
| 412 | 413 | minWidth: 120, |
| 413 | - slots: { default: '${javaField}' }, | |
| 414 | + #if ($column.javaType == "LocalDateTime")## 时间类型 | |
| 415 | + formatter: 'formatDateTime', | |
| 416 | + #elseif("" != $dictType)## 数据字典 | |
| 417 | + cellRender: { | |
| 418 | + name: 'CellDict', | |
| 419 | + props: { type: DICT_TYPE.$dictType.toUpperCase() }, | |
| 420 | + }, | |
| 421 | + #end | |
| 422 | + #if (${table.templateType} == 2 && $column.id == $treeNameColumn.id)## 树表特有:标记树节点列 | |
| 423 | + treeNode: true, | |
| 424 | + #end | |
| 414 | 425 | }, |
| 415 | 426 | #end |
| 416 | 427 | #end |
| 417 | 428 | { |
| 418 | 429 | field: 'operation', |
| 419 | 430 | title: '操作', |
| 420 | - minWidth: 60, | |
| 431 | + minWidth: 200, | |
| 421 | 432 | align: 'center', |
| 422 | 433 | fixed: 'right', |
| 423 | 434 | headerAlign: 'center', |
| ... | ... | @@ -430,13 +441,188 @@ export function use${subSimpleClassName}GridColumns( |
| 430 | 441 | }, |
| 431 | 442 | name: 'CellOperation', |
| 432 | 443 | options: [ |
| 444 | + #if (${table.templateType} == 2)## 树表特有操作 | |
| 445 | + { | |
| 446 | + code: 'append', | |
| 447 | + text: '新增下级', | |
| 448 | + show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:create']), | |
| 449 | + }, | |
| 450 | + #end | |
| 451 | + { | |
| 452 | + code: 'edit', | |
| 453 | + show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:update']), | |
| 454 | + }, | |
| 433 | 455 | { |
| 434 | 456 | code: 'delete', |
| 435 | 457 | show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']), |
| 458 | + #if (${table.templateType} == 2)## 树表禁止删除带有子节点的数据 | |
| 459 | + disabled: (row: ${simpleClassName}Api.${simpleClassName}) => { | |
| 460 | + return !!(row.children && row.children.length > 0); | |
| 461 | + }, | |
| 462 | + #end | |
| 436 | 463 | }, |
| 437 | 464 | ], |
| 438 | 465 | }, |
| 439 | 466 | }, |
| 440 | 467 | ]; |
| 441 | 468 | } |
| 469 | +#else | |
| 470 | + #if ($subTable.subJoinMany) ## 一对多 | |
| 471 | + /** 列表的字段 */ | |
| 472 | + export function use${subSimpleClassName}GridColumns( | |
| 473 | + onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>, | |
| 474 | + ): VxeTableGridOptions<${subSimpleClassName}Api.${subSimpleClassName}>['columns'] { | |
| 475 | + return [ | |
| 476 | + #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 | + { | |
| 482 | + field: '${javaField}', | |
| 483 | + title: '${comment}', | |
| 484 | + minWidth: 120, | |
| 485 | + slots: { default: '${javaField}' }, | |
| 486 | + }, | |
| 487 | + #end | |
| 488 | + #end | |
| 489 | + { | |
| 490 | + field: 'operation', | |
| 491 | + title: '操作', | |
| 492 | + minWidth: 60, | |
| 493 | + align: 'center', | |
| 494 | + fixed: 'right', | |
| 495 | + headerAlign: 'center', | |
| 496 | + showOverflow: false, | |
| 497 | + cellRender: { | |
| 498 | + attrs: { | |
| 499 | + nameField: '${columns[0].javaField}', | |
| 500 | + nameTitle: '${table.classComment}', | |
| 501 | + onClick: onActionClick, | |
| 502 | + }, | |
| 503 | + name: 'CellOperation', | |
| 504 | + options: [ | |
| 505 | + { | |
| 506 | + code: 'delete', | |
| 507 | + show: hasAccessByCodes(['${table.moduleName}:${simpleClassName_strikeCase}:delete']), | |
| 508 | + }, | |
| 509 | + ], | |
| 510 | + }, | |
| 511 | + }, | |
| 512 | + ]; | |
| 513 | + } | |
| 514 | + #else | |
| 515 | + /** 新增/修改的表单 */ | |
| 516 | + export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] { | |
| 517 | + return [ | |
| 518 | + { | |
| 519 | + fieldName: 'id', | |
| 520 | + component: 'Input', | |
| 521 | + dependencies: { | |
| 522 | + triggerFields: [''], | |
| 523 | + show: () => false, | |
| 524 | + }, | |
| 525 | + }, | |
| 526 | + #foreach($column in $subColumns) | |
| 527 | + #if ($column.createOperation || $column.updateOperation) | |
| 528 | + #if (!$column.primaryKey && ($table.templateType != 2 || ($table.templateType == 2 && $column.id != $treeParentColumn.id)))## 树表中已经添加了父ID字段,这里排除 | |
| 529 | + #set ($dictType = $column.dictType) | |
| 530 | + #set ($javaType = $column.javaType) | |
| 531 | + #set ($javaField = $column.javaField) | |
| 532 | + #set ($comment = $column.columnComment) | |
| 533 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | |
| 534 | + #set ($dictMethod = "number") | |
| 535 | + #elseif ($javaType == "String") | |
| 536 | + #set ($dictMethod = "string") | |
| 537 | + #elseif ($javaType == "Boolean") | |
| 538 | + #set ($dictMethod = "boolean") | |
| 539 | + #end | |
| 540 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 541 | + #else | |
| 542 | + { | |
| 543 | + fieldName: '${javaField}', | |
| 544 | + label: '${comment}', | |
| 545 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 546 | + rules: 'required', | |
| 547 | + #end | |
| 548 | + #if ($column.htmlType == "input") | |
| 549 | + component: 'Input', | |
| 550 | + componentProps: { | |
| 551 | + placeholder: '请输入${comment}', | |
| 552 | + }, | |
| 553 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 554 | + component: 'FileUpload', | |
| 555 | + componentProps: { | |
| 556 | + fileType: 'image', | |
| 557 | + maxCount: 1, | |
| 558 | + }, | |
| 559 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 560 | + component: 'FileUpload', | |
| 561 | + componentProps: { | |
| 562 | + fileType: 'file', | |
| 563 | + maxCount: 1, | |
| 564 | + }, | |
| 565 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 566 | + component: 'Editor', | |
| 567 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 568 | + component: 'Select', | |
| 569 | + componentProps: { | |
| 570 | + #if ("" != $dictType)## 有数据字典 | |
| 571 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'), | |
| 572 | + #else##没数据字典 | |
| 573 | + options: [], | |
| 574 | + #end | |
| 575 | + placeholder: '请选择${comment}', | |
| 576 | + class: 'w-full', | |
| 577 | + }, | |
| 578 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 579 | + component: 'Checkbox', | |
| 580 | + componentProps: { | |
| 581 | + #if ("" != $dictType)## 有数据字典 | |
| 582 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'), | |
| 583 | + #else##没数据字典 | |
| 584 | + options: [], | |
| 585 | + #end | |
| 586 | + }, | |
| 587 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 588 | + component: 'RadioGroup', | |
| 589 | + componentProps: { | |
| 590 | + #if ("" != $dictType)## 有数据字典 | |
| 591 | + options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'), | |
| 592 | + #else##没数据字典 | |
| 593 | + options: [], | |
| 594 | + #end | |
| 595 | + buttonStyle: 'solid', | |
| 596 | + optionType: 'button', | |
| 597 | + }, | |
| 598 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 599 | + component: 'DatePicker', | |
| 600 | + componentProps: { | |
| 601 | + showTime: true, | |
| 602 | + format: 'YYYY-MM-DD HH:mm:ss', | |
| 603 | + valueFormat: 'x', | |
| 604 | + }, | |
| 605 | + #elseif($column.htmlType == "textarea")## 文本域 | |
| 606 | + component: 'Textarea', | |
| 607 | + componentProps: { | |
| 608 | + placeholder: '请输入${comment}', | |
| 609 | + }, | |
| 610 | + #elseif($column.htmlType == "inputNumber")## 数字输入框 | |
| 611 | + component: 'InputNumber', | |
| 612 | + componentProps: { | |
| 613 | + min: 0, | |
| 614 | + class: 'w-full', | |
| 615 | + controlsPosition: 'right', | |
| 616 | + placeholder: '请输入${comment}', | |
| 617 | + }, | |
| 618 | + #end | |
| 619 | + }, | |
| 620 | + #end | |
| 621 | + #end | |
| 622 | + #end | |
| 623 | + #end | |
| 624 | + ]; | |
| 625 | + } | |
| 626 | + #end | |
| 627 | +#end | |
| 442 | 628 | #end |
| 443 | 629 | \ No newline at end of file | ... | ... |