reactor:【infra 基础设施】处理 vben + element-plus 树形模版

This commit is contained in:
YunaiV
2025-09-05 22:59:57 +08:00
parent bc9d9bcda3
commit 716ac2f9ff
3 changed files with 36 additions and 28 deletions

View File

@@ -1,5 +1,7 @@
#set ($apiName = "${table.moduleName.substring(0,1).toUpperCase()}${table.moduleName.substring(1)}${simpleClassName}Api")
#if ( $table.templateType != 2 )
import type { PageParam, PageResult } from '@vben/request';
#end
import type { Dayjs } from 'dayjs';
import { requestClient } from '#/api/request';
@@ -97,8 +99,8 @@ export function update${simpleClassName}(data: ${apiName}.${simpleClassName}) {
export function delete${simpleClassName}(id: number) {
return requestClient.delete(`${baseURL}/delete?id=${id}`);
}
#if ( $table.templateType != 2 && $deleteBatchEnable)
/** 批量删除${table.classComment} */
export function delete${simpleClassName}List(ids: number[]) {
return requestClient.delete(

View File

@@ -117,6 +117,10 @@ const [Modal, modalApi] = useVbenModal({
// 加载数据
const data = modalApi.getData<${apiName}.${simpleClassName}>();
if (!data || !data.id) {
#if (${table.templateType} == 2)## 树表特有
// 设置上级
await formApi.setValues(data);
#end
return;
}
modalApi.lock();

View File

@@ -6,7 +6,7 @@ import type { ${apiName} } from '#/api/${table.moduleName}/${table.businessName}
import { ref } from 'vue';
import {#if ($table.templateType != 2 && $deleteBatchEnable) confirm,#end Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { downloadFileFromBlobPart#if ($table.templateType != 2 && $deleteBatchEnable), isEmpty#end } from '@vben/utils';
import { ElLoading, ElMessage#if ($table.templateType == 11), ElTabs, ElTabPane#end } from 'element-plus';
@@ -73,18 +73,18 @@ function onRefresh() {
function handleCreate() {
formModalApi.setData(null).open();
}
#if (${table.templateType} == 2)## 树表特有:新增下级
/** 添加下级${table.classComment} */
function handleAppend(row: ${apiName}.${simpleClassName}) {
formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open();
}
#end
/** 编辑${table.classComment} */
function handleEdit(row: ${apiName}.${simpleClassName}) {
formModalApi.setData(row).open();
}
#if (${table.templateType} == 2)## 树表特有:新增下级
/** 新增下级${table.classComment} */
function handleAppend(row: ${apiName}.${simpleClassName}) {
formModalApi.setData({ ${treeParentColumn.javaField}: row.id }).open();
}
#end
/** 删除${table.classComment} */
async function handleDelete(row: ${apiName}.${simpleClassName}) {
@@ -145,16 +145,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
height: 'auto',
#end
#if (${table.templateType} == 2)## 树表设置
treeConfig: {
parentField: '${treeParentColumn.javaField}',
rowField: 'id',
transform: true,
expandAll: true,
reserve: true,
},
pagerConfig: {
enabled: false,
},
pagerConfig: {
enabled: false,
},
#else## 标准表设置
keepSource: true,
#end
@@ -186,15 +179,24 @@ const [Grid, gridApi] = useVbenVxeGrid({
refresh: true,
search: true,
},
#if (${table.templateType} == 2)## 树表设置
treeConfig: {
parentField: '${treeParentColumn.javaField}',
rowField: 'id',
transform: true,
expandAll: true,
reserve: true,
},
#end
} as VxeTableGridOptions<${apiName}.${simpleClassName}>,
#if (${table.templateType} == 11 || $deleteBatchEnable)
#if (${table.templateType} == 11 || (${table.templateType} != 2 && $deleteBatchEnable))
gridEvents: {
#if(${table.templateType} == 11)
cellClick: ({ row }: { row: ${apiName}.${simpleClassName}}) => {
select${simpleClassName}.value = row;
},
#end
#if(${table.templateType} != 2 && $deleteBatchEnable)
#if (${table.templateType} != 2 && $deleteBatchEnable)
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
#end
@@ -229,13 +231,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template #toolbar-tools>
<TableAction
:actions="[
#if (${table.templateType} == 2)## 树表特有:展开/收缩按钮
{
label: isExpanded ? '收缩' : '展开',
type: 'primary',
onClick: toggleExpand,
},
#end
{
label: $t('ui.actionTitle.create', ['${table.classComment}']),
type: 'primary',
@@ -243,6 +238,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['${table.moduleName}:${simpleClassName_strikeCase}:create'],
onClick: handleCreate,
},
#if (${table.templateType} == 2)## 树表特有:展开/收缩按钮
{
label: isExpanded ? '收缩' : '展开',
type: 'primary',
onClick: toggleExpand,
},
#end
{
label: $t('ui.actionTitle.export'),
type: 'primary',