维护所有模块的多语言功能,对接友情分类接口和友情链接接口
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Form, Input, Switch, Tabs, message, Button, Select } from 'antd';
|
||||
import { useIntl } from 'umi';
|
||||
import WangEditor from '@/components/WangEidtor/WangEidtor';
|
||||
import { TopStatus, EnglishSetting, categoryOptions } from '@/dicts/helpManageDict';
|
||||
import { addHelp, updateHelp, getHelpDetail } from '@/servers/api/help';
|
||||
@ -17,6 +18,7 @@ const HelpManageForm: React.FC<HelpManageFormProps> = ({ id, isEdit, onSuccess }
|
||||
const [form] = Form.useForm();
|
||||
const [activeTabKey, setActiveTabKey] = useState<string>('zh');
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const intl = useIntl();
|
||||
|
||||
// 获取详情数据
|
||||
useEffect(() => {
|
||||
@ -37,11 +39,11 @@ const HelpManageForm: React.FC<HelpManageFormProps> = ({ id, isEdit, onSuccess }
|
||||
answerContentEn: detail.answerContentNe,
|
||||
});
|
||||
} else {
|
||||
message.error(response.message || '获取详情失败');
|
||||
message.error(response.message || intl.formatMessage({ id: 'helpManage.fetchDetailFailed' }));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取帮助详情失败:', error);
|
||||
message.error('获取详情失败');
|
||||
message.error(intl.formatMessage({ id: 'helpManage.fetchDetailFailed' }));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@ -50,7 +52,7 @@ const HelpManageForm: React.FC<HelpManageFormProps> = ({ id, isEdit, onSuccess }
|
||||
if (isEdit && id) {
|
||||
fetchHelpDetail(id);
|
||||
}
|
||||
}, [isEdit, id, form]);
|
||||
}, [isEdit, id, form, intl]);
|
||||
|
||||
// 处理Tab切换
|
||||
const handleTabChange = (key: string) => {
|
||||
@ -107,10 +109,14 @@ const HelpManageForm: React.FC<HelpManageFormProps> = ({ id, isEdit, onSuccess }
|
||||
}
|
||||
|
||||
if (response && response.success) {
|
||||
message.success(isEdit ? '更新成功' : '添加成功');
|
||||
message.success(isEdit
|
||||
? intl.formatMessage({ id: 'helpManage.updateSuccess' })
|
||||
: intl.formatMessage({ id: 'helpManage.addSuccess' }));
|
||||
onSuccess(); // 回调父组件
|
||||
} else {
|
||||
message.error(response.message || (isEdit ? '更新失败' : '添加失败'));
|
||||
message.error(response.message || (isEdit
|
||||
? intl.formatMessage({ id: 'helpManage.updateFailed' })
|
||||
: intl.formatMessage({ id: 'helpManage.addFailed' })));
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('表单验证或提交失败:', error);
|
||||
@ -123,92 +129,102 @@ const HelpManageForm: React.FC<HelpManageFormProps> = ({ id, isEdit, onSuccess }
|
||||
return (
|
||||
<div>
|
||||
<Form form={form} layout="vertical" name="helpForm" preserve={false}>
|
||||
<Form.Item name="isTop" label="是否置顶" valuePropName="checked">
|
||||
<Form.Item name="isTop" label={intl.formatMessage({ id: 'helpManage.form.isTop' })} valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="type"
|
||||
label="问题类型"
|
||||
rules={[{ required: true, message: '请选择问题类型' }]}
|
||||
label={intl.formatMessage({ id: 'helpManage.form.category' })}
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'helpManage.form.categoryRequired' }) }]}
|
||||
>
|
||||
<Select placeholder="请选择问题类型">
|
||||
<Select placeholder={intl.formatMessage({ id: 'helpManage.form.categoryPlaceholder' })}>
|
||||
{categoryOptions.map(option => (
|
||||
<Option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
{typeof option.label === 'function' ? option.label() : option.label}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Tabs activeKey={activeTabKey} onChange={handleTabChange}>
|
||||
<TabPane tab="中文版" key="zh" forceRender={true}>
|
||||
<TabPane tab={intl.formatMessage({ id: 'helpManage.form.chineseTab' })} key="zh" forceRender={true}>
|
||||
<Form.Item
|
||||
name="titleZh"
|
||||
label="标题(中文)"
|
||||
rules={[{ required: true, message: '请输入中文标题' }]}
|
||||
label={intl.formatMessage({ id: 'helpManage.form.titleZh' })}
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'helpManage.form.titleZhRequired' }) }]}
|
||||
>
|
||||
<Input placeholder="请输入中文标题" />
|
||||
<Input placeholder={intl.formatMessage({ id: 'helpManage.form.titleZhPlaceholder' })} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="contentZh"
|
||||
label="内容(中文)"
|
||||
rules={[{ required: true, message: '请输入中文内容' }]}
|
||||
label={intl.formatMessage({ id: 'helpManage.form.contentZh' })}
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'helpManage.form.contentZhRequired' }) }]}
|
||||
>
|
||||
<WangEditor language="zh-CN" height="250px" placeholder="请输入帮助内容..." />
|
||||
<WangEditor
|
||||
language="zh-CN"
|
||||
height="250px"
|
||||
placeholder={intl.formatMessage({ id: 'helpManage.form.contentZhPlaceholder' })}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="answerContentZh"
|
||||
label="回答内容(中文)"
|
||||
label={intl.formatMessage({ id: 'helpManage.form.answerContentZh' })}
|
||||
>
|
||||
<WangEditor language="zh-CN" height="200px" placeholder="请输入回答内容..." />
|
||||
<WangEditor
|
||||
language="zh-CN"
|
||||
height="200px"
|
||||
placeholder={intl.formatMessage({ id: 'helpManage.form.answerContentZhPlaceholder' })}
|
||||
/>
|
||||
</Form.Item>
|
||||
</TabPane>
|
||||
<TabPane tab="英文版" key="en" forceRender={true}>
|
||||
<TabPane tab={intl.formatMessage({ id: 'helpManage.form.englishTab' })} key="en" forceRender={true}>
|
||||
<Form.Item
|
||||
name="titleEn"
|
||||
label="标题(英文)"
|
||||
rules={[{ required: true, message: 'Please enter title in English' }]}
|
||||
label={intl.formatMessage({ id: 'helpManage.form.titleEn' })}
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'helpManage.form.titleEnRequired' }) }]}
|
||||
>
|
||||
<Input placeholder="Please enter title in English" />
|
||||
<Input placeholder={intl.formatMessage({ id: 'helpManage.form.titleEnPlaceholder' })} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="contentEn"
|
||||
label="内容(英文)"
|
||||
rules={[{ required: true, message: 'Please enter content in English' }]}
|
||||
label={intl.formatMessage({ id: 'helpManage.form.contentEn' })}
|
||||
rules={[{ required: true, message: intl.formatMessage({ id: 'helpManage.form.contentEnRequired' }) }]}
|
||||
>
|
||||
<WangEditor
|
||||
language="en"
|
||||
height="250px"
|
||||
placeholder="Please enter help content..."
|
||||
placeholder={intl.formatMessage({ id: 'helpManage.form.contentEnPlaceholder' })}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="answerContentEn"
|
||||
label="回答内容(英文)"
|
||||
label={intl.formatMessage({ id: 'helpManage.form.answerContentEn' })}
|
||||
>
|
||||
<WangEditor
|
||||
language="en"
|
||||
height="200px"
|
||||
placeholder="Please enter answer content..."
|
||||
placeholder={intl.formatMessage({ id: 'helpManage.form.answerContentEnPlaceholder' })}
|
||||
/>
|
||||
</Form.Item>
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
</Form>
|
||||
<div style={{ textAlign: 'right', marginTop: '20px' }}>
|
||||
<Button onClick={() => onSuccess()}>取消</Button>
|
||||
<Button onClick={() => onSuccess()}>
|
||||
{intl.formatMessage({ id: 'helpManage.cancel' })}
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
loading={loading}
|
||||
onClick={handleSubmit}
|
||||
style={{ marginLeft: '8px' }}
|
||||
>
|
||||
提交
|
||||
{intl.formatMessage({ id: 'helpManage.submit' })}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user