首次提交
This commit is contained in:
3
src/user/profile/profile.config.ts
Normal file
3
src/user/profile/profile.config.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '个人资料'
|
||||
})
|
||||
6
src/user/profile/profile.scss
Normal file
6
src/user/profile/profile.scss
Normal file
@@ -0,0 +1,6 @@
|
||||
.nut-form-item-label-left {
|
||||
padding-left: 8px !important;
|
||||
}
|
||||
.nut-form-item-label-required{
|
||||
top: 0 !important;
|
||||
}
|
||||
276
src/user/profile/profile.tsx
Normal file
276
src/user/profile/profile.tsx
Normal file
@@ -0,0 +1,276 @@
|
||||
import {Cell, Avatar} from '@nutui/nutui-react-taro';
|
||||
import {ArrowRight} from '@nutui/icons-react-taro'
|
||||
import {useEffect, useState} from "react";
|
||||
import {ConfigProvider} from '@nutui/nutui-react-taro'
|
||||
import Taro, {getCurrentInstance} from '@tarojs/taro'
|
||||
import {getUserInfo, updateUserInfo} from "@/api/layout";
|
||||
import {TenantId} from "@/utils/config";
|
||||
import './profile.scss'
|
||||
|
||||
const {router} = getCurrentInstance()
|
||||
import {
|
||||
Form,
|
||||
Button,
|
||||
Input,
|
||||
Radio,
|
||||
// SideNavBar,
|
||||
// SideNavBarItem,
|
||||
// SubSideNavBar,
|
||||
// Cascader
|
||||
} from '@nutui/nutui-react-taro'
|
||||
import {DictData} from "@/api/system/dict-data/model";
|
||||
import {pageDictData} from "@/api/system/dict-data";
|
||||
import {User} from "@/api/system/user/model";
|
||||
function Profile() {
|
||||
const formId = Number(router?.params.id)
|
||||
|
||||
const [form] = Form.useForm()
|
||||
const [type, setType] = useState<number>(0)
|
||||
const [sex, setSex] = useState<DictData[]>()
|
||||
const [FormData, setFormData] = useState<User>(
|
||||
{
|
||||
userId: undefined,
|
||||
nickname: undefined,
|
||||
avatar: undefined,
|
||||
sex: undefined,
|
||||
phone: undefined,
|
||||
address: undefined,
|
||||
comments: undefined
|
||||
}
|
||||
)
|
||||
const [user, setUser] = useState<any>({
|
||||
nickname: '',
|
||||
avatar: undefined,
|
||||
username: '',
|
||||
mobile: ''
|
||||
})
|
||||
const reload = () => {
|
||||
// 获取数据字典
|
||||
pageDictData({limit: 200}).then(res => {
|
||||
setSex(res?.list.filter((item) => item.dictCode === 'sex'))
|
||||
// setPresent(res?.list.filter((item) => item.dictCode === 'present'))
|
||||
})
|
||||
// 获取用户信息
|
||||
getUserInfo().then((data) => {
|
||||
setUser(data)
|
||||
setFormData(data)
|
||||
})
|
||||
// pageDictData({limit: 200}).then(res => {
|
||||
// setSex(res?.list.filter((item) => item.dictCode === 'sex'))
|
||||
// setPresent(res?.list.filter((item) => item.dictCode === 'present'))
|
||||
// // setClassList([res?.list.filter((item) => item.dictCode === 'Class')])
|
||||
// setGradeList(res?.list.filter((item) => {
|
||||
// if (item.dictCode === 'Grade') {
|
||||
// item.value = item.dictDataCode;
|
||||
// item.text = item.dictDataName;
|
||||
// return item
|
||||
// }
|
||||
// }))
|
||||
// })
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitSucceed = (values: any) => {
|
||||
console.log(values, 'values')
|
||||
console.log(formId, 'formId>>')
|
||||
if(values.type === 1 && values.name == ''){
|
||||
Taro.showToast({
|
||||
title: '请填写单位名称',
|
||||
icon: 'error'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
updateUserInfo(values).then(() => {
|
||||
Taro.showToast({title: `保存成功`, icon: 'success'})
|
||||
return Taro.navigateBack()
|
||||
}).catch(() => {
|
||||
Taro.showToast({
|
||||
title: '保存失败',
|
||||
icon: 'error'
|
||||
});
|
||||
})
|
||||
}
|
||||
const submitFailed = (error: any) => {
|
||||
console.log(error, 'err...')
|
||||
// Taro.showToast({ title: error[0].message, icon: 'error' })
|
||||
}
|
||||
|
||||
const changeType = (type: any) => {
|
||||
console.log(type, 'type>>>>')
|
||||
setType(type)
|
||||
}
|
||||
|
||||
const uploadAvatar = ({detail}) => {
|
||||
setUser({
|
||||
...user,
|
||||
avatar: `${detail.avatarUrl}`,
|
||||
})
|
||||
Taro.uploadFile({
|
||||
url: 'https://server.gxwebsoft.com/api/oss/upload',
|
||||
filePath: detail.avatarUrl,
|
||||
name: 'file',
|
||||
header: {
|
||||
'content-type': 'application/json',
|
||||
TenantId
|
||||
},
|
||||
success: (res) => {
|
||||
const data = JSON.parse(res.data);
|
||||
if (data.code === 0) {
|
||||
updateUserInfo({
|
||||
userId: user.userId,
|
||||
avatar: `${data.data.thumbnail}`
|
||||
}).then(() => {
|
||||
Taro.showToast({
|
||||
title: '上传成功',
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
reload()
|
||||
}, [form]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={'p-4'}>
|
||||
<Cell.Group>
|
||||
<Cell title={'头像'} align={'center'} extra={
|
||||
<>
|
||||
<Button open-type="chooseAvatar" style={{height: '58px'}} onChooseAvatar={uploadAvatar}>
|
||||
<Avatar src={user.avatar} size="54"/>
|
||||
</Button>
|
||||
<ArrowRight color="#cccccc" className={'ml-1'} size={20}/>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<Cell title={'手机号码'} align={'center'} extra={user.mobile}/>
|
||||
</Cell.Group>
|
||||
<ConfigProvider>
|
||||
<Form
|
||||
divider
|
||||
initialValues={FormData}
|
||||
labelPosition="left"
|
||||
onFinish={(values) => submitSucceed(values)}
|
||||
onFinishFailed={(errors) => submitFailed(errors)}
|
||||
footer={
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
width: '100%'
|
||||
}}
|
||||
>
|
||||
<Button nativeType="submit" block type="info">
|
||||
提交
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Form.Item
|
||||
label="类型"
|
||||
name="type"
|
||||
style={{marginTop: '10px'}}
|
||||
required
|
||||
initialValue={type}
|
||||
>
|
||||
<Radio.Group defaultValue={type} direction="horizontal" onChange={(e) => changeType(e)}>
|
||||
<Radio value={0}>校友</Radio>
|
||||
<Radio value={1}>友好单位</Radio>
|
||||
<Radio value={2}>爱心人士</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={type === 1 ? '单位名称' : '真实姓名'}
|
||||
name="name"
|
||||
required={type === 1}
|
||||
initialValue={FormData.realName}
|
||||
rules={[{message: '请输入姓名或单位名称'}]}
|
||||
>
|
||||
<Input placeholder="请输入姓名或单位名称" type="text"/>
|
||||
</Form.Item>
|
||||
{type !== 1 && (
|
||||
<Form.Item
|
||||
label="性别"
|
||||
name="sex"
|
||||
initialValue={FormData.sex}
|
||||
rules={[
|
||||
{message: '请选择性别'}
|
||||
]}
|
||||
>
|
||||
<Radio.Group defaultValue={FormData.sex} direction="horizontal">
|
||||
{
|
||||
sex?.map((item, index) => (
|
||||
<Radio key={index} value={item.dictDataCode}>
|
||||
{item.dictDataName}
|
||||
</Radio>
|
||||
))
|
||||
}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
)}
|
||||
{/*<Form.Item*/}
|
||||
{/* label="手机号码"*/}
|
||||
{/* name="phone"*/}
|
||||
{/* required*/}
|
||||
{/* initialValue={phone}*/}
|
||||
{/* rules={[{max: 11, message: '请输入手机号码'}]}*/}
|
||||
{/*>*/}
|
||||
{/* <Input placeholder="手机号码" maxLength={11} type="number"/>*/}
|
||||
{/*</Form.Item>*/}
|
||||
<Form.Item
|
||||
label={type === 1 ? '单位地址' : '联系地址'}
|
||||
name="address"
|
||||
initialValue={FormData.address}
|
||||
rules={[{message: '请输入现居住地'}]}
|
||||
>
|
||||
<Input placeholder="请输入现居住地" type="text"/>
|
||||
</Form.Item>
|
||||
{/*<Form.Item*/}
|
||||
{/* label="参加校庆活动"*/}
|
||||
{/* name="present"*/}
|
||||
{/* initialValue={FormData.present}*/}
|
||||
{/* required*/}
|
||||
{/*>*/}
|
||||
{/* <Radio.Group defaultValue={FormData.present} direction="horizontal">*/}
|
||||
{/* {*/}
|
||||
{/* present?.map((item, index) => (*/}
|
||||
{/* <Radio key={index} value={item.dictDataCode}>*/}
|
||||
{/* {item.dictDataName}*/}
|
||||
{/* </Radio>*/}
|
||||
{/* ))*/}
|
||||
{/* }*/}
|
||||
{/* </Radio.Group>*/}
|
||||
{/*</Form.Item>*/}
|
||||
<Form.Item
|
||||
label="备注信息"
|
||||
name="comments"
|
||||
initialValue={FormData.comments}
|
||||
rules={[{message: '备注信息'}]}
|
||||
>
|
||||
<Input placeholder={type == 2 ? '可注明身份,如:家长、小学教师、公务员等' : '未找到班级年级请在标注(初/高xx班)'} />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</ConfigProvider>
|
||||
</div>
|
||||
{/*<Cascader*/}
|
||||
{/* popupProps={{*/}
|
||||
{/* className: 'cascader-popup',*/}
|
||||
{/* }}*/}
|
||||
{/* visible={navBarState.visible}*/}
|
||||
{/* optionKey={{valueKey: 'name', textKey: 'name', childrenKey: 'children'}}*/}
|
||||
{/* title="选择所在班级"*/}
|
||||
{/* options={classList}*/}
|
||||
{/* closeable*/}
|
||||
{/* onChange={change6}*/}
|
||||
{/* onClose={() => {*/}
|
||||
{/* changeNarBar(false)*/}
|
||||
{/* }}*/}
|
||||
{/*/>*/}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Profile
|
||||
Reference in New Issue
Block a user