Compare commits
2 Commits
1c7f35b40f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| fc778e9de6 | |||
| 0ae33997ee |
@@ -3,6 +3,7 @@ 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 {View, Text} from '@tarojs/components'
|
||||
import {getUserInfo} from "@/api/layout";
|
||||
import {TenantId} from "@/config/app";
|
||||
import { TextArea } from '@nutui/nutui-react-taro'
|
||||
@@ -34,7 +35,7 @@ interface InputEvent {
|
||||
}
|
||||
function Profile() {
|
||||
const formId = Number(router?.params.id)
|
||||
const {user, updateUser} = useUser()
|
||||
const {user, updateUser, loading} = useUser()
|
||||
|
||||
const [sex, setSex] = useState<DictData[]>()
|
||||
const [FormData, setFormData] = useState<User>(
|
||||
@@ -49,16 +50,27 @@ function Profile() {
|
||||
comments: undefined
|
||||
}
|
||||
)
|
||||
const [pageLoading, setPageLoading] = useState(true)
|
||||
|
||||
const reload = () => {
|
||||
// 获取数据字典
|
||||
pageDictData({limit: 200}).then(res => {
|
||||
setSex(res?.list.filter((item) => item.dictCode === 'sex'))
|
||||
}).catch(err => {
|
||||
console.error('获取数据字典失败:', err)
|
||||
})
|
||||
// 获取用户信息
|
||||
getUserInfo().then((data) => {
|
||||
// 更新表单数据
|
||||
setFormData(data);
|
||||
}).catch(err => {
|
||||
console.error('获取用户信息失败:', err)
|
||||
Taro.showToast({
|
||||
title: '获取用户信息失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}).finally(() => {
|
||||
setPageLoading(false)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -140,9 +152,12 @@ function Profile() {
|
||||
});
|
||||
}
|
||||
|
||||
// 等待 useUser 初始化完成后再加载数据
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
reload()
|
||||
}, []);
|
||||
}
|
||||
}, [loading]);
|
||||
|
||||
// 监听 useUser hook 中的用户信息变化,同步更新表单数据
|
||||
useEffect(() => {
|
||||
@@ -151,6 +166,15 @@ function Profile() {
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
// 加载中显示
|
||||
if (loading || pageLoading) {
|
||||
return (
|
||||
<View className={'flex justify-center items-center h-screen'}>
|
||||
<Text>加载中...</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={'p-4'}>
|
||||
@@ -223,14 +247,14 @@ function Profile() {
|
||||
label="备注信息"
|
||||
name="comments"
|
||||
initialValue={FormData.comments}
|
||||
rules={[{message: '备注信息'}]}
|
||||
rules={[{message: '请输入备注信息'}]}
|
||||
>
|
||||
<TextArea
|
||||
name="comments"
|
||||
placeholder={'个性签名'}
|
||||
value={FormData?.comments}
|
||||
onChange={(value) => setFormData({...FormData, comments: value})}
|
||||
/>
|
||||
<Input placeholder={'个性签名'} />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</ConfigProvider>
|
||||
|
||||
Reference in New Issue
Block a user