reactor:【infra 基础设施】处理 vben + vben 代码模版(onRefresh => handleRefresh,toggleExpand => handleExpand)

This commit is contained in:
YunaiV 2025-09-06 09:42:40 +08:00
parent 5b29d5ff13
commit 9f66283052
7 changed files with 32 additions and 32 deletions

View File

@ -146,7 +146,7 @@ async function handleDelete(row: ${simpleClassName}Api.${simpleClassName}) {
duration: 0, duration: 0,
}); });
try { try {
await delete${simpleClassName}(row.id as number); await delete${simpleClassName}(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.id])); message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
await getList(); await getList();
} finally { } finally {
@ -195,7 +195,7 @@ try {
#if (${table.templateType} == 2) #if (${table.templateType} == 2)
/** 切换树形展开/收缩状态 */ /** 切换树形展开/收缩状态 */
const isExpanded = ref(true); const isExpanded = ref(true);
function toggleExpand() { function handleExpand() {
isExpanded.value = !isExpanded.value; isExpanded.value = !isExpanded.value;
tableRef.value?.setAllTreeExpand(isExpanded.value); tableRef.value?.setAllTreeExpand(isExpanded.value);
} }
@ -303,7 +303,7 @@ onMounted(() => {
v-model:hidden-search="hiddenSearchBar" v-model:hidden-search="hiddenSearchBar"
> >
#if (${table.templateType} == 2) #if (${table.templateType} == 2)
<Button @click="toggleExpand" class="mr-2"> <Button @click="handleExpand" class="mr-2">
{{ isExpanded ? '收缩' : '展开' }} {{ isExpanded ? '收缩' : '展开' }}
</Button> </Button>
#end #end

View File

@ -70,7 +70,7 @@ async function handleDelete(row: ${simpleClassName}Api.${subSimpleClassName}) {
duration: 0, duration: 0,
}); });
try { try {
await delete${subSimpleClassName}(row.id as number); await delete${subSimpleClassName}(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.id])); message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
await getList(); await getList();
} finally { } finally {

View File

@ -54,14 +54,14 @@ const [FormModal, formModalApi] = useVbenModal({
/** 切换树形展开/收缩状态 */ /** 切换树形展开/收缩状态 */
const isExpanded = ref(true); const isExpanded = ref(true);
function toggleExpand() { function handleExpand() {
isExpanded.value = !isExpanded.value; isExpanded.value = !isExpanded.value;
gridApi.grid.setAllTreeExpand(isExpanded.value); gridApi.grid.setAllTreeExpand(isExpanded.value);
} }
#end #end
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
#if ($table.templateType == 12) ## 内嵌情况 #if ($table.templateType == 12) ## 内嵌情况
gridApi.reload(); gridApi.reload();
#else #else
@ -93,9 +93,9 @@ async function handleDelete(row: ${apiName}.${simpleClassName}) {
duration: 0, duration: 0,
}); });
try { try {
await delete${simpleClassName}(row.id as number); await delete${simpleClassName}(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.id])); message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();
} }
@ -113,7 +113,7 @@ async function handleDeleteBatch() {
await delete${simpleClassName}List(checkedIds.value); await delete${simpleClassName}List(checkedIds.value);
checkedIds.value = []; checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess')); message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();
} }
@ -209,7 +209,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
#if ($table.templateType == 11) ## erp情况 #if ($table.templateType == 11) ## erp情况
<div> <div>
#end #end
@ -244,7 +244,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
{ {
label: isExpanded ? '收缩' : '展开', label: isExpanded ? '收缩' : '展开',
type: 'primary', type: 'primary',
onClick: toggleExpand, onClick: handleExpand,
}, },
#end #end
{ {

View File

@ -63,9 +63,9 @@ async function handleDelete(row: ${apiName}.${subSimpleClassName}) {
duration: 0, duration: 0,
}); });
try { try {
await delete${subSimpleClassName}(row.id as number); await delete${subSimpleClassName}(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.id])); message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();
} }
@ -82,7 +82,7 @@ async function handleDeleteBatch() {
await delete${subSimpleClassName}List(checkedIds.value); await delete${subSimpleClassName}List(checkedIds.value);
checkedIds.value = []; checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess', [row.id])); message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();
} }
@ -154,7 +154,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
/** 刷新表格 */ /** 刷新表格 */
async function onRefresh() { async function handleRefresh() {
#if ($table.templateType == 11) ## erp #if ($table.templateType == 11) ## erp
await gridApi.query(); await gridApi.query();
#else #else
@ -174,7 +174,7 @@ watch(
return; return;
} }
await nextTick(); await nextTick();
await onRefresh() await handleRefresh()
}, },
{ immediate: true }, { immediate: true },
); );
@ -182,7 +182,7 @@ watch(
<template> <template>
#if ($table.templateType == 11) ## erp #if ($table.templateType == 11) ## erp
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="${subTable.classComment}列表"> <Grid table-title="${subTable.classComment}列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction

View File

@ -195,7 +195,7 @@ try {
#if (${table.templateType} == 2) #if (${table.templateType} == 2)
/** 切换树形展开/收缩状态 */ /** 切换树形展开/收缩状态 */
const isExpanded = ref(true); const isExpanded = ref(true);
function toggleExpand() { function handleExpand() {
isExpanded.value = !isExpanded.value; isExpanded.value = !isExpanded.value;
tableRef.value?.setAllTreeExpand(isExpanded.value); tableRef.value?.setAllTreeExpand(isExpanded.value);
} }
@ -306,7 +306,7 @@ onMounted(() => {
v-model:hidden-search="hiddenSearchBar" v-model:hidden-search="hiddenSearchBar"
> >
#if (${table.templateType} == 2) #if (${table.templateType} == 2)
<el-button @click="toggleExpand" class="mr-2"> <el-button @click="handleExpand" class="mr-2">
{{ isExpanded ? '收缩' : '展开' }} {{ isExpanded ? '收缩' : '展开' }}
</el-button> </el-button>
#end #end

View File

@ -54,14 +54,14 @@ const [FormModal, formModalApi] = useVbenModal({
/** 切换树形展开/收缩状态 */ /** 切换树形展开/收缩状态 */
const isExpanded = ref(true); const isExpanded = ref(true);
function toggleExpand() { function handleExpand() {
isExpanded.value = !isExpanded.value; isExpanded.value = !isExpanded.value;
gridApi.grid.setAllTreeExpand(isExpanded.value); gridApi.grid.setAllTreeExpand(isExpanded.value);
} }
#end #end
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
#if ($table.templateType == 12) ## 内嵌情况 #if ($table.templateType == 12) ## 内嵌情况
gridApi.reload(); gridApi.reload();
#else #else
@ -92,9 +92,9 @@ async function handleDelete(row: ${apiName}.${simpleClassName}) {
text: $t('ui.actionMessage.deleting', [row.id]), text: $t('ui.actionMessage.deleting', [row.id]),
}); });
try { try {
await delete${simpleClassName}(row.id as number); await delete${simpleClassName}(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id])); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh(); handleRefresh();
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
} }
@ -111,7 +111,7 @@ async function handleDeleteBatch() {
await delete${simpleClassName}List(checkedIds.value); await delete${simpleClassName}List(checkedIds.value);
checkedIds.value = []; checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess')); ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh(); handleRefresh();
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
} }
@ -207,7 +207,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
#if ($table.templateType == 11) ## erp情况 #if ($table.templateType == 11) ## erp情况
<div> <div>
#end #end
@ -242,7 +242,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
{ {
label: isExpanded ? '收缩' : '展开', label: isExpanded ? '收缩' : '展开',
type: 'primary', type: 'primary',
onClick: toggleExpand, onClick: handleExpand,
}, },
#end #end
{ {

View File

@ -62,9 +62,9 @@ async function handleDelete(row: ${apiName}.${subSimpleClassName}) {
text: $t('ui.actionMessage.deleting', [row.id]), text: $t('ui.actionMessage.deleting', [row.id]),
}); });
try { try {
await delete${subSimpleClassName}(row.id as number); await delete${subSimpleClassName}(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id])); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
onRefresh(); handleRefresh();
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
} }
@ -80,7 +80,7 @@ async function handleDeleteBatch() {
await delete${subSimpleClassName}List(checkedIds.value); await delete${subSimpleClassName}List(checkedIds.value);
checkedIds.value = []; checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess')); ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh(); handleRefresh();
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
} }
@ -152,7 +152,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
/** 刷新表格 */ /** 刷新表格 */
async function onRefresh() { async function handleRefresh() {
#if ($table.templateType == 11) ## erp #if ($table.templateType == 11) ## erp
await gridApi.query(); await gridApi.query();
#else #else
@ -172,7 +172,7 @@ watch(
return; return;
} }
await nextTick(); await nextTick();
await onRefresh() await handleRefresh()
}, },
{ immediate: true }, { immediate: true },
); );
@ -180,7 +180,7 @@ watch(
<template> <template>
#if ($table.templateType == 11) ## erp #if ($table.templateType == 11) ## erp
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="${subTable.classComment}列表"> <Grid table-title="${subTable.classComment}列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction