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

pull/210/head
YunaiV 2025-09-06 17:36:04 +08:00
parent 15359ab9a3
commit 03618a6265
8 changed files with 105 additions and 122 deletions

View File

@ -20,7 +20,7 @@ export namespace SystemSmsTemplateApi {
}
/** 发送短信请求 */
export interface SmsSendReq {
export interface SmsSendReqVO {
mobile: string;
templateCode: string;
templateParams: Record<string, any>;
@ -72,6 +72,6 @@ export function exportSmsTemplate(params: any) {
}
/** 发送短信 */
export function sendSms(data: SystemSmsTemplateApi.SmsSendReq) {
export function sendSms(data: SystemSmsTemplateApi.SmsSendReqVO) {
return requestClient.post('/system/sms-template/send-sms', data);
}

View File

@ -204,10 +204,12 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'id',
title: '编号',
minWidth: 100,
},
{
field: 'type',
title: '短信类型',
minWidth: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE },
@ -216,10 +218,12 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'name',
title: '模板名称',
minWidth: 120,
},
{
field: 'code',
title: '模板编码',
minWidth: 120,
},
{
field: 'content',
@ -229,6 +233,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'status',
title: '开启状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@ -237,10 +242,12 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'apiTemplateId',
title: '短信 API 的模板编号',
minWidth: 180,
},
{
field: 'channelCode',
title: '短信渠道',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE },
@ -249,11 +256,13 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'remark',
title: '备注',
minWidth: 120,
},
{
title: '操作',

View File

@ -4,7 +4,7 @@ import type { SystemSmsTemplateApi } from '#/api/system/sms/template';
import { ref } from 'vue';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
@ -33,7 +33,7 @@ const [SendModal, sendModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@ -62,15 +62,29 @@ function handleSend(row: SystemSmsTemplateApi.SmsTemplate) {
async function handleDelete(row: SystemSmsTemplateApi.SmsTemplate) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
duration: 0,
});
try {
await deleteSmsTemplate(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
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,
});
try {
await deleteSmsTemplateList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
@ -85,23 +99,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 deleteSmsTemplateList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
hideLoading();
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@ -143,7 +140,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DocAlert title="短信配置" url="https://doc.iocoder.cn/sms/" />
</template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<SendModal />
<Grid table-title="">
<template #toolbar-tools>
@ -164,11 +161,11 @@ const [Grid, gridApi] = useVbenVxeGrid({
onClick: handleExport,
},
{
label: '批量删除',
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:sms-template:delete'],
onClick: handleDeleteBatch,
},
@ -186,7 +183,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
onClick: handleEdit.bind(null, row),
},
{
label: '发送短信',
label: '测试',
type: 'link',
icon: ACTION_ICON.ADD,
auth: ['system:sms-template:send-sms'],

View File

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

View File

@ -42,7 +42,7 @@ const [Modal, modalApi] = useVbenModal({
paramsObj[param] = values[`param_${param}`];
});
}
const data: SystemSmsTemplateApi.SmsSendReq = {
const data: SystemSmsTemplateApi.SmsSendReqVO = {
mobile: values.mobile,
templateCode: formData.value?.code || '',
templateParams: paramsObj,
@ -83,7 +83,7 @@ const [Modal, modalApi] = useVbenModal({
});
/** 动态构建表单 schema */
const buildFormSchema = () => {
function buildFormSchema() {
const schema = useSendSmsFormSchema();
if (formData.value?.params) {
formData.value.params.forEach((param) => {
@ -99,7 +99,7 @@ const buildFormSchema = () => {
});
}
return schema;
};
}
</script>
<template>

View File

@ -1,8 +1,6 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemSmsTemplateApi } from '#/api/system/sms/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 { getSimpleSmsChannelList } from '#/api/system/sms/channel';
import { getRangePickerDefaultProps } from '#/utils';
const { hasAccessByCodes } = useAccess();
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
@ -201,14 +197,9 @@ export function useSendSmsFormSchema(): VbenFormSchema[] {
}
/** 列表的字段 */
export function useGridColumns<T = SystemSmsTemplateApi.SmsTemplate>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 40,
},
{ type: 'checkbox', width: 40 },
{
field: 'id',
title: '编号',
@ -247,11 +238,6 @@ export function useGridColumns<T = SystemSmsTemplateApi.SmsTemplate>(
props: { type: DICT_TYPE.COMMON_STATUS },
},
},
{
field: 'remark',
title: '备注',
minWidth: 120,
},
{
field: 'apiTemplateId',
title: '短信 API 的模板编号',
@ -273,34 +259,15 @@ export function useGridColumns<T = SystemSmsTemplateApi.SmsTemplate>(
formatter: 'formatDateTime',
},
{
field: 'operation',
field: 'remark',
title: '备注',
minWidth: 120,
},
{
title: '操作',
minWidth: 180,
align: 'center',
width: 220,
fixed: 'right',
cellRender: {
attrs: {
nameField: 'name',
nameTitle: '短信模板',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['system:sms-template:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['system:sms-template:delete']),
},
{
code: 'sms-send',
text: '发送短信',
show: hasAccessByCodes(['system:sms-template:send-sms']),
},
],
},
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 { SystemSmsTemplateApi } from '#/api/system/sms/template';
import { ref } from 'vue';
@ -36,52 +33,52 @@ const [SendModal, sendModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
/** 导出表格 */
async function onExport() {
async function handleExport() {
const data = await exportSmsTemplate(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '短信模板.xls', source: data });
}
/** 创建短信模板 */
function onCreate() {
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑短信模板 */
function onEdit(row: SystemSmsTemplateApi.SmsTemplate) {
function handleEdit(row: SystemSmsTemplateApi.SmsTemplate) {
formModalApi.setData(row).open();
}
/** 发送测试短信 */
function onSend(row: SystemSmsTemplateApi.SmsTemplate) {
function handleSend(row: SystemSmsTemplateApi.SmsTemplate) {
sendModalApi.setData(row).open();
}
/** 删除短信模板 */
async function onDelete(row: SystemSmsTemplateApi.SmsTemplate) {
async function handleDelete(row: SystemSmsTemplateApi.SmsTemplate) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteSmsTemplate(row.id as number);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh();
handleRefresh();
} finally {
loadingInstance.close();
}
}
/** 批量删除短信模板 */
async function onDeleteBatch() {
await confirm('确定要批量删除该短信模板吗?');
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
await deleteSmsTemplateList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
handleRefresh();
}
const checkedIds = ref<number[]>([]);
@ -93,33 +90,12 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!);
}
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemSmsTemplateApi.SmsTemplate>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
case 'sms-send': {
onSend(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(onActionClick),
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
@ -135,6 +111,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
@ -154,7 +131,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<DocAlert title="短信配置" url="https://doc.iocoder.cn/sms/" />
</template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<SendModal />
<Grid table-title="">
<template #toolbar-tools>
@ -165,14 +142,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['system:sms-template:create'],
onClick: onCreate,
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['system:sms-template:export'],
onClick: onExport,
onClick: handleExport,
},
{
label: $t('ui.actionTitle.deleteBatch'),
@ -180,7 +157,40 @@ const [Grid, gridApi] = useVbenVxeGrid({
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:sms-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:sms-template:update'],
onClick: handleEdit.bind(null, row),
},
{
label: '测试',
type: 'primary',
link: true,
icon: ACTION_ICON.VIEW,
auth: ['system:sms-template:send-sms'],
onClick: handleSend.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['system:sms-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({
});
/** 动态构建表单 schema */
const buildFormSchema = () => {
function buildFormSchema() {
const schema = useSendSmsFormSchema();
if (formData.value?.params) {
formData.value.params.forEach((param) => {
@ -99,11 +99,11 @@ const buildFormSchema = () => {
});
}
return schema;
};
}
</script>
<template>
<Modal title="发送短信">
<Modal class="w-1/3" title="发送短信">
<Form class="mx-4" />
</Modal>
</template>