中英文切换 初始化
This commit is contained in:
@@ -32,6 +32,7 @@ import { setUserInfo } from '../store/userSlice';
|
||||
import { getUserProfile, updateUserProfile, updateUserPwd, uploadAvatar } from '../api/user';
|
||||
import envConfig from '../../env';
|
||||
import utils from '../lib/utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { TabPane } = Tabs;
|
||||
const { Title } = Typography;
|
||||
@@ -53,7 +54,7 @@ const Profile: React.FC = () => {
|
||||
form.setFieldsValue(res.data);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取个人信息失败');
|
||||
message.error(t('profile.getProfileFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -71,12 +72,12 @@ const Profile: React.FC = () => {
|
||||
};
|
||||
const res: any = await updateUserProfile(updateData);
|
||||
if (res.code === 200) {
|
||||
message.success('修改成功');
|
||||
message.success(t('profile.modifySuccess'));
|
||||
const newUserInfo = { ...userInfo, ...values };
|
||||
dispatch(setUserInfo(newUserInfo));
|
||||
fetchProfile();
|
||||
} else {
|
||||
message.error(res.msg || '修改失败');
|
||||
message.error(res.msg || t('profile.modifyFailed'));
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('请求失败');
|
||||
@@ -87,17 +88,17 @@ const Profile: React.FC = () => {
|
||||
|
||||
const handleUpdatePwd = async (values: any) => {
|
||||
if (values.newPassword !== values.confirmPassword) {
|
||||
message.error('两次输入的密码不一致');
|
||||
message.error(t('profile.passwordMismatch'));
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const res: any = await updateUserPwd(values.oldPassword, values.newPassword);
|
||||
if (res.code === 200) {
|
||||
message.success('密码修改成功');
|
||||
message.success(t('profile.passwordChanged'));
|
||||
pwdForm.resetFields();
|
||||
} else {
|
||||
message.error(res.msg || '修改失败');
|
||||
message.error(res.msg || t('profile.modifyFailed'));
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('请求失败');
|
||||
@@ -114,15 +115,15 @@ const Profile: React.FC = () => {
|
||||
try {
|
||||
const res: any = await uploadAvatar(formData);
|
||||
if (res.code === 200) {
|
||||
message.success('头像上传成功');
|
||||
message.success(t('profile.avatarUploadSuccess'));
|
||||
const newUserInfo = { ...userInfo, avatar: res.imgUrl };
|
||||
dispatch(setUserInfo(newUserInfo));
|
||||
fetchProfile();
|
||||
} else {
|
||||
message.error(res.msg || '上传失败');
|
||||
message.error(res.msg || t('profile.avatarUploadFailed'));
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('上传失败');
|
||||
message.error(t('profile.avatarUploadFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -193,20 +194,20 @@ const Profile: React.FC = () => {
|
||||
<div style={{ display: 'flex', alignItems: 'center', fontSize: 14 }}>
|
||||
<PhoneOutlined style={{ marginRight: 12, color: '#165DFF', fontSize: 16 }} />
|
||||
<span style={{ color: '#666' }}>手机号码:</span>
|
||||
<strong style={{ marginLeft: 4, color: '#333' }}>{profileData?.phonenumber || '未设置'}</strong>
|
||||
<strong style={{ marginLeft: 4, color: '#333' }}>{profileData?.phonenumber || t('profile.notSet')}</strong>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'center', fontSize: 14 }}>
|
||||
<MailOutlined style={{ marginRight: 12, color: '#165DFF', fontSize: 16 }} />
|
||||
<span style={{ color: '#666' }}>用户邮箱:</span>
|
||||
<strong style={{ marginLeft: 4, color: '#333' }}>{profileData?.email || '未设置'}</strong>
|
||||
<strong style={{ marginLeft: 4, color: '#333' }}>{profileData?.email || t('profile.notSet')}</strong>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'center', fontSize: 14 }}>
|
||||
<SafetyOutlined style={{ marginRight: 12, color: '#165DFF', fontSize: 16 }} />
|
||||
<span style={{ color: '#666' }}>所属角色:</span>
|
||||
<strong style={{ marginLeft: 4, color: '#333' }}>
|
||||
{profileData?.roles?.map((r: any) => r.roleName).join(', ') || '未设置'}
|
||||
{profileData?.roles?.map((r: any) => r.roleName).join(', ') || t('profile.notSet')}
|
||||
</strong>
|
||||
</div>
|
||||
</Space>
|
||||
@@ -243,7 +244,7 @@ const Profile: React.FC = () => {
|
||||
size="large"
|
||||
>
|
||||
<Form.Item
|
||||
label="用户名称"
|
||||
label={t('profile.username')}
|
||||
name="userName"
|
||||
>
|
||||
<Input
|
||||
@@ -254,19 +255,19 @@ const Profile: React.FC = () => {
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="用户昵称"
|
||||
label={t('users.nicknameLabel')}
|
||||
name="nickName"
|
||||
rules={[{ required: true, message: '请输入用户昵称' }]}
|
||||
rules={[{ required: true, message: t('profile.nicknamePlaceholder') }]}
|
||||
>
|
||||
<Input
|
||||
prefix={<UserOutlined />}
|
||||
placeholder="请输入用户昵称"
|
||||
placeholder={t('profile.nicknamePlaceholder')}
|
||||
style={{ borderRadius: 6 }}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="性别"
|
||||
label={t('users.genderLabel')}
|
||||
name="sex"
|
||||
>
|
||||
<Radio.Group>
|
||||
@@ -276,19 +277,19 @@ const Profile: React.FC = () => {
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="手机号码"
|
||||
label={t('users.phoneLabel')}
|
||||
name="phonenumber"
|
||||
rules={[{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码' }]}
|
||||
>
|
||||
<Input
|
||||
prefix={<PhoneOutlined />}
|
||||
placeholder="请输入手机号码"
|
||||
placeholder={t('profile.phonePlaceholder')}
|
||||
style={{ borderRadius: 6 }}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="邮箱"
|
||||
label={t('users.email')}
|
||||
name="email"
|
||||
rules={[{ type: 'email', message: '请输入正确的邮箱格式' }]}
|
||||
>
|
||||
@@ -300,7 +301,7 @@ const Profile: React.FC = () => {
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="备注"
|
||||
label={t('roles.remark')}
|
||||
name="remark"
|
||||
>
|
||||
<Input.TextArea
|
||||
@@ -339,7 +340,7 @@ const Profile: React.FC = () => {
|
||||
size="large"
|
||||
>
|
||||
<Form.Item
|
||||
label="旧密码"
|
||||
label={t('profile.oldPassword')}
|
||||
name="oldPassword"
|
||||
rules={[{ required: true, message: '请输入旧密码' }]}
|
||||
>
|
||||
@@ -351,7 +352,7 @@ const Profile: React.FC = () => {
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="新密码"
|
||||
label={t('profile.newPassword')}
|
||||
name="newPassword"
|
||||
rules={[
|
||||
{ required: true, message: '请输入新密码' },
|
||||
@@ -366,7 +367,7 @@ const Profile: React.FC = () => {
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="确认密码"
|
||||
label={t('profile.confirmPassword')}
|
||||
name="confirmPassword"
|
||||
rules={[{ required: true, message: '请确认新密码' }]}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user