feat:【INFRA 基础设施】新增 vben5-antd-schema 模板代码生成时,可生成批量删除

This commit is contained in:
puhui999 2025-05-19 12:55:07 +08:00
parent 9295d61030
commit 6dee926253
3 changed files with 59 additions and 6 deletions

View File

@ -89,6 +89,13 @@ export function delete${simpleClassName}(id: number) {
return requestClient.delete(`${baseURL}/delete?id=${id}`);
}
#if ( $table.templateType != 2 && $table.deleteBatch)
// 批量删除${table.classComment}
export function delete${simpleClassName}ByIds(ids: number[]) {
return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`)
}
#end
/** 导出${table.classComment} */
export function export${simpleClassName}(params: any) {
return requestClient.download('${baseURL}/export-excel', params);

View File

@ -193,6 +193,9 @@ export function useGridColumns(
onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
return [
#if ($table.templateType != 2 && $table.deleteBatch)
{ type: 'checkbox', width: 40 },
#end
#if ($table.templateType == 12) ## 内嵌情况
{ type: 'expand', width: 80, slots: { content: 'expand_content' } },
#end

View File

@ -4,7 +4,7 @@ import type { ${simpleClassName}Api } from '#/api/${table.moduleName}/${table.bu
import { Page, useVbenModal } from '@vben/common-ui';
import { Button, message,Tabs } from 'ant-design-vue';
import { Download, Plus } from '@vben/icons';
import { Download, Plus, Trash2 } from '@vben/icons';
import Form from './modules/form.vue';
## 特殊:主子表专属逻辑
@ -16,15 +16,15 @@ import Form from './modules/form.vue';
#end
#end
import { ref, h } from 'vue';
import { ref, h, computed } from 'vue';
import { $t } from '#/locales';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
#if (${table.templateType} == 2)## 树表接口
import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
#else## 标准表接口
import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
import { get${simpleClassName}Page, delete${simpleClassName},delete${simpleClassName}ByIds, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
#end
import { downloadFileFromBlobPart } from '@vben/utils';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { useGridColumns, useGridFormSchema } from './data';
@ -87,11 +87,31 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) {
await delete${simpleClassName}(row.id as number);
message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) );
onRefresh();
} catch {
} finally {
hideLoading();
}
}
#if ($table.templateType != 2 && $table.deleteBatch)
const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID
const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value));
/** 批量删除${table.classComment} */
async function onDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await delete${simpleClassName}ByIds(deleteIds.value);
message.success( $t('ui.actionMessage.deleteSuccess') );
onRefresh();
} finally {
hideLoading();
}
}
#end
/** 导出表格 */
async function onExport() {
const data = await export${simpleClassName}(await gridApi.formApi.getValues());
@ -177,11 +197,21 @@ const [Grid, gridApi] = useVbenVxeGrid({
search: true,
},
} as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>,
#if (${table.templateType} == 11)
#if (${table.templateType} == 11 || $table.deleteBatch)
gridEvents:{
#if(${table.templateType} == 11)
cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => {
select${simpleClassName}.value = row;
},
#end
#if($table.deleteBatch)
checkboxAll: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => {
deleteIds.value = records.map((item) => item.id);
},
checkboxChange: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => {
deleteIds.value = records.map((item) => item.id);
},
#end
}
#end
});
@ -229,6 +259,19 @@ const [Grid, gridApi] = useVbenVxeGrid({
>
{{ $t('ui.actionTitle.export') }}
</Button>
#if ($table.templateType != 2 && $table.deleteBatch)
<Button
:icon="h(Trash2)"
type="primary"
danger
class="ml-2"
:disabled="showDeleteBatchBtn"
@click="onDeleteBatch"
v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']"
>
批量删除
</Button>
#end
</template>
</Grid>