Browse Source

别名优化

main
cs 2 months ago
parent
commit
8b13a5e9ab
  1. 1
      package.json
  2. 60
      src/pages/message/my/index.tsx
  3. 55
      src/pages/message/template/index.tsx
  4. 2
      src/store/message/my.ts
  5. 8
      src/types/message/my.ts
  6. 1
      src/types/message/template.ts

1
package.json

@ -16,6 +16,7 @@
"@ant-design/pro-components": "^2.7.15", "@ant-design/pro-components": "^2.7.15",
"@ant-design/pro-layout": "^7.19.12", "@ant-design/pro-layout": "^7.19.12",
"@ant-design/pro-provider": "^2.14.9", "@ant-design/pro-provider": "^2.14.9",
"@ant-design/pro-utils": "^2.15.17",
"@formily/antd-v5": "^1.2.3", "@formily/antd-v5": "^1.2.3",
"@formily/core": "^2.3.2", "@formily/core": "^2.3.2",
"@formily/react": "^2.3.2", "@formily/react": "^2.3.2",

60
src/pages/message/my/index.tsx

@ -1,5 +1,5 @@
import {useTranslation} from '@/i18n.ts' import {useTranslation} from '@/i18n.ts'
import {Badge, Button, Divider, Form, Input, Select, Space, Tooltip} from 'antd'
import {Badge, Button, Divider, Form, Input, Select, Space, Table, TableColumnsType, Tooltip} from 'antd'
import {useAtom, useAtomValue} from 'jotai' import {useAtom, useAtomValue} from 'jotai'
import React, {useEffect, useMemo, useState} from 'react' import React, {useEffect, useMemo, useState} from 'react'
import {BetaSchemaForm, ProColumns, ProFormColumnsType,} from '@ant-design/pro-components' import {BetaSchemaForm, ProColumns, ProFormColumnsType,} from '@ant-design/pro-components'
@ -11,6 +11,7 @@ import {Table as ProTable} from '@/components/table'
import {msgListAtom, msgSearchAtom, saveMsgAtom} from "@/store/message/my.ts"; import {msgListAtom, msgSearchAtom, saveMsgAtom} from "@/store/message/my.ts";
import {templateAllListAtom} from "@/store/message/template.ts"; import {templateAllListAtom} from "@/store/message/template.ts";
import {coverType, IMsgTemplate} from "@/types/message/template.ts"; import {coverType, IMsgTemplate} from "@/types/message/template.ts";
import dayjs from "dayjs";
const i18nPrefix = 'msgMy.list' const i18nPrefix = 'msgMy.list'
@ -83,7 +84,7 @@ const MdwMessage = () => {
} }
}, },
{ {
title: t(`${i18nPrefix}.columns.type`, '消息类型'),
title: t(`${i18nPrefix}.columns.type`, '通道类型'),
dataIndex: 'type', dataIndex: 'type',
valueType: 'select', valueType: 'select',
fieldProps: { fieldProps: {
@ -104,9 +105,12 @@ const MdwMessage = () => {
} }
}, },
{ {
title: t(`${i18nPrefix}.columns.token`, 'Telegram Token'),
title: t(`${i18nPrefix}.columns.token`, 'Telegram BOT API Token'),
dataIndex: 'token', dataIndex: 'token',
valueType: 'text', valueType: 'text',
fieldProps: {
placeholder: "请输入 @BotFather 获取到的BOT的API Token"
},
formItemProps: { formItemProps: {
hidden: templateType != 'TG', hidden: templateType != 'TG',
rules: [ rules: [
@ -179,14 +183,14 @@ const MdwMessage = () => {
}, },
}, },
{ {
title: t(`${i18nPrefix}.columns.dest`, '收件人(多个收件人用英文逗号隔开,如果类型是TG,则填token)'),
title: t(`${i18nPrefix}.columns.dest`, '收件人(多个收件人用英文逗号隔开;如果类型是Telegram,请填写User ID或Chat ID)'),
dataIndex: 'dest', dataIndex: 'dest',
valueType: 'textarea', valueType: 'textarea',
fieldProps: { fieldProps: {
maxLength: 1000, maxLength: 1000,
showCount: true, showCount: true,
rows: 5, rows: 5,
placeholder: 'aaa@qq.com,bbb@gmail.com',
placeholder: 'aaa@qq.com,bbb@gmail.com,-1001953214222,-1001953214333',
}, },
formItemProps: { formItemProps: {
rules: [ rules: [
@ -225,7 +229,19 @@ const MdwMessage = () => {
dataIndex: 'content', dataIndex: 'content',
}, },
{ {
title: t(`${i18nPrefix}.columns.dest`, '收件人'),
title: t(`${i18nPrefix}.columns.send_at`, '预计发送时间'),
dataIndex: 'send_at',
render: (_, record) => {
return <div>{record.send_at == 0 ? "立即" : dayjs(record.send_at).format('YYYY-MM-DD HH:mm:ss')}</div>
}
},
] as ProColumns[]
}, [search, currentTemplate])
const expandedRowRender = (record) => {
const expandedColumns: TableColumnsType = [
{
title: "收件人",
dataIndex: 'dest', dataIndex: 'dest',
}, },
{ {
@ -240,28 +256,13 @@ const MdwMessage = () => {
{ {
title: t(`${i18nPrefix}.columns.send_at`, '发送时间'), title: t(`${i18nPrefix}.columns.send_at`, '发送时间'),
dataIndex: 'send_at', dataIndex: 'send_at',
render: (_, record) => {
return <div>{record.send_at == 0 ? 0 : dayjs(record.send_at*1000).format('YYYY-MM-DD HH:mm:ss')}</div>
}
}, },
// {
// title: t(`${i18nPrefix}.columns.option`, '操作'),
// key: 'option',
// valueType: 'option',
// fixed: 'right',
// render: (_, record) => [
// <Popconfirm
// key={'del_confirm'}
// disabled={isDeleting}
// onConfirm={() => {
// deleteAppPackage(record.id)
// }}
// title={t('message.deleteConfirm')}>
// <a key="del">
// {t('actions.delete', '删除')}
// </a>
// </Popconfirm>,
// ]
// }
] as ProColumns[]
}, [search, currentTemplate])
];
return <Table columns={expandedColumns} dataSource={record.dest} pagination={false}/>;
}
useEffect(() => { useEffect(() => {
@ -354,6 +355,9 @@ const MdwMessage = () => {
}) })
}, },
}} }}
expandable={{
expandedRowRender,
}}
/> />
<BetaSchemaForm <BetaSchemaForm
grid={true} grid={true}
@ -376,7 +380,7 @@ const MdwMessage = () => {
}} }}
onFinish={async (values) => { onFinish={async (values) => {
saveOrUpdate({...values, "template_id": currentTemplate?.id})
saveOrUpdate({...values, "alias": currentTemplate?.alias})
}} }}
columns={drawerColumns as ProFormColumnsType[]}/> columns={drawerColumns as ProFormColumnsType[]}/>
<BetaSchemaForm <BetaSchemaForm

