添加发布球局拦截

This commit is contained in:
2026-02-11 09:09:53 +08:00
parent 4f0cdad920
commit 08092a89ab
3 changed files with 69 additions and 26 deletions

View File

@@ -4,7 +4,11 @@ import ListLoadError from "@/components/ListLoadError";
import ListCardSkeleton from "@/components/ListCardSkeleton";
import { useReachBottom } from "@tarojs/taro";
import Taro from "@tarojs/taro";
import { useUserInfo, useUserActions, useLastTestResult } from "@/store/userStore";
import {
useUserInfo,
useUserActions,
useLastTestResult,
} from "@/store/userStore";
import { NTRPTestEntryCard } from "@/components";
import { EvaluateScene } from "@/store/evaluateStore";
import { waitForAuthInit } from "@/utils/authInit";
@@ -46,7 +50,11 @@ const ListContainer = (props) => {
const { fetchUserInfo, fetchLastTestResult } = useUserActions();
// 使用全局状态中的测试结果,避免重复调用接口
const lastTestResult = useLastTestResult();
const { bannerListImage, bannerDetailImage, bannerListIndex = 0 } = useDictionaryStore((s) => s.bannerDict) || {};
const {
bannerListImage,
bannerDetailImage,
bannerListIndex = 0,
} = useDictionaryStore((s) => s.bannerDict) || {};
useReachBottom(() => {
// 加载更多方法
if (loading) {
@@ -102,7 +110,7 @@ const ListContainer = (props) => {
// 先等待静默登录完成
await waitForAuthInit();
// 然后再获取用户信息
const userInfoId = userInfo && 'id' in userInfo ? userInfo.id : null;
const userInfoId = userInfo && "id" in userInfo ? userInfo.id : null;
if (!userInfoId) {
await fetchUserInfo();
return; // 等待下一次 useEffect 触发(此时 userInfo.id 已有值)
@@ -113,7 +121,13 @@ const ListContainer = (props) => {
}
};
init();
}, [evaluateFlag, enableHomeCards, userInfo, lastTestResult, fetchLastTestResult]);
}, [
evaluateFlag,
enableHomeCards,
userInfo,
lastTestResult,
fetchLastTestResult,
]);
// 从全局状态中获取测试状态
const hasTestInLastMonth = lastTestResult?.has_test_in_last_month || false;
@@ -142,7 +156,11 @@ const ListContainer = (props) => {
const idx = Number(bannerListIndex);
return [
...list.slice(0, idx),
{ type: "banner", banner_image_url: bannerListImage, banner_detail_url: bannerDetailImage },
{
type: "banner",
banner_image_url: bannerListImage,
banner_detail_url: bannerDetailImage,
},
...list.slice(idx),
];
}
@@ -151,7 +169,9 @@ const ListContainer = (props) => {
function insertEvaluateCard(list) {
if (!list || !Array.isArray(list)) return insertBannerCard(list ?? []);
const limitedList = shouldLimitByShowNumber ? list.slice(0, showNumber) : list;
const limitedList = shouldLimitByShowNumber
? list.slice(0, showNumber)
: list;
if (!evaluateFlag || hasTestInLastMonth) {
return insertBannerCard(limitedList);
@@ -168,7 +188,16 @@ const ListContainer = (props) => {
const memoizedList = useMemo(
() => (enableHomeCards ? insertEvaluateCard(data) : data),
[enableHomeCards, evaluateFlag, data, hasTestInLastMonth, showNumber, bannerListImage, bannerDetailImage, bannerListIndex]
[
enableHomeCards,
evaluateFlag,
data,
hasTestInLastMonth,
showNumber,
bannerListImage,
bannerDetailImage,
bannerListIndex,
]
);
// 渲染 banner 卡片
@@ -183,7 +212,9 @@ const ListContainer = (props) => {
const target = item.banner_detail_url;
if (target) {
(Taro as any).navigateTo({
url: `/other_pages/bannerDetail/index?img=${encodeURIComponent(target)}`,
url: `/other_pages/bannerDetail/index?img=${encodeURIComponent(
target
)}`,
});
}
}}
@@ -196,8 +227,7 @@ const ListContainer = (props) => {
backgroundPosition: "center",
backgroundRepeat: "no-repeat",
}}
>
</View>
></View>
);
};
@@ -229,7 +259,10 @@ const ListContainer = (props) => {
}
if (enableHomeCards && match?.type === "evaluateCard") {
return (
<NTRPTestEntryCard key={`evaluate-${index}`} type={EvaluateScene.list} />
<NTRPTestEntryCard
key={`evaluate-${index}`}
type={EvaluateScene.list}
/>
);
}
return <ListCard key={match?.id || index} {...match} />;