feat: 【ele】任务管理新增批量删除

pull/146/head
puhui999 2025-06-16 21:42:11 +08:00
parent 0be48ce623
commit a0e4b52251
3 changed files with 68 additions and 30 deletions

View File

@ -45,6 +45,11 @@ export function deleteJob(id: number) {
return requestClient.delete(`/infra/job/delete?id=${id}`); return requestClient.delete(`/infra/job/delete?id=${id}`);
} }
/** 批量删除定时任务调度 */
export function deleteJobList(ids: number[]) {
return requestClient.delete(`/infra/job/delete-list?ids=${ids.join(',')}`);
}
/** 导出定时任务调度 */ /** 导出定时任务调度 */
export function exportJob(params: any) { export function exportJob(params: any) {
return requestClient.download('/infra/job/export-excel', { params }); return requestClient.download('/infra/job/export-excel', { params });

View File

@ -128,6 +128,7 @@ export function useGridColumns<T = InfraJobApi.Job>(
onActionClick: OnActionClickFn<T>, onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] { ): VxeTableGridOptions['columns'] {
return [ return [
{ type: 'checkbox', width: 40 },
{ {
field: 'id', field: 'id',
title: '任务编号', title: '任务编号',

View File

@ -5,17 +5,18 @@ import type {
} from '#/adapter/vxe-table'; } from '#/adapter/vxe-table';
import type { InfraJobApi } from '#/api/infra/job'; import type { InfraJobApi } from '#/api/infra/job';
import { ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { Download, History, Plus } from '@vben/icons'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { downloadFileFromBlobPart } from '@vben/utils';
import { ElButton, ElLoading, ElMessage } from 'element-plus'; import { ElLoading, ElMessage } from 'element-plus';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
deleteJob, deleteJob,
deleteJobList,
exportJob, exportJob,
getJobPage, getJobPage,
runJob, runJob,
@ -117,6 +118,26 @@ async function onDelete(row: InfraJobApi.Job) {
} }
} }
/** 批量删除任务 */
async function onDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
fullscreen: true,
});
try {
await deleteJobList(checkedIds.value);
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
loadingInstance.close();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({ records }: { records: InfraJobApi.Job[] }) {
checkedIds.value = records.map((item) => item.id as number);
}
/** 表格操作按钮的回调函数 */ /** 表格操作按钮的回调函数 */
function onActionClick({ code, row }: OnActionClickParams<InfraJobApi.Job>) { function onActionClick({ code, row }: OnActionClickParams<InfraJobApi.Job>) {
switch (code) { switch (code) {
@ -174,6 +195,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
search: true, search: true,
}, },
} as VxeTableGridOptions<InfraJobApi.Job>, } as VxeTableGridOptions<InfraJobApi.Job>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
}); });
</script> </script>
@ -189,32 +214,39 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DetailModal /> <DetailModal />
<Grid table-title=""> <Grid table-title="">
<template #toolbar-tools> <template #toolbar-tools>
<ElButton <TableAction
type="primary" :actions="[
@click="onCreate" {
v-access:code="['infra:job:create']" label: $t('ui.actionTitle.create', ['任务']),
> type: 'primary',
<Plus class="size-5" /> icon: ACTION_ICON.ADD,
{{ $t('ui.actionTitle.create', ['任务']) }} auth: ['infra:job:create'],
</ElButton> onClick: onCreate,
<ElButton },
type="primary" {
class="ml-2" label: $t('ui.actionTitle.export'),
@click="onExport" type: 'primary',
v-access:code="['infra:job:export']" icon: ACTION_ICON.DOWNLOAD,
> auth: ['infra:job:export'],
<Download class="size-5" /> onClick: onExport,
{{ $t('ui.actionTitle.export') }} },
</ElButton> {
<ElButton label: '执行日志',
type="primary" type: 'primary',
class="ml-2" icon: ACTION_ICON.MORE,
@click="onLog(undefined)" auth: ['infra:job:query'],
v-access:code="['infra:job:query']" onClick: () => onLog(undefined),
> },
<History class="size-5" /> {
执行日志 label: $t('ui.actionTitle.deleteBatch'),
</ElButton> type: 'danger',
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['infra:job:delete'],
onClick: onDeleteBatch,
},
]"
/>
</template> </template>
</Grid> </Grid>
</Page> </Page>