Browse Source

消息优化

main
cs 2 months ago
parent
commit
aff0d1dbfb
  1. 64
      src/pages/message/my/index.tsx
  2. 15
      src/pages/message/template/index.tsx

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

@ -16,7 +16,7 @@ const i18nPrefix = 'msgMy.list'
const MdwMessage = () => {
const {styles, cx} = useStyle()
const {styles} = useStyle()
const {t} = useTranslation()
const [form] = Form.useForm()
const [filterForm] = Form.useForm()
@ -31,13 +31,6 @@ const MdwMessage = () => {
const [searchKey, setSearchKey] = useState(search?.title)
const [templateType, setTemplateType] = useState('')
const typeHandlerChange = (value: string) => {
if (value !== 'EMAIL') {
setTemplateTitle('')
form.setFieldsValue({'title': undefined})
}
setTemplateType(value)
}
const templateChange = (index: number) => {
if (templateList && index !== undefined) {
@ -51,8 +44,6 @@ const MdwMessage = () => {
setCurrentTemplate(templateList[index])
form.setFieldsValue({...templateList[index], 'fieldList': result})
setTemplateType(templateList[index].type)
setTemplateTitle(templateList[index].title)
setTemplateContent(templateList[index].content)
} else {
form.resetFields()
setTemplateType('')
@ -60,44 +51,10 @@ const MdwMessage = () => {
}
}
const [templateTitle, setTemplateTitle] = useState('');
const [templateContent, setTemplateContent] = useState('');
useEffect(() => {
handleChange()
}, [templateTitle, templateContent]);
const handleContentChange = (e) => {
const value = e.target.value;
setTemplateContent(value)
};
const titheHandleContentChange = (e) => {
const value = e.target.value;
setTemplateTitle(value)
};
const handleChange = () => {
// 使用正则表达式匹配 ${var} 格式的变量
const regex = /\${\.([a-zA-Z0-9_]+)}/g;
const matches = [...(templateTitle + templateContent).matchAll(regex)];
// 提取变量名
const variables = Array.from(new Set(matches.map(match => match[1])));
const result = variables.map(item => {
return {
field_key: item,
field_value: ''
};
});
form.setFieldsValue({'fieldList': result})
};
const handleInputChange = (index, e) => {
form.getFieldValue("fieldList")[index].field_value = e.target.value
}
const drawerColumns = useMemo(() => {
return [
{
@ -136,7 +93,7 @@ const MdwMessage = () => {
{label: 'Telegram', value: 'TG'}
],
allowClear: false,
onChange: typeHandlerChange
disabled: true,
},
formItemProps: {
rules: [
@ -147,13 +104,26 @@ const MdwMessage = () => {
}
},
{
title: t(`${i18nPrefix}.columns.token`, 'Telegram Token'),
dataIndex: 'token',
valueType: 'text',
formItemProps: {
hidden: templateType != 'TG',
rules: [
{
required: templateType == 'TG',
}
]
},
},
{
title: t(`${i18nPrefix}.columns.title`, '标题'),
dataIndex: 'title',
valueType: 'text',
fieldProps: {
maxLength: 100,
showCount: true,
onChange: titheHandleContentChange,
disabled: true,
},
formItemProps: {
tooltip: '支持邮件类型',
@ -174,7 +144,7 @@ const MdwMessage = () => {
maxLength: 1000,
showCount: true,
rows: 15,
onChange: handleContentChange,
disabled: true,
},
formItemProps: {
rules: [

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

@ -77,6 +77,10 @@ const MdwMessage = () => {
};
const typeHandlerChange = (value) => {
if (value !== 'EMAIL') {
setTemplateTitle('')
form.setFieldsValue({'title': undefined})
}
setTemplateType(value)
}
@ -184,17 +188,6 @@ const MdwMessage = () => {
);
}
},
{
title: t(`${i18nPrefix}.columns.dest`, '收件人(多个收件人用英文逗号隔开,如果类型是TG,则填token)'),
dataIndex: 'dest',
valueType: 'textarea',
fieldProps: {
maxLength: 1000,
showCount: true,
rows: 15,
placeholder: 'aaa@qq.com,bbb@gmail.com',
},
},
] as ProColumns[]
}, [isDeleting, currentTemplate, search, templateField, templateType])

Loading…
Cancel
Save