维护通知中心多语言
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Form, Input, Switch, Tabs, message, Button } from 'antd';
|
||||
import { useIntl } from 'umi';
|
||||
import WangEditor from '@/components/WangEidtor/WangEidtor';
|
||||
import { TopStatus, EnglishSetting } from '@/dicts/noticeManageDict';
|
||||
import { addNotice, updateNotice, getNoticeDetail } from '@/servers/api/notice';
|
||||
@ -14,6 +15,7 @@ interface NoticeManageFormProps {
|
||||
}
|
||||
|
||||
const NoticeManageForm: React.FC<NoticeManageFormProps> = ({ id, isEdit, onSuccess }) => {
|
||||
const intl = useIntl();
|
||||
const [form] = Form.useForm();
|
||||
const [activeTabKey, setActiveTabKey] = useState<string>('zh');
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
@ -78,6 +80,7 @@ const NoticeManageForm: React.FC<NoticeManageFormProps> = ({ id, isEdit, onSucce
|
||||
}
|
||||
}
|
||||
|
||||
message.error(intl.formatMessage({ id: 'notice.message.validate.fail' }));
|
||||
throw error;
|
||||
}
|
||||
|
||||
@ -102,10 +105,14 @@ const NoticeManageForm: React.FC<NoticeManageFormProps> = ({ id, isEdit, onSucce
|
||||
}
|
||||
|
||||
if (response && response.success) {
|
||||
message.success(isEdit ? '更新成功' : '添加成功');
|
||||
message.success(intl.formatMessage({
|
||||
id: isEdit ? 'notice.message.update.success' : 'notice.message.add.success'
|
||||
}));
|
||||
onSuccess(); // 回调父组件
|
||||
} else {
|
||||
message.error(response.message || (isEdit ? '更新失败' : '添加失败'));
|
||||
message.error(response.message || intl.formatMessage({
|
||||
id: isEdit ? 'notice.message.update.fail' : 'notice.message.add.fail'
|
||||
}));
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('表单验证或提交失败:', error);
|
||||
@ -118,63 +125,69 @@ const NoticeManageForm: React.FC<NoticeManageFormProps> = ({ id, isEdit, onSucce
|
||||
return (
|
||||
<div>
|
||||
<Form form={form} layout="vertical" name="noticeForm" preserve={false}>
|
||||
<Form.Item name="isTop" label="是否置顶" valuePropName="checked">
|
||||
<Form.Item name="isTop" label={intl.formatMessage({ id: 'notice.field.isTop' })} valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="settingEn" label="是否设置英文内容" valuePropName="checked">
|
||||
<Form.Item name="settingEn" label={intl.formatMessage({ id: 'notice.field.settingEn' })} valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
|
||||
<Tabs activeKey={activeTabKey} onChange={handleTabChange}>
|
||||
<TabPane tab="中文版" key="zh" forceRender={true}>
|
||||
<TabPane tab={intl.formatMessage({ id: 'notice.tab.chinese' })} key="zh" forceRender={true}>
|
||||
<Form.Item
|
||||
name="titleZh"
|
||||
label="标题(中文)"
|
||||
rules={[{ required: true, message: '请输入中文标题' }]}
|
||||
label={intl.formatMessage({ id: 'notice.field.title' })}
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'notice.form.title.required' }) }]}
|
||||
>
|
||||
<Input placeholder="请输入中文标题" />
|
||||
<Input placeholder={intl.formatMessage({ id: 'notice.form.title.placeholder' })} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="contentZh"
|
||||
label="内容(中文)"
|
||||
rules={[{ required: true, message: '请输入中文内容' }]}
|
||||
label={intl.formatMessage({ id: 'notice.field.content' })}
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'notice.form.content.required' }) }]}
|
||||
>
|
||||
<WangEditor language="zh-CN" height="300px" placeholder="请输入通知内容..." />
|
||||
<WangEditor
|
||||
language="zh-CN"
|
||||
height="300px"
|
||||
placeholder={intl.formatMessage({ id: 'notice.form.content.placeholder' })}
|
||||
/>
|
||||
</Form.Item>
|
||||
</TabPane>
|
||||
<TabPane tab="英文版" key="en" forceRender={true}>
|
||||
<TabPane tab={intl.formatMessage({ id: 'notice.tab.english' })} key="en" forceRender={true}>
|
||||
<Form.Item
|
||||
name="titleEn"
|
||||
label="标题(英文)"
|
||||
rules={[{ required: form.getFieldValue('settingEn'), message: 'Please enter title in English' }]}
|
||||
label={intl.formatMessage({ id: 'notice.field.titleEn' })}
|
||||
rules={[{ required: form.getFieldValue('settingEn'), message: intl.formatMessage({ id: 'notice.form.titleEn.required' }) }]}
|
||||
>
|
||||
<Input placeholder="Please enter title in English" />
|
||||
<Input placeholder={intl.formatMessage({ id: 'notice.form.titleEn.placeholder' })} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="contentEn"
|
||||
label="内容(英文)"
|
||||
rules={[{ required: form.getFieldValue('settingEn'), message: 'Please enter content in English' }]}
|
||||
label={intl.formatMessage({ id: 'notice.field.contentEn' })}
|
||||
rules={[{ required: form.getFieldValue('settingEn'), message: intl.formatMessage({ id: 'notice.form.contentEn.required' }) }]}
|
||||
>
|
||||
<WangEditor
|
||||
language="en"
|
||||
height="300px"
|
||||
placeholder="Please enter notice content..."
|
||||
placeholder={intl.formatMessage({ id: 'notice.form.contentEn.placeholder' })}
|
||||
/>
|
||||
</Form.Item>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
</Form>
|
||||
<div className={styles.formActions}>
|
||||
<Button onClick={() => onSuccess()}>取消</Button>
|
||||
<Button onClick={() => onSuccess()}>
|
||||
{intl.formatMessage({ id: 'notice.button.cancel' })}
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
loading={loading}
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
提交
|
||||
{intl.formatMessage({ id: 'notice.button.submit' })}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user