Commit 39e7d782a759367d609ee73946fd79cfdd8ab4c7
1 parent
73e4f831
perf: vben5 代码生成 使用 table action
Showing
2 changed files
with
91 additions
and
78 deletions
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm
| 1 | 1 | import type { VbenFormSchema } from '#/adapter/form'; |
| 2 | -import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; | |
| 2 | +import type { VxeTableGridOptions } from '#/adapter/vxe-table'; | |
| 3 | 3 | import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}'; |
| 4 | 4 | |
| 5 | 5 | import { z } from '#/adapter/form'; |
| ... | ... | @@ -12,9 +12,6 @@ import { |
| 12 | 12 | import { get${simpleClassName}List } from '#/api/${table.moduleName}/${table.businessName}'; |
| 13 | 13 | import { handleTree } from '@vben/utils'; |
| 14 | 14 | #end |
| 15 | -import { useAccess } from '@vben/access'; | |
| 16 | - | |
| 17 | -const { hasAccessByCodes } = useAccess(); | |
| 18 | 15 | |
| 19 | 16 | /** 新增/修改的表单 */ |
| 20 | 17 | export function useFormSchema(): VbenFormSchema[] { |
| ... | ... | @@ -189,9 +186,7 @@ export function useGridFormSchema(): VbenFormSchema[] { |
| 189 | 186 | } |
| 190 | 187 | |
| 191 | 188 | /** 列表的字段 */ |
| 192 | -export function useGridColumns( | |
| 193 | - onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>, | |
| 194 | -): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] { | |
| 189 | +export function useGridColumns(): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] { | |
| 195 | 190 | return [ |
| 196 | 191 | #if ($table.templateType != 2 && $deleteBatchEnable) |
| 197 | 192 | { type: 'checkbox', width: 40 }, | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm
| 1 | 1 | <script lang="ts" setup> |
| 2 | -import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table'; | |
| 2 | +import type { VxeTableGridOptions } from '#/adapter/vxe-table'; | |
| 3 | 3 | import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.businessName}'; |
| 4 | 4 | |
| 5 | 5 | import { Page, useVbenModal } from '@vben/common-ui'; |
| 6 | -import { Button, message,Tabs } from 'ant-design-vue'; | |
| 7 | -import { Download, Plus, Trash2 } from '@vben/icons'; | |
| 6 | +import { message,Tabs } from 'ant-design-vue'; | |
| 8 | 7 | import Form from './modules/form.vue'; |
| 9 | 8 | |
| 10 | 9 | ## 特殊:主子表专属逻辑 |
| ... | ... | @@ -16,9 +15,9 @@ import Form from './modules/form.vue'; |
| 16 | 15 | #end |
| 17 | 16 | #end |
| 18 | 17 | |
| 19 | -import { ref, h, computed } from 'vue'; | |
| 18 | +import { ref, computed } from 'vue'; | |
| 20 | 19 | import { $t } from '#/locales'; |
| 21 | -import { useVbenVxeGrid } from '#/adapter/vxe-table'; | |
| 20 | +import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; | |
| 22 | 21 | #if (${table.templateType} == 2)## 树表接口 |
| 23 | 22 | import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; |
| 24 | 23 | #else## 标准表接口 |
| ... | ... | @@ -60,32 +59,34 @@ function onRefresh() { |
| 60 | 59 | } |
| 61 | 60 | |
| 62 | 61 | /** 创建${table.classComment} */ |
| 63 | -function onCreate() { | |
| 62 | +function handleCreate() { | |
| 64 | 63 | formModalApi.setData({}).open(); |
| 65 | 64 | } |
| 66 | 65 | |
| 67 | 66 | /** 编辑${table.classComment} */ |
| 68 | -function onEdit(row: ${simpleClassName}Api.${simpleClassName}) { | |
| 67 | +function handleEdit(row: ${simpleClassName}Api.${simpleClassName}) { | |
| 69 | 68 | formModalApi.setData(row).open(); |
| 70 | 69 | } |
| 71 | 70 | |
| 72 | 71 | #if (${table.templateType} == 2)## 树表特有:新增下级 |
| 73 | 72 | /** 新增下级${table.classComment} */ |
| 74 | -function onAppend(row: ${simpleClassName}Api.${simpleClassName}) { | |
| 73 | +function handleAppend(row: ${simpleClassName}Api.${simpleClassName}) { | |
| 75 | 74 | formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open(); |
| 76 | 75 | } |
| 77 | 76 | #end |
| 78 | 77 | |
| 79 | 78 | /** 删除${table.classComment} */ |
| 80 | -async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) { | |
| 79 | +async function handleDelete(row: ${simpleClassName}Api.${simpleClassName}) { | |
| 81 | 80 | const hideLoading = message.loading({ |
| 82 | 81 | content: $t('ui.actionMessage.deleting', [row.id]), |
| 83 | - duration: 0, | |
| 84 | - key: 'action_process_msg', | |
| 82 | + key: 'action_key_msg', | |
| 85 | 83 | }); |
| 86 | 84 | try { |
| 87 | 85 | await delete${simpleClassName}(row.id as number); |
| 88 | - message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) ); | |
| 86 | + message.success({ | |
| 87 | + content: $t('ui.actionMessage.deleteSuccess', [row.id]), | |
| 88 | + key: 'action_key_msg', | |
| 89 | + }); | |
| 89 | 90 | onRefresh(); |
| 90 | 91 | } finally { |
| 91 | 92 | hideLoading(); |
| ... | ... | @@ -94,15 +95,17 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) { |
| 94 | 95 | |
| 95 | 96 | #if ($table.templateType != 2 && $deleteBatchEnable) |
| 96 | 97 | /** 批量删除${table.classComment} */ |
| 97 | -async function onDeleteBatch() { | |
| 98 | +async function handleDeleteBatch() { | |
| 98 | 99 | const hideLoading = message.loading({ |
| 99 | 100 | content: $t('ui.actionMessage.deleting'), |
| 100 | - duration: 0, | |
| 101 | - key: 'action_process_msg', | |
| 101 | + key: 'action_key_msg', | |
| 102 | 102 | }); |
| 103 | 103 | try { |
| 104 | 104 | await delete${simpleClassName}ListByIds(deleteIds.value); |
| 105 | - message.success( $t('ui.actionMessage.deleteSuccess') ); | |
| 105 | + message.success({ | |
| 106 | + content: $t('ui.actionMessage.deleteSuccess'), | |
| 107 | + key: 'action_key_msg', | |
| 108 | + }); | |
| 106 | 109 | onRefresh(); |
| 107 | 110 | } finally { |
| 108 | 111 | hideLoading(); |
| ... | ... | @@ -120,40 +123,17 @@ function setDeleteIds({ |
| 120 | 123 | #end |
| 121 | 124 | |
| 122 | 125 | /** 导出表格 */ |
| 123 | -async function onExport() { | |
| 126 | +async function handleExport() { | |
| 124 | 127 | const data = await export${simpleClassName}(await gridApi.formApi.getValues()); |
| 125 | 128 | downloadFileFromBlobPart({ fileName: '${table.classComment}.xls', source: data }); |
| 126 | 129 | } |
| 127 | 130 | |
| 128 | -/** 表格操作按钮的回调函数 */ | |
| 129 | -function onActionClick({ | |
| 130 | - code, | |
| 131 | - row, | |
| 132 | -}: OnActionClickParams<${simpleClassName}Api.${simpleClassName}>) { | |
| 133 | - switch (code) { | |
| 134 | - #if (${table.templateType} == 2)## 树表特有:新增下级 | |
| 135 | - case 'append': { | |
| 136 | - onAppend(row); | |
| 137 | - break; | |
| 138 | - } | |
| 139 | - #end | |
| 140 | - case 'edit': { | |
| 141 | - onEdit(row); | |
| 142 | - break; | |
| 143 | - } | |
| 144 | - case 'delete': { | |
| 145 | - onDelete(row); | |
| 146 | - break; | |
| 147 | - } | |
| 148 | - } | |
| 149 | -} | |
| 150 | - | |
| 151 | 131 | const [Grid, gridApi] = useVbenVxeGrid({ |
| 152 | 132 | formOptions: { |
| 153 | 133 | schema: useGridFormSchema(), |
| 154 | 134 | }, |
| 155 | 135 | gridOptions: { |
| 156 | - columns: useGridColumns(onActionClick), | |
| 136 | + columns: useGridColumns(), | |
| 157 | 137 | #if (${table.templateType} == 11) |
| 158 | 138 | height: '600px', |
| 159 | 139 | #else |
| ... | ... | @@ -245,36 +225,74 @@ const [Grid, gridApi] = useVbenVxeGrid({ |
| 245 | 225 | </template> |
| 246 | 226 | #end |
| 247 | 227 | <template #toolbar-tools> |
| 248 | -#if (${table.templateType} == 2)## 树表特有:展开/收缩按钮 | |
| 249 | - <Button @click="toggleExpand" class="mr-2"> | |
| 250 | - {{ isExpanded ? '收缩' : '展开' }} | |
| 251 | - </Button> | |
| 252 | -#end | |
| 253 | - <Button :icon="h(Plus)" type="primary" @click="onCreate" v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:create']"> | |
| 254 | - {{ $t('ui.actionTitle.create', ['${table.classComment}']) }} | |
| 255 | - </Button> | |
| 256 | - <Button | |
| 257 | - :icon="h(Download)" | |
| 258 | - type="primary" | |
| 259 | - class="ml-2" | |
| 260 | - @click="onExport" | |
| 261 | - v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:export']" | |
| 262 | - > | |
| 263 | - {{ $t('ui.actionTitle.export') }} | |
| 264 | - </Button> | |
| 265 | -#if ($table.templateType != 2 && $deleteBatchEnable) | |
| 266 | - <Button | |
| 267 | - :icon="h(Trash2)" | |
| 268 | - type="primary" | |
| 269 | - danger | |
| 270 | - class="ml-2" | |
| 271 | - :disabled="isEmpty(deleteIds)" | |
| 272 | - @click="onDeleteBatch" | |
| 273 | - v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']" | |
| 274 | - > | |
| 275 | - 批量删除 | |
| 276 | - </Button> | |
| 277 | -#end | |
| 228 | + <TableAction | |
| 229 | + :actions="[ | |
| 230 | + #if (${table.templateType} == 2)## 树表特有:展开/收缩按钮 | |
| 231 | + { | |
| 232 | + label: isExpanded ? '收缩' : '展开', | |
| 233 | + type: 'primary', | |
| 234 | + onClick: toggleExpand, | |
| 235 | + }, | |
| 236 | + #end | |
| 237 | + { | |
| 238 | + label: $t('ui.actionTitle.create', ['${table.classComment}']), | |
| 239 | + type: 'primary', | |
| 240 | + icon: ACTION_ICON.ADD, | |
| 241 | + auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'], | |
| 242 | + onClick: handleCreate, | |
| 243 | + }, | |
| 244 | + { | |
| 245 | + label: $t('ui.actionTitle.export'), | |
| 246 | + type: 'primary', | |
| 247 | + icon: ACTION_ICON.DOWNLOAD, | |
| 248 | + auth: ['${table.moduleName}:${simpleClassName_strikeCase}:export'], | |
| 249 | + onClick: handleExport, | |
| 250 | + }, | |
| 251 | + #if ($table.templateType != 2 && $deleteBatchEnable) | |
| 252 | + { | |
| 253 | + label: $t('ui.actionTitle.deleteBatch'), | |
| 254 | + type: 'primary', | |
| 255 | + icon: ACTION_ICON.DELETE, | |
| 256 | + disabled: isEmpty(deleteIds), | |
| 257 | + auth: ['${table.moduleName}:${simpleClassName_strikeCase}:delete'], | |
| 258 | + onClick: handleDeleteBatch, | |
| 259 | + }, | |
| 260 | + #end | |
| 261 | + ]" | |
| 262 | + /> | |
| 263 | + </template> | |
| 264 | + <template #actions="{ row }"> | |
| 265 | + <TableAction | |
| 266 | + :actions="[ | |
| 267 | + #if (${table.templateType} == 2)## 树表特有:新增下级 | |
| 268 | + { | |
| 269 | + label: '新增下级', | |
| 270 | + type: 'link', | |
| 271 | + icon: ACTION_ICON.ADD, | |
| 272 | + auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'], | |
| 273 | + onClick: handleAppend.bind(null, row), | |
| 274 | + }, | |
| 275 | + #end | |
| 276 | + { | |
| 277 | + label: $t('common.edit'), | |
| 278 | + type: 'link', | |
| 279 | + icon: ACTION_ICON.EDIT, | |
| 280 | + auth: ['${table.moduleName}:${simpleClassName_strikeCase}:update'], | |
| 281 | + onClick: handleEdit.bind(null, row), | |
| 282 | + }, | |
| 283 | + { | |
| 284 | + label: $t('common.delete'), | |
| 285 | + type: 'link', | |
| 286 | + danger: true, | |
| 287 | + icon: ACTION_ICON.DELETE, | |
| 288 | + auth: ['${table.moduleName}:${simpleClassName_strikeCase}:delete'], | |
| 289 | + popConfirm: { | |
| 290 | + title: $t('ui.actionMessage.deleteConfirm', [row.id]), | |
| 291 | + confirm: handleDelete.bind(null, row), | |
| 292 | + }, | |
| 293 | + }, | |
| 294 | + ]" | |
| 295 | + /> | |
| 278 | 296 | </template> |
| 279 | 297 | </Grid> |
| 280 | 298 | ... | ... |