55
src/pages/message/template/index.tsx

@ -36,23 +36,35 @@ const MdwMessage = () => {
const [openFilter, setFilterOpen] = useState(false) const [openFilter, setFilterOpen] = useState(false)
const [searchKey, setSearchKey] = useState(search?.title) const [searchKey, setSearchKey] = useState(search?.title)
// 变量
const [templateField, setTemplateField] = useState<string[]>([]); const [templateField, setTemplateField] = useState<string[]>([]);
const [templateTitle, setTemplateTitle] = useState(''); const [templateTitle, setTemplateTitle] = useState('');
const [templateContent, setTemplateContent] = useState(''); const [templateContent, setTemplateContent] = useState('');
const [templateType, setTemplateType] = useState('') const [templateType, setTemplateType] = useState('')
const preContent = "你好,我叫${.name}"
useEffect(() => { useEffect(() => {
setTemplateType(currentTemplate?.type) setTemplateType(currentTemplate?.type)
// 初始化title和content,如果是创建,加载个默认值
if (form.getFieldValue('id') === 0) { if (form.getFieldValue('id') === 0) {
setTemplateField(['name']);
form.setFieldValue('content', preContent)
setTemplateContent(preContent)
} else { } else {
setTemplateField(currentTemplate?.fields.split(","));
if (currentTemplate?.content) {
setTemplateContent(currentTemplate?.content)
}
}
if (currentTemplate) {
setTemplateTitle(currentTemplate.title)
} }
}, [open]); }, [open]);
const handleChange = () => { const handleChange = () => {
console.log(templateTitle, templateContent)
// 使用正则表达式匹配 ${var} 格式的变量 // 使用正则表达式匹配 ${var} 格式的变量
const regex = /\${\.([a-zA-Z0-9_]+)}/g; const regex = /\${\.([a-zA-Z0-9_]+)}/g;
const matches = [...(templateTitle + templateContent).matchAll(regex)]; const matches = [...(templateTitle + templateContent).matchAll(regex)];
@ -111,7 +123,24 @@ const MdwMessage = () => {
} }
}, },
{ {
title: t(`${i18nPrefix}.columns.type`, '模板类型'),
title: t(`${i18nPrefix}.columns.alias`, '模板别名'),
dataIndex: 'alias',
valueType: 'text',
fieldProps: {
maxLength: 50,
showCount: true,
},
formItemProps: {
rules: [
{
required: true,
message: t('message.required', '模板名称必填')
}
]
}
},
{
title: t(`${i18nPrefix}.columns.type`, '通道类型'),
dataIndex: 'type', dataIndex: 'type',
valueType: 'select', valueType: 'select',
fieldProps: { fieldProps: {
@ -188,6 +217,15 @@ const MdwMessage = () => {
); );
} }
}, },
{
title: t(`${i18nPrefix}.columns.tag`, '标签'),
dataIndex: 'tag',
valueType: 'text',
fieldProps: {
maxLength: 50,
showCount: true,
},
},
] as ProColumns[] ] as ProColumns[]
}, [isDeleting, currentTemplate, search, templateField, templateType]) }, [isDeleting, currentTemplate, search, templateField, templateType])
@ -196,15 +234,16 @@ const MdwMessage = () => {
{ {
title: 'ID', title: 'ID',
dataIndex: 'id', dataIndex: 'id',
hideInTable: true,
hideInSearch: true,
formItemProps: {hidden: true}
}, },
{ {
title: t(`${i18nPrefix}.columns.name`, '模板名称'), title: t(`${i18nPrefix}.columns.name`, '模板名称'),
dataIndex: 'name', dataIndex: 'name',
}, },
{ {
title: t(`${i18nPrefix}.columns.alias`, '别名'),
dataIndex: 'alias',
},
{
title: t(`${i18nPrefix}.columns.type`, '模板类型'), title: t(`${i18nPrefix}.columns.type`, '模板类型'),
dataIndex: 'type', dataIndex: 'type',
render: (_, record) => { render: (_, record) => {
@ -220,6 +259,10 @@ const MdwMessage = () => {
dataIndex: 'content', dataIndex: 'content',
}, },
{ {
title: t(`${i18nPrefix}.columns.tag`, '标签'),
dataIndex: 'tag',
},
{
title: t(`${i18nPrefix}.columns.option`, '操作'), title: t(`${i18nPrefix}.columns.option`, '操作'),
key: 'option', key: 'option',
valueType: 'option', valueType: 'option',

2
src/store/message/my.ts

@ -14,6 +14,8 @@ type SearchParams = IPage & {
export const msgIdsAtom = atom<number>(0) export const msgIdsAtom = atom<number>(0)
export const currentRow = atom<IMsgMy>()
export const msgSearchAtom = atom<SearchParams>({ export const msgSearchAtom = atom<SearchParams>({
key: '', key: '',
pageSize: 10, pageSize: 10,

8
src/types/message/my.ts

@ -3,8 +3,14 @@ export interface IMsgMy {
template_id: number template_id: number
title: string title: string
send_content: string send_content: string
dest: string
type: string type: string
send_at: number
dest: IMsgDest[]
}
export interface IMsgDest {
id: number
dest: string
status: number status: number
error_message: string error_message: string
send_at: number send_at: number

1
src/types/message/template.ts

@ -6,6 +6,7 @@ export interface IMsgTemplate {
dest: string dest: string
type: string type: string
fields: string fields: string
alias: string
} }
export const coverType = (type: string) => { export const coverType = (type: string) => {

Loading…
Cancel
Save