diff --git a/src/components/UserInfo/index.tsx b/src/components/UserInfo/index.tsx index fb9885f..ddff616 100644 --- a/src/components/UserInfo/index.tsx +++ b/src/components/UserInfo/index.tsx @@ -10,7 +10,7 @@ import { useUserActions } from "@/store/userStore"; import { UserInfoType } from "@/services/userService"; import { useCities, useProfessions } from "@/store/pickerOptionsStore"; import { formatNtrpDisplay } from "@/utils/helper"; -import FamilyContext from '@/context'; +import FamilyContext from "@/context"; // 用户信息接口 // export interface UserInfo { @@ -105,12 +105,22 @@ const UserInfoCardComponent: React.FC = ({ }); useEffect(() => { - const visibles = [gender_picker_visible, location_picker_visible, ntrp_picker_visible, occupation_picker_visible] - const showGuideBar = visibles.every(item => !item) + const visibles = [ + gender_picker_visible, + location_picker_visible, + ntrp_picker_visible, + occupation_picker_visible, + ]; + const showGuideBar = visibles.every((item) => !item); if (showGuideBar) { - handleGrandchildTrigger(false) + handleGrandchildTrigger(false); } - }, [gender_picker_visible, location_picker_visible, ntrp_picker_visible, occupation_picker_visible]) + }, [ + gender_picker_visible, + location_picker_visible, + ntrp_picker_visible, + occupation_picker_visible, + ]); // 职业数据 const professions = useProfessions(); @@ -142,7 +152,7 @@ const UserInfoCardComponent: React.FC = ({ // }; // 处理编辑弹窗 const handle_open_edit_modal = (field: string) => { - handleGrandchildTrigger(true) + handleGrandchildTrigger(true); if (field === "gender") { setGenderPickerVisible(true); return; @@ -161,11 +171,11 @@ const UserInfoCardComponent: React.FC = ({ } if (field === "nickname") { // 手动输入 - handleGrandchildTrigger(true) + handleGrandchildTrigger(true); setEditingField(field); setEditModalVisible(true); } else { - handleGrandchildTrigger(true) + handleGrandchildTrigger(true); setEditingField(field); setEditModalVisible(true); } @@ -178,6 +188,10 @@ const UserInfoCardComponent: React.FC = ({ await updateUserInfo({ [editing_field]: value }); + set_form_data((prev) => { + return { ...prev, ...update_data }; + }); + // 更新本地状态 // setFormData((prev) => { // const updated = { ...prev, [editing_field]: value }; @@ -338,7 +352,14 @@ const UserInfoCardComponent: React.FC = ({ /> - {user_info.nickname || ""} + { + handle_open_edit_modal("nickname"); + }} + > + {user_info.nickname || ""} + {user_info.join_date || ""} {is_current_user && ( @@ -472,7 +493,9 @@ const UserInfoCardComponent: React.FC = ({ editable && handle_open_edit_modal("ntrp_level"); }} > - {`NTRP ${formatNtrpDisplay(user_info.ntrp_level)}`} + {`NTRP ${formatNtrpDisplay( + user_info.ntrp_level + )}`} ) : is_current_user ? ( = ({ ) : null} - handle_open_edit_modal("personal_profile")}> + handle_open_edit_modal("personal_profile")} + > {user_info.personal_profile ? ( {user_info.personal_profile} ) : is_current_user ? ( - + = ({ {/* 编辑个人简介弹窗 */} + {/* = ({ onSave={handle_edit_modal_save} onCancel={handle_edit_modal_cancel} validationMessage="请填写 2-100 个字符" - /> + /> */} {/* 性别选择弹窗 */} {gender_picker_visible && ( = ({ }; // 自定义比较函数:只在关键 props 变化时重新渲染 -const arePropsEqual = (prevProps: UserInfoCardProps, nextProps: UserInfoCardProps) => { +const arePropsEqual = ( + prevProps: UserInfoCardProps, + nextProps: UserInfoCardProps +) => { // 使用 JSON.stringify 进行深度比较(注意:对于复杂对象可能有性能问题) const prevUserInfoStr = JSON.stringify(prevProps.user_info); const nextUserInfoStr = JSON.stringify(nextProps.user_info); @@ -781,8 +826,9 @@ export const GameTabs: React.FC = ({ {hosted_text} on_tab_change("participated")} > {participated_text} diff --git a/src/user_pages/edit/index.tsx b/src/user_pages/edit/index.tsx index 53da465..d00a6dc 100644 --- a/src/user_pages/edit/index.tsx +++ b/src/user_pages/edit/index.tsx @@ -316,7 +316,11 @@ const EditProfilePage: React.FC = () => { // 处理地区选择 const handle_location_change = (e: any) => { - if (!Array.isArray(e) || e.length < 3 || e.some((v) => v === undefined || v === null)) { + if ( + !Array.isArray(e) || + e.length < 3 || + e.some((v) => v === undefined || v === null) + ) { Taro.showToast({ title: "请完整选择地区", icon: "none", @@ -324,10 +328,10 @@ const EditProfilePage: React.FC = () => { return; } const [country, province, city] = e; - handle_field_edit({ - country: String(country ?? ""), - province: String(province ?? ""), - city: String(city ?? "") + handle_field_edit({ + country: String(country ?? ""), + province: String(province ?? ""), + city: String(city ?? ""), }); }; @@ -346,7 +350,11 @@ const EditProfilePage: React.FC = () => { // 处理职业选择 const handle_occupation_change = (e: any) => { - if (!Array.isArray(e) || e.length === 0 || e.some((v) => v === undefined || v === null)) { + if ( + !Array.isArray(e) || + e.length === 0 || + e.some((v) => v === undefined || v === null) + ) { Taro.showToast({ title: "请完整选择职业", icon: "none", @@ -354,7 +362,10 @@ const EditProfilePage: React.FC = () => { return; } // 职业可能是多级联动,将所有选中的值用空格连接 - const occupation_value = e.map((v) => String(v ?? "")).filter(Boolean).join(" "); + const occupation_value = e + .map((v) => String(v ?? "")) + .filter(Boolean) + .join(" "); handle_field_edit("occupation", occupation_value); };