feat: 【antd】新增批量删除操作

This commit is contained in:
puhui999
2025-06-15 15:11:19 +08:00
parent 413f3fae15
commit 1054eec9d1
15 changed files with 248 additions and 7 deletions

View File

@@ -2,14 +2,16 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { InfraFileApi } from '#/api/infra/file';
import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { openWindow } from '@vben/utils';
import { isEmpty, openWindow } from '@vben/utils';
import { useClipboard } from '@vueuse/core';
import { Button, Image, message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteFile, getFilePage } from '#/api/infra/file';
import { deleteFile, deleteFileList, getFilePage } from '#/api/infra/file';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
@@ -64,6 +66,31 @@ async function handleDelete(row: InfraFileApi.File) {
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: InfraFileApi.File[];
}) {
checkedIds.value = records.map((item) => item.id as number);
}
/** 批量删除文件 */
async function handleDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteFileList(checkedIds.value);
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -85,12 +112,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<InfraFileApi.File>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
@@ -108,6 +140,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['infra:file:create'],
onClick: handleUpload,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['infra:file:delete'],
onClick: handleDeleteBatch,
},
]"
/>
</template>