个人设置中设置为 2.5,弹窗打开时正确显示 2.5,不再默认显示 1.5

This commit is contained in:
张成
2025-12-08 09:58:59 +08:00
parent 6ae6c8a028
commit 175e5814e3

View File

@@ -9,9 +9,7 @@ import { Button, Input, View, Text, Image } from "@tarojs/components";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import classnames from "classnames"; import classnames from "classnames";
import CommonPopup from "../CommonPopup"; import CommonPopup from "../CommonPopup";
import { getCurrentFullPath } from "@/utils"; import { useUserActions, useUserInfo } from "@/store/userStore";
import evaluateService from "@/services/evaluateService";
import { useUserActions } from "@/store/userStore";
import { EvaluateCallback, EvaluateScene } from "@/store/evaluateStore"; import { EvaluateCallback, EvaluateScene } from "@/store/evaluateStore";
import { useNtrpLevels } from "@/store/pickerOptionsStore"; import { useNtrpLevels } from "@/store/pickerOptionsStore";
import NTRPTestEntryCard from "../NTRPTestEntryCard"; import NTRPTestEntryCard from "../NTRPTestEntryCard";
@@ -67,6 +65,7 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => {
const [ntrp, setNtrp] = useState<string>(""); const [ntrp, setNtrp] = useState<string>("");
const [guideShow, setGuideShow] = useState(() => showGuide); const [guideShow, setGuideShow] = useState(() => showGuide);
const { updateUserInfo } = useUserActions(); const { updateUserInfo } = useUserActions();
const userInfo = useUserInfo();
const ntrpLevels = useNtrpLevels(); const ntrpLevels = useNtrpLevels();
const options = [ const options = [
ntrpLevels.map((item) => ({ ntrpLevels.map((item) => ({
@@ -97,23 +96,22 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => {
// }); // });
// } // }
// 当弹窗打开或用户信息变化时,从用户信息中提取并更新 ntrp 状态
useEffect(() => { useEffect(() => {
getNtrp(); if (visible) {
}, []); if (userInfo?.ntrp_level) {
// 从 ntrp_level 中提取数字部分(如 "2.5" 或 "NTRP 2.5"
async function getNtrp() { const match = String(userInfo.ntrp_level).match(/-?\d+(\.\d+)?/);
const res = await evaluateService.getLastResult(); if (match) {
if (res.code === 0 && res.data.has_ntrp_level) { setNtrp(match[0]);
const match = res.data.user_ntrp_level.match(/-?\d+(\.\d+)?/); } else {
if (!match) { setNtrp("");
}
} else {
setNtrp(""); setNtrp("");
return;
} }
setNtrp(match[0] as string);
} else {
setNtrp("");
} }
} }, [visible, userInfo?.ntrp_level]);
// const showEntry = // const showEntry =
// displayCondition === "auto" // displayCondition === "auto"
@@ -128,7 +126,9 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => {
async function handleChangeNtrp() { async function handleChangeNtrp() {
Taro.showLoading({ title: "修改中" }); Taro.showLoading({ title: "修改中" });
// 更新用户信息,会自动更新 store 中的 ntrp_level
await updateUserInfo({ ntrp_level: ntrp }); await updateUserInfo({ ntrp_level: ntrp });
Taro.hideLoading();
Taro.showToast({ Taro.showToast({
title: "NTRP水平修改成功", title: "NTRP水平修改成功",
icon: "none", icon: "none",