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

This commit is contained in:
puhui999
2025-06-15 17:02:10 +08:00
parent 34f41790c2
commit 0cc83967ed
45 changed files with 997 additions and 297 deletions

View File

@@ -88,6 +88,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'id',
title: '公告编号',

View File

@@ -2,12 +2,20 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemNoticeApi } from '#/api/system/notice';
import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteNotice, getNoticePage, pushNotice } from '#/api/system/notice';
import {
deleteNotice,
deleteNoticeList,
getNoticePage,
pushNotice,
} from '#/api/system/notice';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
@@ -37,14 +45,37 @@ function handleEdit(row: SystemNoticeApi.Notice) {
async function handleDelete(row: SystemNoticeApi.Notice) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.title]),
key: 'action_key_msg',
duration: 0,
key: 'action_process_msg',
});
try {
await deleteNotice(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.title]),
key: 'action_key_msg',
});
message.success($t('ui.actionMessage.deleteSuccess', [row.title]));
onRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemNoticeApi.Notice[];
}) {
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 deleteNoticeList(checkedIds.value);
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
@@ -59,10 +90,7 @@ async function handlePush(row: SystemNoticeApi.Notice) {
});
try {
await pushNotice(row.id as number);
message.success({
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_key_msg',
});
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
hideLoading();
}
@@ -89,12 +117,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<SystemNoticeApi.Notice>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
@@ -112,6 +145,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['system:notice:create'],
onClick: handleCreate,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:notice:delete'],
onClick: handleDeleteBatch,
},
]"
/>
</template>
@@ -139,7 +181,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
icon: ACTION_ICON.DELETE,
auth: ['system:notice:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
title: $t('ui.actionMessage.deleteConfirm', [row.title]),
confirm: handleDelete.bind(null, row),
},
},