From 175e5814e3ad4b2a01b4df038aed886f46b765df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Mon, 8 Dec 2025 09:58:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E8=AE=BE=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=202.5=EF=BC=8C=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=89=93=E5=BC=80=E6=97=B6=E6=AD=A3=E7=A1=AE=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=202.5=EF=BC=8C=E4=B8=8D=E5=86=8D=E9=BB=98=E8=AE=A4=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=201.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/NTRPEvaluatePopup/index.tsx | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/components/NTRPEvaluatePopup/index.tsx b/src/components/NTRPEvaluatePopup/index.tsx index fc4f78f..fc541ed 100644 --- a/src/components/NTRPEvaluatePopup/index.tsx +++ b/src/components/NTRPEvaluatePopup/index.tsx @@ -9,9 +9,7 @@ import { Button, Input, View, Text, Image } from "@tarojs/components"; import Taro from "@tarojs/taro"; import classnames from "classnames"; import CommonPopup from "../CommonPopup"; -import { getCurrentFullPath } from "@/utils"; -import evaluateService from "@/services/evaluateService"; -import { useUserActions } from "@/store/userStore"; +import { useUserActions, useUserInfo } from "@/store/userStore"; import { EvaluateCallback, EvaluateScene } from "@/store/evaluateStore"; import { useNtrpLevels } from "@/store/pickerOptionsStore"; import NTRPTestEntryCard from "../NTRPTestEntryCard"; @@ -67,6 +65,7 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { const [ntrp, setNtrp] = useState(""); const [guideShow, setGuideShow] = useState(() => showGuide); const { updateUserInfo } = useUserActions(); + const userInfo = useUserInfo(); const ntrpLevels = useNtrpLevels(); const options = [ ntrpLevels.map((item) => ({ @@ -97,23 +96,22 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { // }); // } + // 当弹窗打开或用户信息变化时,从用户信息中提取并更新 ntrp 状态 useEffect(() => { - getNtrp(); - }, []); - - async function getNtrp() { - const res = await evaluateService.getLastResult(); - if (res.code === 0 && res.data.has_ntrp_level) { - const match = res.data.user_ntrp_level.match(/-?\d+(\.\d+)?/); - if (!match) { + if (visible) { + if (userInfo?.ntrp_level) { + // 从 ntrp_level 中提取数字部分(如 "2.5" 或 "NTRP 2.5") + const match = String(userInfo.ntrp_level).match(/-?\d+(\.\d+)?/); + if (match) { + setNtrp(match[0]); + } else { + setNtrp(""); + } + } else { setNtrp(""); - return; } - setNtrp(match[0] as string); - } else { - setNtrp(""); } - } + }, [visible, userInfo?.ntrp_level]); // const showEntry = // displayCondition === "auto" @@ -128,7 +126,9 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { async function handleChangeNtrp() { Taro.showLoading({ title: "修改中" }); + // 更新用户信息,会自动更新 store 中的 ntrp_level await updateUserInfo({ ntrp_level: ntrp }); + Taro.hideLoading(); Taro.showToast({ title: "NTRP水平修改成功", icon: "none",