diff --git a/_doc/ntrp.md b/_doc/ntrp.md new file mode 100644 index 0000000..e450c1f --- /dev/null +++ b/_doc/ntrp.md @@ -0,0 +1,12 @@ + + 1 球局 ntrp 异化卡片 + + 点击 如果未绑定手机号,点击测试卡片,跳转登录页 + + + 2.点击授权手机号完成后,直接跳转「首次测试 启动页 + + + 3.已绑定手机号,点击测试卡片,直接进入测试题 + +4 .曾经测过 进入曾经测过的 页面 \ No newline at end of file diff --git a/src/components/NTRPTestEntryCard/index.tsx b/src/components/NTRPTestEntryCard/index.tsx index f973166..8bbfc10 100644 --- a/src/components/NTRPTestEntryCard/index.tsx +++ b/src/components/NTRPTestEntryCard/index.tsx @@ -19,6 +19,7 @@ function NTRPTestEntryCard(props: { evaluateCallback?: EvaluateCallback; }) { const [testFlag, setTestFlag] = useState(false); + const [hasTestInLastMonth, setHasTestInLastMonth] = useState(false); const { type, evaluateCallback } = props; const userInfo = useUserInfo(); const { setCallback } = useEvaluate(); @@ -36,7 +37,10 @@ function NTRPTestEntryCard(props: { } // 获取测试结果 const res = await evaluateService.getLastResult(); - setTestFlag(res.code === 0 && res.data.has_ntrp_level); + if (res.code === 0) { + setTestFlag(res.data.has_ntrp_level); + setHasTestInLastMonth(res.data.has_test_in_last_month); + } }; init(); }, [userInfo.id]); @@ -115,6 +119,11 @@ function NTRPTestEntryCard(props: { [setCallback, testFlag, type, evaluateCallback] ); + // 如果最近一个月有测试记录,则不展示 + if (hasTestInLastMonth) { + return null; + } + return type === EvaluateScene.list ? ( diff --git a/src/container/listContainer/index.tsx b/src/container/listContainer/index.tsx index 7a09f47..545c41d 100644 --- a/src/container/listContainer/index.tsx +++ b/src/container/listContainer/index.tsx @@ -3,10 +3,12 @@ import ListCard from "@/components/ListCard"; import ListLoadError from "@/components/ListLoadError"; import ListCardSkeleton from "@/components/ListCardSkeleton"; import { useReachBottom } from "@tarojs/taro"; -import { useUserInfo } from "@/store/userStore"; +import { useUserInfo, useUserActions } from "@/store/userStore"; import { setStorage, getStorage } from "@/store/storage"; import { NTRPTestEntryCard } from "@/components"; import { EvaluateScene } from "@/store/evaluateStore"; +import evaluateService from "@/services/evaluateService"; +import { waitForAuthInit } from "@/utils/authInit"; import "./index.scss"; import { useRef, useEffect, useState, useMemo } from "react"; @@ -34,8 +36,10 @@ const ListContainer = (props) => { const [showNumber, setShowNumber] = useState(0); const [showSkeleton, setShowSkeleton] = useState(false); + const [hasTestInLastMonth, setHasTestInLastMonth] = useState(false); const userInfo = useUserInfo(); + const { fetchUserInfo } = useUserActions(); useReachBottom(() => { // 加载更多方法 @@ -85,6 +89,25 @@ const ListContainer = (props) => { }; }, []); + // 获取测试结果,判断最近一个月是否有测试记录 + useEffect(() => { + const init = async () => { + if (!evaluateFlag) return; + // 先等待静默登录完成 + await waitForAuthInit(); + // 然后再获取用户信息 + if (!userInfo.id) { + await fetchUserInfo(); + } + // 获取测试结果 + const res = await evaluateService.getLastResult(); + if (res.code === 0) { + setHasTestInLastMonth(res.data.has_test_in_last_month); + } + }; + init(); + }, [evaluateFlag, userInfo.id]); + if (error) { return ; } @@ -99,32 +122,27 @@ const ListContainer = (props) => { ); }; - // 对于没有ntrp等级的用户每个月展示一次, 插在第三个位置 + // 对于没有ntrp等级的用户每个月展示一次, 插在第二个位置后面 function insertEvaluateCard(list) { if (!evaluateFlag) return list; if (!list || list.length === 0) { return list; } - // if (userInfo.ntrp_level) { - // return list; - // } - // const lastShowTime = getStorage("list_evaluate_card"); - // if (!lastShowTime) { - // setStorage("list_evaluate_card", Date.now()); - // } - // if (Date.now() - Number(lastShowTime) < 30 * 24 * 60 * 60 * 1000) { - // return list; - // } - if (list.length <= 3) { + // 如果最近一个月有测试记录,则不插入 card + if (hasTestInLastMonth) { + return list; + } + + if (list.length <= 2) { return [...list, { type: "evaluateCard" }]; } - const [item1, item2, item3, ...rest] = list; - return [item1, item2, item3, { type: "evaluateCard" }, ...rest]; + const [item1, item2, ...rest] = list; + return [item1, item2, { type: "evaluateCard" }, ...rest]; } const memoizedList = useMemo( () => insertEvaluateCard(data), - [evaluateFlag, data, userInfo.ntrp_level] + [evaluateFlag, data, hasTestInLastMonth] ); // 渲染列表 diff --git a/src/services/evaluateService.ts b/src/services/evaluateService.ts index 178577b..a661c26 100644 --- a/src/services/evaluateService.ts +++ b/src/services/evaluateService.ts @@ -93,6 +93,7 @@ export interface LastTimeTestResult { has_ntrp_level: boolean; user_ntrp_level: string; last_test_result: TestResult; + has_test_in_last_month: boolean; // 最近一个月是否有测试记录 } class EvaluateService {