Commit 716ac2f9ff48054a46b2e6900c0d2a6081f13656
1 parent
bc9d9bcd
reactor:【infra 基础设施】处理 vben + element-plus 树形模版
Showing
3 changed files
with
35 additions
and
27 deletions
yudao-module-infra/src/main/resources/codegen/vue3_vben5_ele/schema/api/api.ts.vm
| 1 | #set ($apiName = "${table.moduleName.substring(0,1).toUpperCase()}${table.moduleName.substring(1)}${simpleClassName}Api") | 1 | #set ($apiName = "${table.moduleName.substring(0,1).toUpperCase()}${table.moduleName.substring(1)}${simpleClassName}Api") |
| 2 | +#if ( $table.templateType != 2 ) | ||
| 2 | import type { PageParam, PageResult } from '@vben/request'; | 3 | import type { PageParam, PageResult } from '@vben/request'; |
| 4 | +#end | ||
| 3 | import type { Dayjs } from 'dayjs'; | 5 | import type { Dayjs } from 'dayjs'; |
| 4 | 6 | ||
| 5 | import { requestClient } from '#/api/request'; | 7 | import { requestClient } from '#/api/request'; |
| @@ -97,8 +99,8 @@ export function update${simpleClassName}(data: ${apiName}.${simpleClassName}) { | @@ -97,8 +99,8 @@ export function update${simpleClassName}(data: ${apiName}.${simpleClassName}) { | ||
| 97 | export function delete${simpleClassName}(id: number) { | 99 | export function delete${simpleClassName}(id: number) { |
| 98 | return requestClient.delete(`${baseURL}/delete?id=${id}`); | 100 | return requestClient.delete(`${baseURL}/delete?id=${id}`); |
| 99 | } | 101 | } |
| 100 | - | ||
| 101 | #if ( $table.templateType != 2 && $deleteBatchEnable) | 102 | #if ( $table.templateType != 2 && $deleteBatchEnable) |
| 103 | + | ||
| 102 | /** 批量删除${table.classComment} */ | 104 | /** 批量删除${table.classComment} */ |
| 103 | export function delete${simpleClassName}List(ids: number[]) { | 105 | export function delete${simpleClassName}List(ids: number[]) { |
| 104 | return requestClient.delete( | 106 | return requestClient.delete( |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_ele/schema/views/form.vue.vm
| @@ -117,6 +117,10 @@ const [Modal, modalApi] = useVbenModal({ | @@ -117,6 +117,10 @@ const [Modal, modalApi] = useVbenModal({ | ||
| 117 | // 加载数据 | 117 | // 加载数据 |
| 118 | const data = modalApi.getData<${apiName}.${simpleClassName}>(); | 118 | const data = modalApi.getData<${apiName}.${simpleClassName}>(); |
| 119 | if (!data || !data.id) { | 119 | if (!data || !data.id) { |
| 120 | +#if (${table.templateType} == 2)## 树表特有 | ||
| 121 | + // 设置上级 | ||
| 122 | + await formApi.setValues(data); | ||
| 123 | +#end | ||
| 120 | return; | 124 | return; |
| 121 | } | 125 | } |
| 122 | modalApi.lock(); | 126 | modalApi.lock(); |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_ele/schema/views/index.vue.vm
| @@ -6,7 +6,7 @@ import type { ${apiName} } from '#/api/${table.moduleName}/${table.businessName} | @@ -6,7 +6,7 @@ import type { ${apiName} } from '#/api/${table.moduleName}/${table.businessName} | ||
| 6 | import { ref } from 'vue'; | 6 | import { ref } from 'vue'; |
| 7 | 7 | ||
| 8 | import {#if ($table.templateType != 2 && $deleteBatchEnable) confirm,#end Page, useVbenModal } from '@vben/common-ui'; | 8 | import {#if ($table.templateType != 2 && $deleteBatchEnable) confirm,#end Page, useVbenModal } from '@vben/common-ui'; |
| 9 | -import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; | 9 | +import { downloadFileFromBlobPart#if ($table.templateType != 2 && $deleteBatchEnable), isEmpty#end } from '@vben/utils'; |
| 10 | 10 | ||
| 11 | import { ElLoading, ElMessage#if ($table.templateType == 11), ElTabs, ElTabPane#end } from 'element-plus'; | 11 | import { ElLoading, ElMessage#if ($table.templateType == 11), ElTabs, ElTabPane#end } from 'element-plus'; |
| 12 | 12 | ||
| @@ -73,19 +73,19 @@ function onRefresh() { | @@ -73,19 +73,19 @@ function onRefresh() { | ||
| 73 | function handleCreate() { | 73 | function handleCreate() { |
| 74 | formModalApi.setData(null).open(); | 74 | formModalApi.setData(null).open(); |
| 75 | } | 75 | } |
| 76 | - | ||
| 77 | -/** 编辑${table.classComment} */ | ||
| 78 | -function handleEdit(row: ${apiName}.${simpleClassName}) { | ||
| 79 | - formModalApi.setData(row).open(); | ||
| 80 | -} | ||
| 81 | #if (${table.templateType} == 2)## 树表特有:新增下级 | 76 | #if (${table.templateType} == 2)## 树表特有:新增下级 |
| 82 | 77 | ||
| 83 | -/** 新增下级${table.classComment} */ | 78 | +/** 添加下级${table.classComment} */ |
| 84 | function handleAppend(row: ${apiName}.${simpleClassName}) { | 79 | function handleAppend(row: ${apiName}.${simpleClassName}) { |
| 85 | formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open(); | 80 | formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open(); |
| 86 | } | 81 | } |
| 87 | #end | 82 | #end |
| 88 | 83 | ||
| 84 | +/** 编辑${table.classComment} */ | ||
| 85 | +function handleEdit(row: ${apiName}.${simpleClassName}) { | ||
| 86 | + formModalApi.setData(row).open(); | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | /** 删除${table.classComment} */ | 89 | /** 删除${table.classComment} */ |
| 90 | async function handleDelete(row: ${apiName}.${simpleClassName}) { | 90 | async function handleDelete(row: ${apiName}.${simpleClassName}) { |
| 91 | const loadingInstance = ElLoading.service({ | 91 | const loadingInstance = ElLoading.service({ |
| @@ -145,16 +145,9 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -145,16 +145,9 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 145 | height: 'auto', | 145 | height: 'auto', |
| 146 | #end | 146 | #end |
| 147 | #if (${table.templateType} == 2)## 树表设置 | 147 | #if (${table.templateType} == 2)## 树表设置 |
| 148 | - treeConfig: { | ||
| 149 | - parentField: '${treeParentColumn.javaField}', | ||
| 150 | - rowField: 'id', | ||
| 151 | - transform: true, | ||
| 152 | - expandAll: true, | ||
| 153 | - reserve: true, | ||
| 154 | - }, | ||
| 155 | - pagerConfig: { | ||
| 156 | - enabled: false, | ||
| 157 | - }, | 148 | + pagerConfig: { |
| 149 | + enabled: false, | ||
| 150 | + }, | ||
| 158 | #else## 标准表设置 | 151 | #else## 标准表设置 |
| 159 | keepSource: true, | 152 | keepSource: true, |
| 160 | #end | 153 | #end |
| @@ -186,15 +179,24 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -186,15 +179,24 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 186 | refresh: true, | 179 | refresh: true, |
| 187 | search: true, | 180 | search: true, |
| 188 | }, | 181 | }, |
| 182 | +#if (${table.templateType} == 2)## 树表设置 | ||
| 183 | + treeConfig: { | ||
| 184 | + parentField: '${treeParentColumn.javaField}', | ||
| 185 | + rowField: 'id', | ||
| 186 | + transform: true, | ||
| 187 | + expandAll: true, | ||
| 188 | + reserve: true, | ||
| 189 | + }, | ||
| 190 | +#end | ||
| 189 | } as VxeTableGridOptions<${apiName}.${simpleClassName}>, | 191 | } as VxeTableGridOptions<${apiName}.${simpleClassName}>, |
| 190 | -#if (${table.templateType} == 11 || $deleteBatchEnable) | 192 | +#if (${table.templateType} == 11 || (${table.templateType} != 2 && $deleteBatchEnable)) |
| 191 | gridEvents: { | 193 | gridEvents: { |
| 192 | #if(${table.templateType} == 11) | 194 | #if(${table.templateType} == 11) |
| 193 | cellClick: ({ row }: { row: ${apiName}.${simpleClassName}}) => { | 195 | cellClick: ({ row }: { row: ${apiName}.${simpleClassName}}) => { |
| 194 | select${simpleClassName}.value = row; | 196 | select${simpleClassName}.value = row; |
| 195 | }, | 197 | }, |
| 196 | #end | 198 | #end |
| 197 | - #if(${table.templateType} != 2 && $deleteBatchEnable) | 199 | + #if (${table.templateType} != 2 && $deleteBatchEnable) |
| 198 | checkboxAll: handleRowCheckboxChange, | 200 | checkboxAll: handleRowCheckboxChange, |
| 199 | checkboxChange: handleRowCheckboxChange, | 201 | checkboxChange: handleRowCheckboxChange, |
| 200 | #end | 202 | #end |
| @@ -229,13 +231,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -229,13 +231,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 229 | <template #toolbar-tools> | 231 | <template #toolbar-tools> |
| 230 | <TableAction | 232 | <TableAction |
| 231 | :actions="[ | 233 | :actions="[ |
| 232 | - #if (${table.templateType} == 2)## 树表特有:展开/收缩按钮 | ||
| 233 | - { | ||
| 234 | - label: isExpanded ? '收缩' : '展开', | ||
| 235 | - type: 'primary', | ||
| 236 | - onClick: toggleExpand, | ||
| 237 | - }, | ||
| 238 | - #end | ||
| 239 | { | 234 | { |
| 240 | label: $t('ui.actionTitle.create', ['${table.classComment}']), | 235 | label: $t('ui.actionTitle.create', ['${table.classComment}']), |
| 241 | type: 'primary', | 236 | type: 'primary', |
| @@ -243,6 +238,13 @@ const [Grid, gridApi] = useVbenVxeGrid({ | @@ -243,6 +238,13 @@ const [Grid, gridApi] = useVbenVxeGrid({ | ||
| 243 | auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'], | 238 | auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'], |
| 244 | onClick: handleCreate, | 239 | onClick: handleCreate, |
| 245 | }, | 240 | }, |
| 241 | + #if (${table.templateType} == 2)## 树表特有:展开/收缩按钮 | ||
| 242 | + { | ||
| 243 | + label: isExpanded ? '收缩' : '展开', | ||
| 244 | + type: 'primary', | ||
| 245 | + onClick: toggleExpand, | ||
| 246 | + }, | ||
| 247 | + #end | ||
| 246 | { | 248 | { |
| 247 | label: $t('ui.actionTitle.export'), | 249 | label: $t('ui.actionTitle.export'), |
| 248 | type: 'primary', | 250 | type: 'primary', |