reactor:【system 系统管理】mail/account 进一步统一代码风格

This commit is contained in:
YunaiV
2025-09-06 10:37:26 +08:00
parent 0539aece1b
commit e3b2f944a8
5 changed files with 88 additions and 99 deletions

View File

@@ -128,26 +128,32 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'id', field: 'id',
title: '编号', title: '编号',
minWidth: 100,
}, },
{ {
field: 'mail', field: 'mail',
title: '邮箱', title: '邮箱',
minWidth: 160,
}, },
{ {
field: 'username', field: 'username',
title: '用户名', title: '用户名',
minWidth: 160,
}, },
{ {
field: 'host', field: 'host',
title: 'SMTP 服务器域名', title: 'SMTP 服务器域名',
minWidth: 150,
}, },
{ {
field: 'port', field: 'port',
title: 'SMTP 服务器端口', title: 'SMTP 服务器端口',
minWidth: 130,
}, },
{ {
field: 'sslEnable', field: 'sslEnable',
title: '是否开启 SSL', title: '是否开启 SSL',
minWidth: 120,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING }, props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
@@ -156,6 +162,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'starttlsEnable', field: 'starttlsEnable',
title: '是否开启 STARTTLS', title: '是否开启 STARTTLS',
minWidth: 145,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING }, props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
@@ -164,6 +171,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'createTime', field: 'createTime',
title: '创建时间', title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {

View File

@@ -4,7 +4,7 @@ import type { SystemMailAccountApi } from '#/api/system/mail/account';
import { ref } from 'vue'; import { ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils'; import { isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
@@ -26,7 +26,7 @@ const [FormModal, formModalApi] = useVbenModal({
}); });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
@@ -44,15 +44,28 @@ function handleEdit(row: SystemMailAccountApi.MailAccount) {
async function handleDelete(row: SystemMailAccountApi.MailAccount) { async function handleDelete(row: SystemMailAccountApi.MailAccount) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.mail]), content: $t('ui.actionMessage.deleting', [row.mail]),
key: 'action_key_msg',
}); });
try { try {
await deleteMailAccount(row.id as number); await deleteMailAccount(row.id as number);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.mail]));
content: $t('ui.actionMessage.deleteSuccess', [row.mail]), handleRefresh();
key: 'action_key_msg', } finally {
}); hideLoading();
onRefresh(); }
}
/** 批量删除邮箱账号 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
try {
await deleteMailAccountList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();
} }
@@ -67,23 +80,6 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!); checkedIds.value = records.map((item) => item.id!);
} }
/** 批量删除邮箱账号 */
async function handleDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteMailAccountList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
@@ -124,7 +120,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DocAlert title="邮件配置" url="https://doc.iocoder.cn/mail" /> <DocAlert title="邮件配置" url="https://doc.iocoder.cn/mail" />
</template> </template>
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="邮箱账号列表"> <Grid table-title="邮箱账号列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
@@ -137,12 +133,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
onClick: handleCreate, onClick: handleCreate,
}, },
{ {
label: '批量删除', label: $t('ui.actionTitle.deleteBatch'),
type: 'primary', type: 'primary',
danger: true, danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
auth: ['system:mail-account:delete'], auth: ['system:mail-account:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch, onClick: handleDeleteBatch,
}, },
]" ]"

View File

