个人设置中设置为 2.5,弹窗打开时正确显示 2.5,不再默认显示 1.5
This commit is contained in:
@@ -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<string>("");
|
||||
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("");
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user