86133 | aaa3f5d | 2025-04-20 21:33:29 +0800 | [diff] [blame] | 1 | import React from 'react'; |
| 2 | import { Form, message, Row } from 'antd'; |
| 3 | import { FormattedMessage, useIntl } from '@umijs/max'; |
| 4 | import { ProForm, ProFormRadio, ProFormText } from '@ant-design/pro-components'; |
| 5 | import { updateUserProfile } from '@/services/system/user'; |
| 6 | |
| 7 | |
| 8 | export type BaseInfoProps = { |
| 9 | values: Partial<API.CurrentUser> | undefined; |
| 10 | }; |
| 11 | |
| 12 | const BaseInfo: React.FC<BaseInfoProps> = (props) => { |
| 13 | const [form] = Form.useForm(); |
| 14 | const intl = useIntl(); |
| 15 | |
| 16 | const handleFinish = async (values: Record<string, any>) => { |
| 17 | const data = { ...props.values, ...values } as API.CurrentUser; |
| 18 | const resp = await updateUserProfile(data); |
| 19 | if (resp.code === 200) { |
| 20 | message.success('修改成功'); |
| 21 | } else { |
| 22 | message.warning(resp.msg); |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | return ( |
| 27 | <> |
| 28 | <ProForm form={form} onFinish={handleFinish} initialValues={props.values}> |
| 29 | <Row> |
| 30 | <ProFormText |
| 31 | name="nickName" |
| 32 | label={intl.formatMessage({ |
| 33 | id: 'system.user.nick_name', |
| 34 | defaultMessage: '用户昵称', |
| 35 | })} |
| 36 | width="xl" |
| 37 | placeholder="请输入用户昵称" |
| 38 | rules={[ |
| 39 | { |
| 40 | required: true, |
| 41 | message: ( |
| 42 | <FormattedMessage id="请输入用户昵称!" defaultMessage="请输入用户昵称!" /> |
| 43 | ), |
| 44 | }, |
| 45 | ]} |
| 46 | /> |
| 47 | </Row> |
| 48 | <Row> |
| 49 | <ProFormText |
| 50 | name="phonenumber" |
| 51 | label={intl.formatMessage({ |
| 52 | id: 'system.user.phonenumber', |
| 53 | defaultMessage: '手机号码', |
| 54 | })} |
| 55 | width="xl" |
| 56 | placeholder="请输入手机号码" |
| 57 | rules={[ |
| 58 | { |
| 59 | required: false, |
| 60 | message: ( |
| 61 | <FormattedMessage id="请输入手机号码!" defaultMessage="请输入手机号码!" /> |
| 62 | ), |
| 63 | }, |
| 64 | ]} |
| 65 | /> |
| 66 | </Row> |
| 67 | <Row> |
| 68 | <ProFormText |
| 69 | name="email" |
| 70 | label={intl.formatMessage({ |
| 71 | id: 'system.user.email', |
| 72 | defaultMessage: '邮箱', |
| 73 | })} |
| 74 | width="xl" |
| 75 | placeholder="请输入邮箱" |
| 76 | rules={[ |
| 77 | { |
| 78 | type: 'email', |
| 79 | message: '无效的邮箱地址!', |
| 80 | }, |
| 81 | { |
| 82 | required: false, |
| 83 | message: <FormattedMessage id="请输入邮箱!" defaultMessage="请输入邮箱!" />, |
| 84 | }, |
| 85 | ]} |
| 86 | /> |
| 87 | </Row> |
| 88 | <Row> |
| 89 | <ProFormRadio.Group |
| 90 | options={[ |
| 91 | { |
| 92 | label: '男', |
| 93 | value: '0', |
| 94 | }, |
| 95 | { |
| 96 | label: '女', |
| 97 | value: '1', |
| 98 | }, |
| 99 | ]} |
| 100 | name="sex" |
| 101 | label={intl.formatMessage({ |
| 102 | id: 'system.user.sex', |
| 103 | defaultMessage: 'sex', |
| 104 | })} |
| 105 | width="xl" |
| 106 | rules={[ |
| 107 | { |
| 108 | required: false, |
| 109 | message: <FormattedMessage id="请输入性别!" defaultMessage="请输入性别!" />, |
| 110 | }, |
| 111 | ]} |
| 112 | /> |
| 113 | </Row> |
| 114 | </ProForm> |
| 115 | </> |
| 116 | ); |
| 117 | }; |
| 118 | |
| 119 | export default BaseInfo; |