From 0ae33997eeef9071ec9b0725a8812f68e0f54d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Wed, 29 Apr 2026 16:48:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E4=BC=98=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E5=8A=A0=E8=BD=BD=E5=8F=8A=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增页面加载状态,加载中显示提示 - 等待 useUser 初始化完成后再加载用户数据 - 添加获取数据字典和用户信息的异常处理及错误提示 - 同步更新备注信息表单控件,修正校验提示文案 - 修正备注信息输入框的name属性,确保表单数据绑定正确 --- src/user/profile/profile.tsx | 43 +++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/user/profile/profile.tsx b/src/user/profile/profile.tsx index 8d16019..cc9b799 100644 --- a/src/user/profile/profile.tsx +++ b/src/user/profile/profile.tsx @@ -34,7 +34,7 @@ interface InputEvent { } function Profile() { const formId = Number(router?.params.id) - const {user, updateUser} = useUser() + const {user, updateUser, loading} = useUser() const [sex, setSex] = useState() const [FormData, setFormData] = useState( @@ -49,16 +49,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 +151,12 @@ function Profile() { }); } + // 等待 useUser 初始化完成后再加载数据 useEffect(() => { - reload() - }, []); + if (!loading) { + reload() + } + }, [loading]); // 监听 useUser hook 中的用户信息变化,同步更新表单数据 useEffect(() => { @@ -151,6 +165,15 @@ function Profile() { } }, [user]); + // 加载中显示 + if (loading || pageLoading) { + return ( + + 加载中... + + ) + } + return ( <>
@@ -223,14 +246,14 @@ function Profile() { label="备注信息" name="comments" initialValue={FormData.comments} - rules={[{message: '备注信息'}]} + rules={[{message: '请输入备注信息'}]} > -