diff --git a/src/pages/system/messages/sms/channel/config.tsx b/src/pages/system/messages/sms/channel/config.tsx index 9127ea4..827c58b 100644 --- a/src/pages/system/messages/sms/channel/config.tsx +++ b/src/pages/system/messages/sms/channel/config.tsx @@ -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[] = [ +import type { SmsChannelVO } from '@/services/system/message/sms/channel'; +export const baseTenantColumns: ProColumns[] = [ { - 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[] = [ }; }, }, - render: (_, record: LoginLogVO) => + render: (_, record: SmsChannelVO) => dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'), }, ]; -export const descriptionsColumns = (): ProDescriptionsItemProps< - Record, - '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', }, ]; diff --git a/src/pages/system/messages/sms/channel/index.tsx b/src/pages/system/messages/sms/channel/index.tsx index 01d36c4..1b347c1 100644 --- a/src/pages/system/messages/sms/channel/index.tsx +++ b/src/pages/system/messages/sms/channel/index.tsx @@ -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(null); - const descriptionsRef = useRef(null); + const configurableDrawerRef = useRef(null); + const [type, setType] = useState<'create' | 'update'>('create'); + const [currentItem, setCurrentItem] = useState(); 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 = { + const handleAdd = () => { + setType('create'); + configurableDrawerRef.current?.open({}); + }; + const toolbarActions: ToolbarAction[] = [ + { + key: 'add', + label: '新建', + type: 'primary', + icon: , + onClick: handleAdd, + }, + ]; + const actionColumns: ProColumns = { title: '操作', dataIndex: 'option', valueType: 'option', fixed: 'right', width: 80, - render: (text: React.ReactNode, record: LoginLogVO) => [ - handleDetail(record)}> - 详情 + render: ( + text: React.ReactNode, + record: SmsChannelVO, + _: number, + action: ProCoreActionType | undefined, + ) => [ + handleEdit(record)}> + 编辑 , + { + await deleteSmsChannel(record.id); + message.success('删除成功'); + action?.reload?.(); + }} + okText="是" + cancelText="否" + > + + 删除 + + , ], }; + 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 ( <> - + ref={tableRef} columns={columns} request={onFetch} - headerTitle="登录日志" + toolbarActions={toolbarActions} + headerTitle="短信渠道" showIndex={false} showSelection={false} /> - ); diff --git a/src/services/system/message/sms/channel.tsx b/src/services/system/message/sms/channel.tsx index 558ea8c..840a1d7 100644 --- a/src/services/system/message/sms/channel.tsx +++ b/src/services/system/message/sms/channel.tsx @@ -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 }, });