feat: 【ele】邮箱管理新增批量删除

This commit is contained in:
puhui999
2025-06-16 21:24:11 +08:00
parent 79c451d256
commit 3bae7aa442
6 changed files with 126 additions and 24 deletions

View File

@@ -5,14 +5,17 @@ import type {
} 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 { Plus } from '@vben/icons';
import { isEmpty } 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 {
deleteMailAccount,
deleteMailAccountList,
getMailAccountPage,
} from '#/api/system/mail/account';
import { $t } from '#/locales';
@@ -50,13 +53,35 @@ async function onDelete(row: SystemMailAccountApi.MailAccount) {
await deleteMailAccount(row.id as number);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.mail]));
onRefresh();
} catch {
// 异常处理
} finally {
loadingInstance.close();
}
}
/** 批量删除邮箱账号 */
async function onDeleteBatch() {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting'),
fullscreen: true,
});
try {
await deleteMailAccountList(checkedIds.value);
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
loadingInstance.close();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemMailAccountApi.MailAccount[];
}) {
checkedIds.value = records.map((item) => item.id as number);
}
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
@@ -101,6 +126,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
search: true,
},
} as VxeTableGridOptions<SystemMailAccountApi.MailAccount>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
<template>
@@ -112,14 +141,25 @@ const [Grid, gridApi] = useVbenVxeGrid({
<FormModal @success="onRefresh" />
<Grid table-title="邮箱账号列表">
<template #toolbar-tools>
<ElButton
type="primary"
@click="onCreate"
v-access:code="['system:mail-account:create']"
>
<Plus class="mr-2 size-5" />
{{ $t('ui.actionTitle.create', ['邮箱账号']) }}
</ElButton>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['邮箱账号']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['system:mail-account:create'],
onClick: onCreate,
},
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'danger',
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:mail-account:delete'],
onClick: onDeleteBatch,
},
]"
/>
</template>
</Grid>
</Page>