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

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

View File

@@ -2,13 +2,17 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemMailAccountApi } from '#/api/system/mail/account';
import { ref } from 'vue';
import { DocAlert, 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 {
deleteMailAccount,
deleteMailAccountList,
getMailAccountPage,
} from '#/api/system/mail/account';
import { $t } from '#/locales';
@@ -40,14 +44,37 @@ function handleEdit(row: SystemMailAccountApi.MailAccount) {
async function handleDelete(row: SystemMailAccountApi.MailAccount) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.mail]),
key: 'action_key_msg',
duration: 0,
key: 'action_process_msg',
});
try {
await deleteMailAccount(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.mail]),
key: 'action_key_msg',
});
message.success($t('ui.actionMessage.deleteSuccess', [row.mail]));
onRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemMailAccountApi.MailAccount[];
}) {
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 deleteMailAccountList(checkedIds.value);
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
@@ -75,12 +102,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<SystemMailAccountApi.MailAccount>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
<template>
@@ -101,6 +133,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['system:mail-account:create'],
onClick: handleCreate,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:mail-account:delete'],
onClick: handleDeleteBatch,
},
]"
/>
</template>
@@ -121,7 +162,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
icon: ACTION_ICON.DELETE,
auth: ['system:mail-account:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
title: $t('ui.actionMessage.deleteConfirm', [row.mail]),
confirm: handleDelete.bind(null, row),
},
},

View File

@@ -192,6 +192,7 @@ export function useGridColumns(
getAccountMail?: (accountId: number) => string | undefined,
): VxeTableGridOptions['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'id',
title: '编号',

View File

@@ -6,6 +6,7 @@ import type { SystemMailTemplateApi } from '#/api/system/mail/template';
import { onMounted, ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
@@ -13,6 +14,7 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getSimpleMailAccountList } from '#/api/system/mail/account';
import {
deleteMailTemplate,
deleteMailTemplateList,
getMailTemplatePage,
} from '#/api/system/mail/template';
import { $t } from '#/locales';
@@ -55,17 +57,43 @@ function handleSend(row: SystemMailTemplateApi.MailTemplate) {
/** 删除邮件模板 */
async function handleDelete(row: SystemMailTemplateApi.MailTemplate) {
message.loading({
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
key: 'action_process_msg',
});
await deleteMailTemplate(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
try {
await deleteMailTemplate(row.id as number);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemMailTemplateApi.MailTemplate[];
}) {
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',
});
onRefresh();
try {
await deleteMailTemplateList(checkedIds.value);
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
/** 获取邮箱账号 */
@@ -94,12 +122,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<SystemMailTemplateApi.MailTemplate>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
/** 初始化 */
@@ -126,6 +159,15 @@ onMounted(async () => {
auth: ['system:mail-template:create'],
onClick: handleCreate,
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:mail-template:delete'],
onClick: handleDeleteBatch,
},
]"
/>
</template>