@@ -1,15 +1,11 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemMailAccountApi } from '#/api/system/mail/account';
import { useAccess } from '@vben/access';
import { DICT_TYPE } from '@vben/constants'; import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
import { z } from '#/adapter/form'; import { z } from '#/adapter/form';
const { hasAccessByCodes } = useAccess();
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
@@ -126,14 +122,9 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns<T = SystemMailAccountApi.MailAccount>( export function useGridColumns(): VxeTableGridOptions['columns'] {
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [ return [
{ { type: 'checkbox', width: 40 },
type: 'checkbox',
width: 40,
},
{ {
field: 'id', field: 'id',
title: '编号', title: '编号',
@@ -184,29 +175,10 @@ export function useGridColumns<T = SystemMailAccountApi.MailAccount>(
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'operation',
title: '操作', title: '操作',
minWidth: 130, width: 130,
align: 'center',
fixed: 'right', fixed: 'right',
cellRender: { slots: { default: 'actions' },
attrs: {
nameField: 'mail',
nameTitle: '邮箱账号',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['system:mail-account:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['system:mail-account:delete']),
},
],
},
}, },
]; ];
} }

View File

@@ -1,8 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { import type { VxeTableGridOptions } from '#/adapter/vxe-table';
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { SystemMailAccountApi } from '#/api/system/mail/account'; import type { SystemMailAccountApi } from '#/api/system/mail/account';
import { ref } from 'vue'; import { ref } from 'vue';
@@ -29,41 +26,48 @@ const [FormModal, formModalApi] = useVbenModal({
}); });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 创建邮箱账号 */ /** 创建邮箱账号 */
function onCreate() { function handleCreate() {
formModalApi.setData(null).open(); formModalApi.setData(null).open();
} }
/** 编辑邮箱账号 */ /** 编辑邮箱账号 */
function onEdit(row: SystemMailAccountApi.MailAccount) { function handleEdit(row: SystemMailAccountApi.MailAccount) {
formModalApi.setData(row).open(); formModalApi.setData(row).open();
} }
/** 删除邮箱账号 */ /** 删除邮箱账号 */
async function onDelete(row: SystemMailAccountApi.MailAccount) { async function handleDelete(row: SystemMailAccountApi.MailAccount) {
const loadingInstance = ElLoading.service({ const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.mail]), text: $t('ui.actionMessage.deleting', [row.mail]),
}); });
try { try {
await deleteMailAccount(row.id as number); await deleteMailAccount(row.id as number);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.mail])); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.mail]));
onRefresh(); handleRefresh();
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
} }
} }
/** 批量删除邮箱账号 */ /** 批量删除邮箱账号 */
async function onDeleteBatch() { async function handleDeleteBatch() {
await confirm('确定要批量删除该邮箱账号吗?'); await confirm($t('ui.actionMessage.deleteBatchConfirm'));
await deleteMailAccountList(checkedIds.value); const loadingInstance = ElLoading.service({
checkedIds.value = []; text: $t('ui.actionMessage.deletingBatch'),
ElMessage.success($t('ui.actionMessage.deleteSuccess')); });
onRefresh(); try {
await deleteMailAccountList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
loadingInstance.close();
}
} }
const checkedIds = ref<number[]>([]); const checkedIds = ref<number[]>([]);
@@ -75,29 +79,12 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!); checkedIds.value = records.map((item) => item.id!);
} }
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemMailAccountApi.MailAccount>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(onActionClick), columns: useGridColumns(),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@@ -113,6 +100,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@@ -131,7 +119,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DocAlert title="邮件配置" url="https://doc.iocoder.cn/mail" /> <DocAlert title="邮件配置" url="https://doc.iocoder.cn/mail" />
</template> </template>
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="邮箱账号列表"> <Grid table-title="邮箱账号列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
@@ -141,7 +129,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
type: 'primary', type: 'primary',
icon: ACTION_ICON.ADD, icon: ACTION_ICON.ADD,
auth: ['system:mail-account:create'], auth: ['system:mail-account:create'],
onClick: onCreate, onClick: handleCreate,
}, },
{ {
label: $t('ui.actionTitle.deleteBatch'), label: $t('ui.actionTitle.deleteBatch'),
@@ -149,7 +137,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds), disabled: isEmpty(checkedIds),
auth: ['system:mail-account:delete'], auth: ['system:mail-account:delete'],
onClick: onDeleteBatch, onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['system:mail-account:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['system:mail-account:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.mail]),
confirm: handleDelete.bind(null, row),
},
}, },
]" ]"
/> />

View File

@@ -31,7 +31,7 @@ const [Form, formApi] = useVbenForm({
class: 'w-full', class: 'w-full',
}, },
formItemClass: 'col-span-2', formItemClass: 'col-span-2',
labelWidth: 80, labelWidth: 140,
}, },
layout: 'horizontal', layout: 'horizontal',
schema: useFormSchema(), schema: useFormSchema(),
@@ -83,7 +83,7 @@ const [Modal, modalApi] = useVbenModal({
</script> </script>
<template> <template>
<Modal :title="getTitle"> <Modal :title="getTitle" class="w-1/3">
<Form class="mx-4" /> <Form class="mx-4" />
</Modal> </Modal>
</template> </template>