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

pull/210/head
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>

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

@ -1,8 +1,6 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemMailTemplateApi } from '#/api/system/mail/template';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { useAccess } from '@vben/access';
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
@ -10,8 +8,6 @@ import { z } from '#/adapter/form';
import { getSimpleMailAccountList } from '#/api/system/mail/account';
import { getRangePickerDefaultProps } from '#/utils';
const { hasAccessByCodes } = useAccess();
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
@ -73,11 +69,7 @@ export function useFormSchema(): VbenFormSchema[] {
{
fieldName: 'content',
label: '模板内容',
component: 'Textarea',
componentProps: {
placeholder: '请输入模板内容',
height: 300,
},
component: 'RichTextarea',
rules: 'required',
},
{
@ -117,9 +109,11 @@ export function useSendMailFormSchema(): VbenFormSchema[] {
{
fieldName: 'content',
label: '模板内容',
component: 'Textarea',
component: 'RichTextarea',
componentProps: {
disabled: true,
options: {
readonly: true,
},
},
},
{
@ -208,15 +202,11 @@ export function useGridFormSchema(): VbenFormSchema[] {
}
/** 列表的字段 */
export function useGridColumns<T = SystemMailTemplateApi.MailTemplate>(
onActionClick: OnActionClickFn<T>,
export function useGridColumns(
getAccountMail?: (accountId: number) => string | undefined,
): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 40,
},
{ type: 'checkbox', width: 40 },
{
field: 'id',
title: '编号',
@ -241,7 +231,7 @@ export function useGridColumns<T = SystemMailTemplateApi.MailTemplate>(
field: 'accountId',
title: '邮箱账号',
minWidth: 120,
formatter: (row) => getAccountMail?.(row.cellValue) || '-',
formatter: ({ cellValue }) => getAccountMail?.(cellValue) || '-',
},
{
field: 'nickname',
@ -264,34 +254,10 @@ export function useGridColumns<T = SystemMailTemplateApi.MailTemplate>(
formatter: 'formatDateTime',
},
{
field: 'operation',
title: '操作',
minWidth: 150,
align: 'center',
width: 220,
fixed: 'right',
cellRender: {
attrs: {
nameField: 'name',
nameTitle: '邮件模板',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['system:mail-template:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['system:mail-template:delete']),
},
{
code: 'send',
text: '测试',
show: hasAccessByCodes(['system:mail-template:send-mail']),
},
],
},
slots: { default: 'actions' },
},
];
}

View File

@ -1,8 +1,5 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemMailAccountApi } from '#/api/system/mail/account';
import type { SystemMailTemplateApi } from '#/api/system/mail/template';
@ -26,13 +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 getAccountMail = (accountId: number) => {
return accountList.value.find((account) => account.id === accountId)?.mail;
};
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
@ -43,47 +33,60 @@ 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();
}
/** 创建邮件模板 */
function onCreate() {
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑邮件模板 */
function onEdit(row: SystemMailTemplateApi.MailTemplate) {
function handleEdit(row: SystemMailTemplateApi.MailTemplate) {
formModalApi.setData(row).open();
}
/** 发送测试邮件 */
function onSend(row: SystemMailTemplateApi.MailTemplate) {
function handleSend(row: SystemMailTemplateApi.MailTemplate) {
sendModalApi.setData(row).open();
}
/** 删除邮件模板 */
async function onDelete(row: SystemMailTemplateApi.MailTemplate) {
async function handleDelete(row: SystemMailTemplateApi.MailTemplate) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteMailTemplate(row.id as number);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
handleRefresh();
} finally {
loadingInstance.close();
}
}
/** 批量删除邮件模板 */
async function onDeleteBatch() {
await confirm('确定要批量删除该邮件模板吗?');
await deleteMailTemplateList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deletingBatch'),
});
try {
await deleteMailTemplateList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
loadingInstance.close();
}
}
const checkedIds = ref<number[]>([]);
@ -95,33 +98,12 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!);
}
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemMailTemplateApi.MailTemplate>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
case 'send': {
onSend(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(onActionClick, getAccountMail),
columns: useGridColumns(getAccountMail),
height: 'auto',
keepSource: true,
proxyConfig: {
@ -137,6 +119,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
@ -160,7 +143,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>
@ -171,7 +154,7 @@ onMounted(async () => {
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['system:mail-template:create'],
onClick: onCreate,
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.deleteBatch'),
@ -179,7 +162,40 @@ onMounted(async () => {
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:mail-template: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-template:update'],
onClick: handleEdit.bind(null, row),
},
{
label: '测试',
type: 'primary',
link: true,
icon: ACTION_ICON.VIEW,
auth: ['system:mail-template:send-mail'],
onClick: handleSend.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['system:mail-template:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>

View File

@ -83,7 +83,7 @@ const [Modal, modalApi] = useVbenModal({
</script>
<template>
<Modal :title="getTitle">
<Modal :title="getTitle" class="w-1/3">
<Form class="mx-4" />
</Modal>
</template>

View File

@ -92,7 +92,7 @@ const [Modal, modalApi] = useVbenModal({
});
/** 动态构建表单 schema */
const buildFormSchema = () => {
function buildFormSchema() {
const schema = useSendMailFormSchema();
if (formData.value?.params) {
formData.value.params?.forEach((param: string) => {
@ -108,11 +108,11 @@ const buildFormSchema = () => {
});
}
return schema;
};
}
</script>
<template>
<Modal title="测试发送邮件">
<Modal title="测试发送邮件" class="w-1/3">
<Form class="mx-4" />
</Modal>
</template>