reactor:【system 系统管理】sms/channel 进一步统一代码风格
parent
965ccdbea1
commit
15359ab9a3
|
@ -48,6 +48,14 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'apiKey',
|
||||
label: '短信 API 的账号',
|
||||
|
@ -73,14 +81,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||
placeholder: '请输入短信发送回调 URL',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -134,14 +134,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||
{
|
||||
field: 'id',
|
||||
title: '编号',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'signature',
|
||||
title: '短信签名',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '渠道编码',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE },
|
||||
|
@ -150,6 +153,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||
{
|
||||
field: 'status',
|
||||
title: '启用状态',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
|
@ -158,27 +162,32 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
|||
{
|
||||
field: 'apiKey',
|
||||
title: '短信 API 的账号',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'apiSecret',
|
||||
title: '短信 API 的密钥',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'callbackUrl',
|
||||
title: '短信发送回调 URL',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
width: 220,
|
||||
fixed: 'right',
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
|
|
|
@ -4,8 +4,8 @@ import type { SystemSmsChannelApi } from '#/api/system/sms/channel';
|
|||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
|
@ -13,7 +13,6 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
|||
import {
|
||||
deleteSmsChannel,
|
||||
deleteSmsChannelList,
|
||||
exportSmsChannel,
|
||||
getSmsChannelPage,
|
||||
} from '#/api/system/sms/channel';
|
||||
import { $t } from '#/locales';
|
||||
|
@ -27,16 +26,10 @@ const [FormModal, formModalApi] = useVbenModal({
|
|||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function handleExport() {
|
||||
const data = await exportSmsChannel(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '短信渠道.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建短信渠道 */
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
|
@ -51,15 +44,29 @@ function handleEdit(row: SystemSmsChannelApi.SmsChannel) {
|
|||
async function handleDelete(row: SystemSmsChannelApi.SmsChannel) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.signature]),
|
||||
key: 'action_key_msg',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteSmsChannel(row.id as number);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.signature]),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
onRefresh();
|
||||
message.success($t('ui.actionMessage.deleteSuccess', [row.signature]));
|
||||
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 deleteSmsChannelList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
message.success($t('ui.actionMessage.deleteSuccess'));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
|
@ -74,30 +81,6 @@ function handleRowCheckboxChange({
|
|||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 批量删除处理 */
|
||||
async function handleDeleteBatch() {
|
||||
if (checkedIds.value.length === 0) {
|
||||
message.warning('请至少选择一条数据');
|
||||
return;
|
||||
}
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', ['短信渠道']),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
try {
|
||||
await deleteSmsChannelList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', ['短信渠道']),
|
||||
key: 'action_key_msg',
|
||||
});
|
||||
checkedIds.value = [];
|
||||
onRefresh();
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
|
@ -125,9 +108,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
checkboxConfig: {
|
||||
checkField: 'checked',
|
||||
},
|
||||
} as VxeTableGridOptions<SystemSmsChannelApi.SmsChannel>,
|
||||
gridEvents: {
|
||||
checkboxAll: handleRowCheckboxChange,
|
||||
|
@ -142,7 +122,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
<DocAlert title="短信配置" url="https://doc.iocoder.cn/sms/" />
|
||||
</template>
|
||||
|
||||
<FormModal @success="onRefresh" />
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="短信渠道列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
|
@ -155,18 +135,11 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['system:sms-channel:export'],
|
||||
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-channel:delete'],
|
||||
onClick: handleDeleteBatch,
|
||||
},
|
||||
|
|
|
@ -82,7 +82,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<Modal class="w-2/5" :title="getTitle">
|
||||
<Modal :title="getTitle">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemSmsChannelApi } from '#/api/system/sms/channel';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
const { hasAccessByCodes } = useAccess();
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
|
@ -132,14 +128,9 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns<T = SystemSmsChannelApi.SmsChannel>(
|
||||
onActionClick: OnActionClickFn<T>,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 40,
|
||||
},
|
||||
{ type: 'checkbox', width: 40 },
|
||||
{
|
||||
field: 'id',
|
||||
title: '编号',
|
||||
|
@ -168,11 +159,6 @@ export function useGridColumns<T = SystemSmsChannelApi.SmsChannel>(
|
|||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'apiKey',
|
||||
title: '短信 API 的账号',
|
||||
|
@ -195,29 +181,15 @@ export function useGridColumns<T = SystemSmsChannelApi.SmsChannel>(
|
|||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'operation',
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 180,
|
||||
align: 'center',
|
||||
width: 220,
|
||||
fixed: 'right',
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: 'signature',
|
||||
nameTitle: '短信渠道',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
{
|
||||
code: 'edit',
|
||||
show: hasAccessByCodes(['system:sms-channel:update']),
|
||||
},
|
||||
{
|
||||
code: 'delete',
|
||||
show: hasAccessByCodes(['system:sms-channel:delete']),
|
||||
},
|
||||
],
|
||||
},
|
||||
slots: { default: 'actions' },
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
<script lang="ts" setup>
|
||||
import type {
|
||||
OnActionClickParams,
|
||||
VxeTableGridOptions,
|
||||
} from '#/adapter/vxe-table';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemSmsChannelApi } from '#/api/system/sms/channel';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||
import { isEmpty } from '@vben/utils';
|
||||
|
||||
import { ElLoading, ElMessage } from 'element-plus';
|
||||
|
||||
|
@ -16,7 +13,6 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
|||
import {
|
||||
deleteSmsChannel,
|
||||
deleteSmsChannelList,
|
||||
exportSmsChannel,
|
||||
getSmsChannelPage,
|
||||
} from '#/api/system/sms/channel';
|
||||
import { $t } from '#/locales';
|
||||
|
@ -30,47 +26,48 @@ const [FormModal, formModalApi] = useVbenModal({
|
|||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
const data = await exportSmsChannel(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '短信渠道.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建短信渠道 */
|
||||
function onCreate() {
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑短信渠道 */
|
||||
function onEdit(row: SystemSmsChannelApi.SmsChannel) {
|
||||
function handleEdit(row: SystemSmsChannelApi.SmsChannel) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除短信渠道 */
|
||||
async function onDelete(row: SystemSmsChannelApi.SmsChannel) {
|
||||
async function handleDelete(row: SystemSmsChannelApi.SmsChannel) {
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', [row.signature]),
|
||||
});
|
||||
try {
|
||||
await deleteSmsChannel(row.id as number);
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.signature]));
|
||||
onRefresh();
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量删除短信渠道 */
|
||||
async function onDeleteBatch() {
|
||||
await confirm('确定要批量删除该短信渠道吗?');
|
||||
await deleteSmsChannelList(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 deleteSmsChannelList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
|
@ -82,29 +79,12 @@ function handleRowCheckboxChange({
|
|||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemSmsChannelApi.SmsChannel>) {
|
||||
switch (code) {
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(onActionClick),
|
||||
columns: useGridColumns(),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
|
@ -120,6 +100,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
isHover: true,
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: true,
|
||||
|
@ -139,7 +120,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
<DocAlert title="短信配置" url="https://doc.iocoder.cn/sms/" />
|
||||
</template>
|
||||
|
||||
<FormModal @success="onRefresh" />
|
||||
<FormModal @success="handleRefresh" />
|
||||
<Grid table-title="短信渠道列表">
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
|
@ -149,14 +130,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
type: 'primary',
|
||||
icon: ACTION_ICON.ADD,
|
||||
auth: ['system:sms-channel:create'],
|
||||
onClick: onCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.export'),
|
||||
type: 'primary',
|
||||
icon: ACTION_ICON.DOWNLOAD,
|
||||
auth: ['system:sms-channel:export'],
|
||||
onClick: onExport,
|
||||
onClick: handleCreate,
|
||||
},
|
||||
{
|
||||
label: $t('ui.actionTitle.deleteBatch'),
|
||||
|
@ -164,7 +138,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
icon: ACTION_ICON.DELETE,
|
||||
disabled: isEmpty(checkedIds),
|
||||
auth: ['system:sms-channel: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-channel:update'],
|
||||
onClick: handleEdit.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.delete'),
|
||||
type: 'danger',
|
||||
link: true,
|
||||
icon: ACTION_ICON.DELETE,
|
||||
auth: ['system:sms-channel:delete'],
|
||||
popConfirm: {
|
||||
title: $t('ui.actionMessage.deleteConfirm', [row.signature]),
|
||||
confirm: handleDelete.bind(null, row),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
|
|
|
@ -31,7 +31,7 @@ const [Form, formApi] = useVbenForm({
|
|||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
labelWidth: 120,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
|
|
Loading…
Reference in New Issue