feat: 短信渠道
This commit is contained in:
@@ -1,49 +1,55 @@
|
||||
import type {
|
||||
ProColumns,
|
||||
ProDescriptionsItemProps,
|
||||
ProFormColumnsType,
|
||||
} from '@ant-design/pro-components';
|
||||
import dayjs from 'dayjs';
|
||||
import type { LoginLogVO } from '@/services/system/log/login';
|
||||
export const baseTenantColumns: ProColumns<LoginLogVO>[] = [
|
||||
import type { SmsChannelVO } from '@/services/system/message/sms/channel';
|
||||
export const baseTenantColumns: ProColumns<SmsChannelVO>[] = [
|
||||
{
|
||||
title: '日志编号',
|
||||
title: '编号',
|
||||
dataIndex: 'id',
|
||||
tip: '日志编号',
|
||||
width: 100,
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: '操作类型',
|
||||
dataIndex: 'logType',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
tip: '操作类型', // 提示信息
|
||||
},
|
||||
{
|
||||
title: '操作模块',
|
||||
dataIndex: 'type',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: '用户名称',
|
||||
dataIndex: 'username',
|
||||
},
|
||||
{
|
||||
title: '登录地址',
|
||||
dataIndex: 'userIp',
|
||||
title: '短信签名',
|
||||
dataIndex: 'signature',
|
||||
},
|
||||
|
||||
{
|
||||
title: '浏览器',
|
||||
dataIndex: 'userAgent',
|
||||
title: '渠道编码',
|
||||
dataIndex: 'code',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: '登录结果',
|
||||
dataIndex: 'result',
|
||||
title: '启用状态',
|
||||
dataIndex: 'status',
|
||||
valueType: 'select',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: '短信 API 的账号',
|
||||
dataIndex: 'apiKey',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
|
||||
{
|
||||
title: '短信 API 的密钥',
|
||||
dataIndex: 'apiSecret',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: '短信发送回调 URL',
|
||||
dataIndex: 'callbackUrl',
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: '登录日期',
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateRange',
|
||||
search: {
|
||||
@@ -58,48 +64,64 @@ export const baseTenantColumns: ProColumns<LoginLogVO>[] = [
|
||||
};
|
||||
},
|
||||
},
|
||||
render: (_, record: LoginLogVO) =>
|
||||
render: (_, record: SmsChannelVO) =>
|
||||
dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
|
||||
},
|
||||
];
|
||||
|
||||
export const descriptionsColumns = (): ProDescriptionsItemProps<
|
||||
Record<string, any>,
|
||||
'text'
|
||||
>[] => [
|
||||
export const formColumns = (type: string): ProFormColumnsType[] => [
|
||||
{
|
||||
title: '日志编号',
|
||||
key: 'id',
|
||||
dataIndex: 'id',
|
||||
title: '短信签名',
|
||||
dataIndex: 'signature',
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入用户名',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作类型',
|
||||
key: 'logType',
|
||||
dataIndex: 'logType',
|
||||
title: '渠道编码',
|
||||
dataIndex: 'code',
|
||||
valueType: 'select',
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入用户名',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '用户名称',
|
||||
key: 'username',
|
||||
dataIndex: 'username',
|
||||
title: '启用状态',
|
||||
dataIndex: 'status',
|
||||
valueType: 'radio',
|
||||
},
|
||||
{
|
||||
title: '登录地址',
|
||||
key: 'userIp',
|
||||
dataIndex: 'userIp',
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
},
|
||||
{
|
||||
title: '浏览器',
|
||||
key: 'userAgent',
|
||||
dataIndex: 'userAgent',
|
||||
title: '短信 API 的账号',
|
||||
dataIndex: 'apiKey',
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入用户名',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '登录结果',
|
||||
key: 'result',
|
||||
dataIndex: 'result',
|
||||
title: '短信 API 的密钥',
|
||||
dataIndex: 'apiSecret',
|
||||
},
|
||||
{
|
||||
title: '登录日期',
|
||||
key: 'createTime',
|
||||
dataIndex: 'createTime',
|
||||
title: '短信发送回调 URL',
|
||||
dataIndex: 'callbackUrl',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,22 +1,38 @@
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import React, { useRef } from 'react';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type {
|
||||
ActionType,
|
||||
ProColumns,
|
||||
ProCoreActionType,
|
||||
} from '@ant-design/pro-components';
|
||||
import { message, Popconfirm } from 'antd';
|
||||
import React, { useCallback, useRef, useState } from 'react';
|
||||
import ConfigurableDrawerForm, {
|
||||
type ConfigurableDrawerFormRef,
|
||||
} from '@/components/DrawerForm';
|
||||
import EnhancedProTable from '@/components/EnhancedProTable';
|
||||
import ModalDescriptions, {
|
||||
type DescriptionsFormRef,
|
||||
} from '@/components/ModalDescriptions';
|
||||
import { getLoginLogPage, type LoginLogVO } from '@/services/system/log/login';
|
||||
import { baseTenantColumns, descriptionsColumns } from './config';
|
||||
import type { ToolbarAction } from '@/components/EnhancedProTable/types';
|
||||
import { formStatusType } from '@/constants';
|
||||
import {
|
||||
createSmsChannel,
|
||||
deleteSmsChannel,
|
||||
getSmsChannelPage,
|
||||
type SmsChannelVO,
|
||||
updateSmsChannel,
|
||||
} from '@/services/system/message/sms/channel';
|
||||
import { baseTenantColumns, formColumns } from './config';
|
||||
|
||||
const SyStemLogLogin = () => {
|
||||
const tableRef = useRef<ActionType>(null);
|
||||
const descriptionsRef = useRef<DescriptionsFormRef>(null);
|
||||
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
|
||||
const [type, setType] = useState<'create' | 'update'>('create');
|
||||
const [currentItem, setCurrentItem] = useState<SmsChannelVO>();
|
||||
const onFetch = async (
|
||||
params: LoginLogVO & {
|
||||
params: SmsChannelVO & {
|
||||
pageSize?: number;
|
||||
current?: number;
|
||||
},
|
||||
) => {
|
||||
const data = await getLoginLogPage({
|
||||
const data = await getSmsChannelPage({
|
||||
...params,
|
||||
pageNo: params.current,
|
||||
pageSize: params.pageSize,
|
||||
@@ -28,37 +44,88 @@ const SyStemLogLogin = () => {
|
||||
};
|
||||
};
|
||||
|
||||
const handleDetail = (record: LoginLogVO) => {
|
||||
descriptionsRef.current?.open(record);
|
||||
const handleEdit = (record: SmsChannelVO) => {
|
||||
setType('update');
|
||||
setCurrentItem(record);
|
||||
configurableDrawerRef.current?.open(record);
|
||||
};
|
||||
|
||||
const actionColumns: ProColumns<LoginLogVO> = {
|
||||
const handleAdd = () => {
|
||||
setType('create');
|
||||
configurableDrawerRef.current?.open({});
|
||||
};
|
||||
const toolbarActions: ToolbarAction[] = [
|
||||
{
|
||||
key: 'add',
|
||||
label: '新建',
|
||||
type: 'primary',
|
||||
icon: <PlusOutlined />,
|
||||
onClick: handleAdd,
|
||||
},
|
||||
];
|
||||
const actionColumns: ProColumns<SmsChannelVO> = {
|
||||
title: '操作',
|
||||
dataIndex: 'option',
|
||||
valueType: 'option',
|
||||
fixed: 'right',
|
||||
width: 80,
|
||||
render: (text: React.ReactNode, record: LoginLogVO) => [
|
||||
<a key="editable" onClick={() => handleDetail(record)}>
|
||||
详情
|
||||
render: (
|
||||
text: React.ReactNode,
|
||||
record: SmsChannelVO,
|
||||
_: number,
|
||||
action: ProCoreActionType | undefined,
|
||||
) => [
|
||||
<a key="editable" onClick={() => handleEdit(record)}>
|
||||
编辑
|
||||
</a>,
|
||||
<Popconfirm
|
||||
title="是否删除?"
|
||||
key="delete"
|
||||
onConfirm={async () => {
|
||||
await deleteSmsChannel(record.id);
|
||||
message.success('删除成功');
|
||||
action?.reload?.();
|
||||
}}
|
||||
okText="是"
|
||||
cancelText="否"
|
||||
>
|
||||
<a style={{ color: 'var(--ant-red)' }} key="delete">
|
||||
删除
|
||||
</a>
|
||||
</Popconfirm>,
|
||||
],
|
||||
};
|
||||
const handleSubmit = useCallback(
|
||||
async (values: SmsChannelVO) => {
|
||||
if (type === 'create') {
|
||||
await createSmsChannel(values);
|
||||
} else {
|
||||
await updateSmsChannel({
|
||||
...values,
|
||||
id: currentItem!.id,
|
||||
});
|
||||
}
|
||||
tableRef.current?.reload();
|
||||
return true;
|
||||
},
|
||||
[type, currentItem],
|
||||
);
|
||||
const columns = [...baseTenantColumns, actionColumns];
|
||||
return (
|
||||
<>
|
||||
<EnhancedProTable<LoginLogVO>
|
||||
<EnhancedProTable<SmsChannelVO>
|
||||
ref={tableRef}
|
||||
columns={columns}
|
||||
request={onFetch}
|
||||
headerTitle="登录日志"
|
||||
toolbarActions={toolbarActions}
|
||||
headerTitle="短信渠道"
|
||||
showIndex={false}
|
||||
showSelection={false}
|
||||
/>
|
||||
<ModalDescriptions
|
||||
ref={descriptionsRef}
|
||||
title="登录日志详情"
|
||||
columns={descriptionsColumns()}
|
||||
<ConfigurableDrawerForm
|
||||
ref={configurableDrawerRef}
|
||||
title={formStatusType[type]}
|
||||
columns={formColumns(type)}
|
||||
onSubmit={handleSubmit}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -56,7 +56,7 @@ export async function createSmsChannel(data: SmsChannelVO) {
|
||||
// return request.put({ url: '/system/sms-channel/update', data })
|
||||
// }
|
||||
export async function updateSmsChannel(data: SmsChannelVO) {
|
||||
return request("/system/sms-channel/create", {
|
||||
return request("/system/sms-channel/update", {
|
||||
method: "PUT",
|
||||
data,
|
||||
});
|
||||
@@ -66,7 +66,7 @@ export async function updateSmsChannel(data: SmsChannelVO) {
|
||||
// return request.delete({ url: '/system/sms-channel/delete?id=' + id })
|
||||
// }
|
||||
export async function deleteSmsChannel(id: number) {
|
||||
return request("/system/sms-channel/create", {
|
||||
return request("/system/sms-channel/delete", {
|
||||
method: "DELETE",
|
||||
params: { id },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user