feat: 短信渠道
parent
198cd6912c
commit
8f385f1da3
|
@ -0,0 +1,60 @@
|
|||
import type { PageParam } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace SystemSmsChannelApi {
|
||||
/** 短信渠道信息 */
|
||||
export interface SmsChannelVO {
|
||||
id?: number;
|
||||
code: string;
|
||||
status: number;
|
||||
signature: string;
|
||||
remark: string;
|
||||
apiKey: string;
|
||||
apiSecret: string;
|
||||
callbackUrl: string;
|
||||
createTime?: Date;
|
||||
}
|
||||
}
|
||||
|
||||
/** 查询短信渠道列表 */
|
||||
export function getSmsChannelPage(params: PageParam) {
|
||||
return requestClient.get<{
|
||||
list: SystemSmsChannelApi.SmsChannelVO[];
|
||||
total: number;
|
||||
}>('/system/sms-channel/page', { params });
|
||||
}
|
||||
|
||||
/** 获得短信渠道精简列表 */
|
||||
export function getSimpleSmsChannelList() {
|
||||
return requestClient.get<SystemSmsChannelApi.SmsChannelVO[]>(
|
||||
'/system/sms-channel/simple-list',
|
||||
);
|
||||
}
|
||||
|
||||
/** 查询短信渠道详情 */
|
||||
export function getSmsChannel(id: number) {
|
||||
return requestClient.get<SystemSmsChannelApi.SmsChannelVO>(
|
||||
`/system/sms-channel/get?id=${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 新增短信渠道 */
|
||||
export function createSmsChannel(data: SystemSmsChannelApi.SmsChannelVO) {
|
||||
return requestClient.post({ url: '/system/sms-channel/create', data });
|
||||
}
|
||||
|
||||
/** 修改短信渠道 */
|
||||
export function updateSmsChannel(data: SystemSmsChannelApi.SmsChannelVO) {
|
||||
return requestClient.put({ url: '/system/sms-channel/update', data });
|
||||
}
|
||||
|
||||
/** 删除短信渠道 */
|
||||
export function deleteSmsChannel(id: number) {
|
||||
return requestClient.delete({ url: `/system/sms-channel/delete?id=${id}` });
|
||||
}
|
||||
|
||||
/** 导出短信渠道 */
|
||||
export function exportSmsChannel(params: SystemSmsChannelApi.SmsChannelVO) {
|
||||
return requestClient.download('/system/sms-channel/export', { params });
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import { requestClient } from '#/api/request';
|
||||
import type { PageParam } from '@vben/request';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace SystemUserApi {
|
||||
/** 用户信息 */
|
||||
export interface SystemUser {
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemSmsChannelApi } from '#/api/system/sms/smsChannel';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { CommonStatusEnum } from '#/utils/constants';
|
||||
import { DICT_TYPE, getDictOptions } from '#/utils/dict';
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
label: 'id',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'signature',
|
||||
label: '短信签名',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '渠道编码',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
options: getDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE, 'string'),
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '启用状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
},
|
||||
{
|
||||
fieldName: 'apiKey',
|
||||
label: '短信 API 的账号',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'apiSecret',
|
||||
label: '短信 API 的密钥',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'callbackUrl',
|
||||
label: '短信发送回调 URL',
|
||||
component: 'Input',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'signature',
|
||||
label: '短信签名',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '渠道编码',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE, 'string'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns<T = SystemSmsChannelApi.SmsChannelVO>(
|
||||
onActionClick: OnActionClickFn<T>,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
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 },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '启用状态',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
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: 'operation',
|
||||
title: '操作',
|
||||
minWidth: 180,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: 'signature',
|
||||
nameTitle: '短信渠道',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
<script lang="ts" setup>
|
||||
import type {
|
||||
OnActionClickParams,
|
||||
VxeTableGridOptions,
|
||||
} from '#/adapter/vxe-table';
|
||||
import type { SystemSmsChannelApi } from '#/api/system/sms/smsChannel';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Download, Plus } from '@vben/icons';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteSmsChannel,
|
||||
exportSmsChannel,
|
||||
getSmsChannelPage,
|
||||
} from '#/api/system/sms/smsChannel';
|
||||
import { $t } from '#/locales';
|
||||
import { downloadByData } from '#/utils/download';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
const data = await exportSmsChannel(await gridApi.formApi.getValues());
|
||||
downloadByData(data, '短信渠道.xls');
|
||||
}
|
||||
|
||||
/** 创建短信渠道 */
|
||||
function onCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑短信渠道 */
|
||||
function onEdit(row: SystemSmsChannelApi.SmsChannelVO) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除短信渠道 */
|
||||
async function onDelete(row: SystemSmsChannelApi.SmsChannelVO) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.signature]),
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await deleteSmsChannel(row.id as number);
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.signature]),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
onRefresh();
|
||||
} catch {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemSmsChannelApi.SmsChannelVO>) {
|
||||
switch (code) {
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(onActionClick),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getSmsChannelPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<SystemSmsChannelApi.SmsChannelVO>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<FormModal @success="onRefresh" />
|
||||
<Grid table-title="短信渠道列表">
|
||||
<template #toolbar-tools>
|
||||
<Button type="primary" @click="onCreate">
|
||||
<Plus class="size-5" />
|
||||
{{ $t('ui.actionTitle.create', ['短信渠道']) }}
|
||||
</Button>
|
||||
<Button type="primary" class="ml-2" @click="onExport">
|
||||
<Download class="size-5" />
|
||||
{{ $t('ui.actionTitle.export') }}
|
||||
</Button>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
|
@ -0,0 +1,84 @@
|
|||
<script lang="ts" setup>
|
||||
import type { SystemSmsChannelApi } from '#/api/system/sms/smsChannel';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createSmsChannel,
|
||||
getSmsChannel,
|
||||
updateSmsChannel,
|
||||
} from '#/api/system/sms/smsChannel';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<SystemSmsChannelApi.SmsChannelVO>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['短信渠道'])
|
||||
: $t('ui.actionTitle.create', ['短信渠道']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data =
|
||||
(await formApi.getValues()) as SystemSmsChannelApi.SmsChannelVO;
|
||||
try {
|
||||
await (formData.value?.id
|
||||
? updateSmsChannel(data)
|
||||
: createSmsChannel(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.operationSuccess'),
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
} finally {
|
||||
modalApi.lock(false);
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen) {
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<SystemSmsChannelApi.SmsChannelVO>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getSmsChannel(data.id as number);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.lock(false);
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
Loading…
Reference in New Issue