forgeplus-react/src/forge/users/Material/Base.jsx

134 lines
4.4 KiB
React
Raw Normal View History

2021-06-04 09:43:38 +08:00
import React , { forwardRef, useEffect } from 'react';
import { Form , Checkbox , Input, Radio , Button , Cascader } from 'antd';
import { AlignCenter } from '../../Component/layout';
import './Index.scss';
import { locData } from '../../Utils/locData';
import Axios from 'axios';
const { TextArea } = Input;
export default Form.create()(
forwardRef((props)=>{
const { getFieldDecorator, validateFields , setFieldsValue } = props && props.form;
2021-09-01 11:24:37 +08:00
// const { username } = props && props.match && props.match.params;
const { resetUserInfo , current_user } = props;
console.log(props);
2021-06-08 14:56:00 +08:00
2021-06-04 09:43:38 +08:00
useEffect(()=>{
2021-06-08 14:56:00 +08:00
if(current_user && current_user.login){
2021-06-04 09:43:38 +08:00
setFieldsValue({
2021-06-08 14:56:00 +08:00
...current_user,
location:current_user.province && [current_user.province,current_user.city]
2021-06-04 09:43:38 +08:00
})
}
2021-06-08 14:56:00 +08:00
},[current_user])
2021-06-04 09:43:38 +08:00
function submit() {
validateFields((error,values)=>{
if(!error){
submitFunc(values);
}
})
}
function submitFunc(values) {
2021-09-01 11:24:37 +08:00
const url = `/users/${current_user && current_user.login}.json`;
2021-06-04 09:43:38 +08:00
const params={
user: {
2021-09-02 14:13:16 +08:00
nickname: values.nickname,
2021-06-04 09:43:38 +08:00
user_extension_attributes: {
province: values.location && values.location[0],
city: values.location && values.location[1],
...values
}
}
}
Axios.put(url,params).then(result=>{
if(result && result.data){
2021-06-04 10:55:05 +08:00
props.showNotification("资料修改成功!")
2021-09-01 11:24:37 +08:00
resetUserInfo && resetUserInfo();
2021-06-04 09:43:38 +08:00
}
}).catch(error=>{})
}
return(
<Form layout={'inline'} className="formBase">
<Form.Item label="邮箱">
{getFieldDecorator("email",{
rules:[{required:true,message:"请输入邮箱账号"}]
})(
2021-06-07 11:13:38 +08:00
<Input placeholder="请输入您的邮箱账号" disabled style={{width:"400px"}}/>
2021-06-04 09:43:38 +08:00
)}
</Form.Item>
<Form.Item label="">
{getFieldDecorator("show_email",{
rules:[],
valuePropName:"checked"
})(
<Checkbox>在个人主页展示</Checkbox>
)}
</Form.Item>
<Form.Item label="姓名">
2021-09-02 14:13:16 +08:00
{getFieldDecorator("nickname",{
2021-06-04 09:43:38 +08:00
rules:[{required:true,message:"请输入姓名"}]
})(
2021-08-30 10:31:51 +08:00
<Input placeholder="请输入您的姓名" maxLength={20} style={{width:"400px"}}/>
2021-06-04 09:43:38 +08:00
)}
</Form.Item>
<div>
<Form.Item label="性别">
{getFieldDecorator("gender",{
rules:[{required:true,message:"请选择性别"}]
})(
<Radio.Group>
<Radio value={1}></Radio>
<Radio value={0}></Radio>
</Radio.Group>
)}
</Form.Item>
</div>
<Form.Item label="单位名称">
{getFieldDecorator("custom_department",{
rules:[{required:true,message:"请输入单位名称"}]
})(
2021-08-30 10:31:51 +08:00
<Input placeholder="请输入单位名称" maxLength={30} style={{width:"400px"}}/>
2021-06-04 09:43:38 +08:00
)}
</Form.Item>
<Form.Item label="">
{getFieldDecorator("show_department",{
rules:[],
valuePropName:"checked"
})(
<Checkbox>在个人主页展示</Checkbox>
)}
</Form.Item>
<Form.Item label="地区">
{getFieldDecorator("location",{
rules:[]
})(
<Cascader placeholder="请选择省份城市" options={locData} style={{width:"400px"}}></Cascader>
)}
</Form.Item>
<Form.Item label="">
{getFieldDecorator("show_location",{
rules:[],
valuePropName:"checked"
})(
<Checkbox>在个人主页展示</Checkbox>
)}
</Form.Item>
<Form.Item label="简介">
{getFieldDecorator("description",{
rules:[]
})(
2021-08-30 10:31:51 +08:00
<TextArea placeholder="请输入您的自我简介" rows={4} maxLength={140} style={{width:"600px"}}/>
2021-06-04 09:43:38 +08:00
)}
</Form.Item>
<AlignCenter>
<span className="ant-form-item-label"></span>
<Button type={"primary"} onClick={submit}>提交</Button>
2021-09-01 11:24:37 +08:00
{/* <Button type={"default"} onClick={()=>props.history.push(`/${current_user && current_user.login}`)} className="ml20">取消</Button> */}
2021-06-04 09:43:38 +08:00
</AlignCenter>
</Form>
)
})
)