diff --git a/src/components/NTRPEvaluatePopup/index.tsx b/src/components/NTRPEvaluatePopup/index.tsx index 3e041fe..fc4f78f 100644 --- a/src/components/NTRPEvaluatePopup/index.tsx +++ b/src/components/NTRPEvaluatePopup/index.tsx @@ -13,20 +13,13 @@ import { getCurrentFullPath } from "@/utils"; import evaluateService from "@/services/evaluateService"; import { useUserActions } from "@/store/userStore"; import { EvaluateCallback, EvaluateScene } from "@/store/evaluateStore"; +import { useNtrpLevels } from "@/store/pickerOptionsStore"; import NTRPTestEntryCard from "../NTRPTestEntryCard"; import NtrpPopupGuide from "../NTRPPopupGuide"; import Picker from "../Picker/Picker"; import CloseIcon from "@/static/ntrp/ntrp_popup_close.svg"; import styles from "./index.module.scss"; -const ntrpLevels = ["1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "4.5+"]; -const options = [ - ntrpLevels.map((item) => ({ - text: item, - value: item, - })), -]; - export enum EvaluateType { EDIT = "edit", EVALUATE = "evaluate", @@ -74,6 +67,13 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { const [ntrp, setNtrp] = useState(""); const [guideShow, setGuideShow] = useState(() => showGuide); const { updateUserInfo } = useUserActions(); + const ntrpLevels = useNtrpLevels(); + const options = [ + ntrpLevels.map((item) => ({ + text: item, + value: item, + })), + ]; const [evaCallback, setEvaCallback] = useState({ type: "", next: () => {}, diff --git a/src/components/UserInfo/index.tsx b/src/components/UserInfo/index.tsx index 62cf654..3e978f6 100644 --- a/src/components/UserInfo/index.tsx +++ b/src/components/UserInfo/index.tsx @@ -8,7 +8,7 @@ import { UserService, PickerOption } from "@/services/userService"; import { PopupPicker } from "@/components/Picker/index"; import { useUserActions, useNicknameChangeStatus } from "@/store/userStore"; import { UserInfoType } from "@/services/userService"; -import { useCities, useProfessions } from "@/store/pickerOptionsStore"; +import { useCities, useProfessions, useNtrpLevels } from "@/store/pickerOptionsStore"; import { formatNtrpDisplay } from "@/utils/helper"; import { useGlobalState } from "@/store/global"; import evaluateService from "@/services/evaluateService"; @@ -80,6 +80,7 @@ const UserInfoCardComponent: React.FC = ({ const nickname_change_status = useNicknameChangeStatus(); const { setShowGuideBar } = useGlobalState(); const { updateUserInfo, updateNickname } = useUserActions(); + const ntrpLevels = useNtrpLevels(); const [ntrpTested, setNtrpTested] = useState(false); // 使用 useRef 记录上一次的 user_info,只在真正变化时打印 @@ -674,16 +675,10 @@ const UserInfoCardComponent: React.FC = ({ showHeader={true} title="选择 NTRP 自评水平" ntrpTested={ntrpTested} - options={[ - { text: "1.5", value: "1.5" }, - { text: "2.0", value: "2.0" }, - { text: "2.5", value: "2.5" }, - { text: "3.0", value: "3.0" }, - { text: "3.5", value: "3.5" }, - { text: "4.0", value: "4.0" }, - { text: "4.5", value: "4.5" }, - { text: "4.5+", value: "4.5+" }, - ]} + options={ntrpLevels.map((level) => ({ + text: level, + value: level, + }))} type="ntrp" img={user_info.avatar_url || ""} visible={ntrp_picker_visible} diff --git a/src/store/pickerOptionsStore.ts b/src/store/pickerOptionsStore.ts index 14695e3..0c7ccc4 100644 --- a/src/store/pickerOptionsStore.ts +++ b/src/store/pickerOptionsStore.ts @@ -5,6 +5,7 @@ import { UserService } from "@/services/userService"; export interface PickerOptionState { cities: any[]; professions: any[]; + ntrpLevels: string[]; getCities: () => Promise; getProfessions: () => Promise; } @@ -12,6 +13,7 @@ export interface PickerOptionState { export const usePickerOption = create((set) => ({ cities: [], professions: [], + ntrpLevels: ["1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "4.5+"], getCities: async () => { try { const res = await UserService.getCities(); @@ -37,3 +39,4 @@ export const usePickerOption = create((set) => ({ export const useCities = () => usePickerOption((state) => state.cities); export const useProfessions = () => usePickerOption((state) => state.professions); +export const useNtrpLevels = () => usePickerOption((state) => state.ntrpLevels); diff --git a/src/user_pages/edit/index.tsx b/src/user_pages/edit/index.tsx index a448bd7..36938cd 100644 --- a/src/user_pages/edit/index.tsx +++ b/src/user_pages/edit/index.tsx @@ -15,7 +15,7 @@ import { useNicknameChangeStatus, } from "@/store/userStore"; import { UserInfoType } from "@/services/userService"; -import { useCities, useProfessions } from "@/store/pickerOptionsStore"; +import { useCities, useProfessions, useNtrpLevels } from "@/store/pickerOptionsStore"; import { handleCustomerService } from "@/services/userService"; import evaluateService from "@/services/evaluateService"; @@ -24,6 +24,7 @@ const EditProfilePage: React.FC = () => { // 直接从store获取用户信息,确保响应式更新 const user_info = useUserInfo(); const nickname_change_status = useNicknameChangeStatus(); + const ntrpLevels = useNtrpLevels(); // 表单状态,基于store中的用户信息初始化 const getInitialFormData = () => { @@ -894,16 +895,10 @@ const EditProfilePage: React.FC = () => { title="选择 NTRP 自评水平" confirmText="保存" ntrpTested={ntrpTested} - options={[ - { text: "1.5", value: "1.5" }, - { text: "2.0", value: "2.0" }, - { text: "2.5", value: "2.5" }, - { text: "3.0", value: "3.0" }, - { text: "3.5", value: "3.5" }, - { text: "4.0", value: "4.0" }, - { text: "4.5", value: "4.5" }, - { text: "4.5+", value: "4.5+" }, - ]} + options={ntrpLevels.map((level) => ({ + text: level, + value: level, + }))} type="ntrp" // img={(user_info as UserInfoType)?.avatar_url} visible={ntrp_picker_visible}