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 MdwMessage = () => {
const {styles, cx} = useStyle()
const {styles} = useStyle()
const {t} = useTranslation() const {t} = useTranslation()
const [form] = Form.useForm() const [form] = Form.useForm()
const [filterForm] = Form.useForm() const [filterForm] = Form.useForm()
@ -31,13 +31,6 @@ const MdwMessage = () => {
const [searchKey, setSearchKey] = useState(search?.title) const [searchKey, setSearchKey] = useState(search?.title)
const [templateType, setTemplateType] = useState('') const [templateType, setTemplateType] = useState('')
const typeHandlerChange = (value: string) => {
if (value !== 'EMAIL') {
setTemplateTitle('')
form.setFieldsValue({'title': undefined})
}
setTemplateType(value)
}
const templateChange = (index: number) => { const templateChange = (index: number) => {
if (templateList && index !== undefined) { if (templateList && index !== undefined) {
@ -51,8 +44,6 @@ const MdwMessage = () => {
setCurrentTemplate(templateList[index]) setCurrentTemplate(templateList[index])
form.setFieldsValue({...templateList[index], 'fieldList': result}) form.setFieldsValue({...templateList[index], 'fieldList': result})
setTemplateType(templateList[index].type) setTemplateType(templateList[index].type)
setTemplateTitle(templateList[index].title)
setTemplateContent(templateList[index].content)
} else { } else {
form.resetFields() form.resetFields()
setTemplateType('') 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) => { const handleInputChange = (index, e) => {
form.getFieldValue("fieldList")[index].field_value = e.target.value form.getFieldValue("fieldList")[index].field_value = e.target.value
} }
const drawerColumns = useMemo(() => { const drawerColumns = useMemo(() => {
return [ return [
{ {
@ -136,7 +93,7 @@ const MdwMessage = () => {
{label: 'Telegram', value: 'TG'} {label: 'Telegram', value: 'TG'}
], ],
allowClear: false, allowClear: false,
onChange: typeHandlerChange
disabled: true,
}, },
formItemProps: { formItemProps: {
rules: [ 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`, '标题'), title: t(`${i18nPrefix}.columns.title`, '标题'),
dataIndex: 'title', dataIndex: 'title',
valueType: 'text', valueType: 'text',
fieldProps: { fieldProps: {
maxLength: 100, maxLength: 100,
showCount: true, showCount: true,
onChange: titheHandleContentChange,
disabled: true,
}, },
formItemProps: { formItemProps: {
tooltip: '支持邮件类型', tooltip: '支持邮件类型',
@ -174,7 +144,7 @@ const MdwMessage = () => {
maxLength: 1000, maxLength: 1000,
showCount: true, showCount: true,
rows: 15, rows: 15,
onChange: handleContentChange,
disabled: true,
}, },
formItemProps: { formItemProps: {
rules: [ rules: [

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

@ -77,6 +77,10 @@ const MdwMessage = () => {
}; };
const typeHandlerChange = (value) => { const typeHandlerChange = (value) => {
if (value !== 'EMAIL') {
setTemplateTitle('')
form.setFieldsValue({'title': undefined})
}
setTemplateType(value) 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[] ] as ProColumns[]
}, [isDeleting, currentTemplate, search, templateField, templateType]) }, [isDeleting, currentTemplate, search, templateField, templateType])

Loading…
Cancel
Save