From a3c3087e4685633faf8729e3f06c7f7ca855ada7 Mon Sep 17 00:00:00 2001 From: Ultrame <1019265060@qq.com> Date: Sun, 19 Oct 2025 18:27:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=BA=E9=99=B7=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListLoadError/index.module.scss | 2 +- src/components/Picker/PopupPicker.tsx | 12 ++--- src/components/UserInfo/index.tsx | 53 ++++++++++++------- src/user_pages/edit/index.tsx | 28 +++++++--- .../setTransactionPassword/index.tsx | 4 +- 5 files changed, 63 insertions(+), 36 deletions(-) diff --git a/src/components/ListLoadError/index.module.scss b/src/components/ListLoadError/index.module.scss index 342b51b..1804db8 100644 --- a/src/components/ListLoadError/index.module.scss +++ b/src/components/ListLoadError/index.module.scss @@ -26,7 +26,7 @@ justify-content: center; width: 76px; background: #00000008; - border: 0.5px solid #0000001F; + border: 1.5px solid #e5e5e5; border-radius: 12px; padding: 12px 0; font-weight: 500; diff --git a/src/components/Picker/PopupPicker.tsx b/src/components/Picker/PopupPicker.tsx index 1d524a7..e4197af 100644 --- a/src/components/Picker/PopupPicker.tsx +++ b/src/components/Picker/PopupPicker.tsx @@ -1,6 +1,6 @@ -import React, { useState, useEffect, useCallback } from "react"; +import React, { useState, useEffect } from "react"; import CommonPopup from "@/components/CommonPopup"; -import { View, Text, Image } from "@tarojs/components"; +import { View } from "@tarojs/components"; import Picker from "./Picker"; import { renderYearMonth, @@ -9,7 +9,7 @@ import { } from "./PickerData"; import NTRPTestEntryCard from "../NTRPTestEntryCard"; import { EvaluateScene } from "@/store/evaluateStore"; -import imgs from "@/config/images"; +// import imgs from "@/config/images"; import styles from "./index.module.scss"; interface PickerOption { text: string | number; @@ -27,7 +27,7 @@ interface PickerProps { options?: PickerOption[][] | PickerOption[]; value?: (string | number)[]; type?: "month" | "day" | "hour" | "ntrp" | null; - img?: string; + // img?: string; onConfirm?: (options: PickerOption[], values: (string | number)[]) => void; onChange?: (value: (string | number)[]) => void; style?: React.CSSProperties; @@ -42,7 +42,7 @@ const PopupPicker = ({ visible, setvisible, value = [], - img, + // img, onConfirm, onChange, options = [], @@ -54,7 +54,6 @@ const PopupPicker = ({ const changePicker = (options: any[], values: any, columnIndex: number) => { if (onChange) { console.log("picker onChange", columnIndex, values, options); - if ( type === "day" && JSON.stringify(defaultValue) !== JSON.stringify(values) @@ -79,7 +78,6 @@ const PopupPicker = ({ }; const handleConfirm = () => { - console.log(defaultValue, "defaultValue"); onChange(defaultValue); setvisible(false); }; diff --git a/src/components/UserInfo/index.tsx b/src/components/UserInfo/index.tsx index a73cf97..a71cab5 100644 --- a/src/components/UserInfo/index.tsx +++ b/src/components/UserInfo/index.tsx @@ -78,7 +78,7 @@ export const UserInfoCard: React.FC = ({ useState(false); // 表单状态 - const [form_data, setFormData] = useState>({ + const [form_data] = useState>({ ...user_info, }); @@ -143,12 +143,14 @@ export const UserInfoCard: React.FC = ({ const update_data = { [editing_field]: value }; await UserService.update_user_info(update_data); + await updateUserInfo({ [editing_field]: value }); + // 更新本地状态 - setFormData((prev) => { - const updated = { ...prev, [editing_field]: value }; - typeof set_user_info === "function" && set_user_info(updated); - return updated; - }); + // setFormData((prev) => { + // const updated = { ...prev, [editing_field]: value }; + // typeof set_user_info === "function" && set_user_info(updated); + // return updated; + // }); // 关闭弹窗 setEditModalVisible(false); @@ -180,14 +182,14 @@ export const UserInfoCard: React.FC = ({ ) { await updateUserInfo({ ...field }); // 更新本地状态 - setFormData((prev) => ({ ...prev, ...field })); + // setFormData((prev) => ({ ...prev, ...field })); // setUserInfo((prev) => ({ ...prev, ...field })); } else { // 调用更新用户信息接口,只传递修改的字段 const update_data = { [field as string]: value }; await updateUserInfo(update_data); // 更新本地状态 - setFormData((prev) => ({ ...prev, [field as string]: value })); + // setFormData((prev) => ({ ...prev, [field as string]: value })); // setUserInfo((prev) => ({ ...prev, [field as string]: value })); } @@ -259,6 +261,22 @@ export const UserInfoCard: React.FC = ({ // 主办和参加暂时不处理,可以后续扩展 }; + const getDefaultOption = (options) => { + if (!Array.isArray(options) || options.length === 0) { + return []; + } + + const defaultOptions: string[] = []; + let current = options[0]; + + while (current) { + defaultOptions.push(current.text); + current = current.children?.[0]; + } + + return defaultOptions; + } + return ( {/* 头像和基本信息 */} @@ -385,7 +403,7 @@ export const UserInfoCard: React.FC = ({ 选择性别 ) : null} - {user_info.ntrp_level ? ( + {user_info.ntrp_level !== "0" ? ( {`NTRP ${user_info.ntrp_level}`} @@ -472,7 +490,7 @@ export const UserInfoCard: React.FC = ({ ]} visible={gender_picker_visible} setvisible={setGenderPickerVisible} - value={[form_data.gender || ""]} + value={form_data.gender === "" ? ["0"] : [form_data.gender]} onChange={handle_gender_change} /> )} @@ -484,11 +502,7 @@ export const UserInfoCard: React.FC = ({ options={cities} visible={location_picker_visible} setvisible={setLocationPickerVisible} - value={[ - form_data.country || "", - form_data.province || "", - form_data.city || "", - ]} + value={form_data.country ? [form_data.country, form_data.province, form_data.city] : getDefaultOption(cities)} onChange={handle_location_change} /> )} @@ -512,7 +526,7 @@ export const UserInfoCard: React.FC = ({ img={user_info.avatar_url || ""} visible={ntrp_picker_visible} setvisible={setNtrpPickerVisible} - value={[form_data.ntrp_level || ""]} + value={form_data.ntrp_level === "0" ? ["3.0"] : [form_data.ntrp_level]} onChange={handle_ntrp_level_change} /> )} @@ -524,7 +538,7 @@ export const UserInfoCard: React.FC = ({ options={professions} visible={occupation_picker_visible} setvisible={setOccupationPickerVisible} - value={[...(form_data.occupation || "").split(" ")]} + value={form_data.occupation ? [...form_data.occupation.split(" ")] : getDefaultOption(professions)} onChange={handle_occupation_change} /> )} @@ -665,9 +679,8 @@ 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 5056e07..0884e51 100644 --- a/src/user_pages/edit/index.tsx +++ b/src/user_pages/edit/index.tsx @@ -133,7 +133,7 @@ const EditProfilePage: React.FC = () => { const tempFilePath = res.tempFilePaths[0]; try { const avatar_url = await UserService.upload_avatar(tempFilePath); - setUserInfo((prev) => ({ ...prev, avatar: avatar_url })); + await updateUserInfo({ avatar: avatar_url }); Taro.showToast({ title: "头像上传成功", icon: "success", @@ -331,6 +331,22 @@ const EditProfilePage: React.FC = () => { } }; + const getDefaultOption = (options) => { + if (!Array.isArray(options) || options.length === 0) { + return []; + } + + const defaultOptions: string[] = []; + let current = options[0]; + + while (current) { + defaultOptions.push(current.text); + current = current.children?.[0]; + } + + return defaultOptions; + } + return ( {/* 导航栏 */} @@ -639,7 +655,7 @@ const EditProfilePage: React.FC = () => { ]} visible={gender_picker_visible} setvisible={setGenderPickerVisible} - value={[form_data.gender]} + value={form_data.gender === "" ? ["0"] : [form_data.gender]} onChange={handle_gender_change} /> )} @@ -671,7 +687,7 @@ const EditProfilePage: React.FC = () => { options={cities} visible={location_picker_visible} setvisible={setLocationPickerVisible} - value={[form_data.country, form_data.province, form_data.city]} + value={form_data.country ? [form_data.country, form_data.province, form_data.city] : getDefaultOption(cities)} onChange={handle_location_change} /> )} @@ -693,10 +709,10 @@ const EditProfilePage: React.FC = () => { ], ]} type="ntrp" - img={(user_info as UserInfoType)?.avatar_url} + // img={(user_info as UserInfoType)?.avatar_url} visible={ntrp_picker_visible} setvisible={setNtrpPickerVisible} - value={[form_data.ntrp_level]} + value={form_data.ntrp_level === "0" ? ["3.0"] : [form_data.ntrp_level]} onChange={handle_ntrp_level_change} /> )} @@ -709,7 +725,7 @@ const EditProfilePage: React.FC = () => { options={professions} visible={occupation_picker_visible} setvisible={setOccupationPickerVisible} - value={[...form_data.occupation.split(" ")]} + value={form_data.occupation ? [...form_data.occupation.split(" ")] : getDefaultOption(professions)} onChange={handle_occupation_change} /> )} diff --git a/src/user_pages/setTransactionPassword/index.tsx b/src/user_pages/setTransactionPassword/index.tsx index 9735cdb..8ef29c2 100644 --- a/src/user_pages/setTransactionPassword/index.tsx +++ b/src/user_pages/setTransactionPassword/index.tsx @@ -62,10 +62,10 @@ const SetTransactionPassword: React.FC = () => { const { new_password, confirm_password, sms_code } = formData; if (handleType === "set") { setValid( - !!sms_code && new_password.length === 6 && confirm_password.length === 6 + (sms_code !== "") && (new_password.length === 6) && (confirm_password.length === 6) ); } else { - setValid(new_password.length === 6 && confirm_password.length === 6); + setValid((new_password.length === 6) && (confirm_password.length === 6)); } }, [formData]);