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

This commit is contained in:
YunaiV
2025-09-06 11:13:27 +08:00
parent e3b2f944a8
commit 9565de2b5c
10 changed files with 134 additions and 149 deletions

View File

@@ -19,7 +19,7 @@ export namespace SystemMailTemplateApi {
}
/** 邮件发送信息 */
export interface MailSendReq {
export interface MailSendReqVO {
toMails: string[];
ccMails?: string[];
bccMails?: string[];
@@ -66,6 +66,6 @@ export function deleteMailTemplateList(ids: number[]) {
}
/** 发送邮件 */
export function sendMail(data: SystemMailTemplateApi.MailSendReq) {
export function sendMail(data: SystemMailTemplateApi.MailSendReqVO) {
return requestClient.post('/system/mail-template/send-mail', data);
}

View File

@@ -23,9 +23,8 @@ const [FormModal, formModalApi] = useVbenModal({
destroyOnClose: true,
});
const userList = ref<SystemUserApi.User[]>([]);
/** 获取负责人名称 */
const userList = ref<SystemUserApi.User[]>([]);
function getLeaderName(userId: number) {
return userList.value.find((user) => user.id === userId)?.nickname;
}

View File

@@ -69,11 +69,7 @@ export function useFormSchema(): VbenFormSchema[] {
{
fieldName: 'content',
label: '模板内容',
component: 'Textarea',
componentProps: {
placeholder: '请输入模板内容',
height: 300,
},
component: 'RichTextarea',
rules: 'required',
},
{
@@ -113,9 +109,11 @@ export function useSendMailFormSchema(): VbenFormSchema[] {
{
fieldName: 'content',
label: '模板内容',
component: 'Textarea',
component: 'RichTextarea',
componentProps: {
disabled: true,
options: {
readonly: true,
},
},
},
{
@@ -212,31 +210,38 @@ export function useGridColumns(
{
field: 'id',
title: '编号',
minWidth: 100,
},
{
field: 'code',
title: '模板编码',
minWidth: 120,
},
{
field: 'name',
title: '模板名称',
minWidth: 120,
},
{
field: 'title',
title: '模板标题',
minWidth: 120,
},
{
field: 'accountId',
title: '邮箱账号',
minWidth: 120,
formatter: ({ cellValue }) => getAccountMail?.(cellValue) || '-',
},
{
field: 'nickname',
title: '发送人名称',
minWidth: 120,
},
{
field: 'status',
title: '开启状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@@ -245,6 +250,7 @@ export function useGridColumns(
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{

View File

@@ -5,7 +5,7 @@ import type { SystemMailTemplateApi } from '#/api/system/mail/template';
import { onMounted, 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 { message } from 'ant-design-vue';
@@ -23,8 +23,6 @@ import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
import SendForm from './modules/send-form.vue';
const accountList = ref<SystemMailAccountApi.MailAccount[]>([]);
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
@@ -35,8 +33,14 @@ const [SendModal, sendModalApi] = useVbenModal({
destroyOnClose: true,
});
/** 获取邮箱账号 */
const accountList = ref<SystemMailAccountApi.MailAccount[]>([]);
function getAccountMail(accountId: number) {
return accountList.value.find((account) => account.id === accountId)?.mail;
}
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -57,17 +61,34 @@ 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]));
handleRefresh();
} finally {
hideLoading();
}
}
/** 批量删除邮件模板 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
onRefresh();
try {
await deleteMailTemplateList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
@@ -79,28 +100,6 @@ function handleRowCheckboxChange({
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 deleteMailTemplateList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
/** 获取邮箱账号 */
function getAccountMail(accountId: number) {
return accountList.value.find((account) => account.id === accountId)?.mail;
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -146,7 +145,7 @@ onMounted(async () => {
<DocAlert title="邮件配置" url="https://doc.iocoder.cn/mail" />
</template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<SendModal />
<Grid table-title="邮件模板列表">
<template #toolbar-tools>
@@ -160,12 +159,12 @@ onMounted(async () => {
onClick: handleCreate,
},
{
label: '批量删除',
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:mail-template:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"
@@ -184,7 +183,7 @@ onMounted(async () => {
{
label: '测试',
type: 'link',
icon: ACTION_ICON.EDIT,
icon: ACTION_ICON.VIEW,
auth: ['system:mail-template:send-mail'],
onClick: handleSend.bind(null, row),
},

View File

@@ -49,7 +49,7 @@ const [Modal, modalApi] = useVbenModal({
.map((email) => email.trim())
.filter((email) => email.length > 0);
};
const data: SystemMailTemplateApi.MailSendReq = {
const data: SystemMailTemplateApi.MailSendReqVO = {
toMails: parseEmails(values.toMails || ''),
ccMails: parseEmails(values.ccMails || ''),
bccMails: parseEmails(values.bccMails || ''),
@@ -112,7 +112,7 @@ function buildFormSchema() {
</script>
<template>
<Modal title="测试发送邮件">
<Modal title="测试发送邮件" class="w-1/3">
<Form class="mx-4" />
</Modal>
</template>