|
@@ -35,6 +35,7 @@ export default function LotteryScreen() {
|
|
|
|
|
|
|
|
const tradeNo = params.tradeNo as string;
|
|
const tradeNo = params.tradeNo as string;
|
|
|
const poolId = params.poolId as string;
|
|
const poolId = params.poolId as string;
|
|
|
|
|
+ const prefetchedResults = params.prefetchedResults as string | undefined;
|
|
|
|
|
|
|
|
const [results, setResults] = useState<any[]>([]);
|
|
const [results, setResults] = useState<any[]>([]);
|
|
|
const [pool, setPool] = useState<any[]>([]);
|
|
const [pool, setPool] = useState<any[]>([]);
|
|
@@ -102,50 +103,67 @@ export default function LotteryScreen() {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const loadData = async () => {
|
|
const loadData = async () => {
|
|
|
- if (tradeNo) {
|
|
|
|
|
- try {
|
|
|
|
|
- const res: any = await services.award.getApplyResult(tradeNo);
|
|
|
|
|
- const list = res?.data?.inventoryList || res?.inventoryList || [];
|
|
|
|
|
- setResults(list);
|
|
|
|
|
-
|
|
|
|
|
- // 2. Fetch Pool (Goods) if not passed
|
|
|
|
|
- if (poolId && !isGrid) {
|
|
|
|
|
- const detailRes = await services.award.getPoolDetail(poolId);
|
|
|
|
|
- const goods = detailRes?.luckGoodsList || [];
|
|
|
|
|
- setPool(goods);
|
|
|
|
|
- } else if (!isGrid) {
|
|
|
|
|
- setPool(list);
|
|
|
|
|
|
|
+ if (!tradeNo) return;
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 优先使用预取数据,避免重复网络请求
|
|
|
|
|
+ let list: any[] = [];
|
|
|
|
|
+ let videoFromRes = "";
|
|
|
|
|
+
|
|
|
|
|
+ if (prefetchedResults) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ list = JSON.parse(prefetchedResults);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.warn(
|
|
|
|
|
+ "Failed to parse prefetchedResults, falling back to API",
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (list.length === 0) {
|
|
|
|
|
+ // fallback: 没有预取数据时才调用 API
|
|
|
|
|
+ const res: any = await services.award.getApplyResult(tradeNo);
|
|
|
|
|
+ list = res?.data?.inventoryList || res?.inventoryList || [];
|
|
|
|
|
+ videoFromRes = res?.video || "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setResults(list);
|
|
|
|
|
+
|
|
|
|
|
+ // Pool 数据不阻塞动画,并行加载
|
|
|
|
|
+ if (poolId && !isGrid) {
|
|
|
|
|
+ services.award
|
|
|
|
|
+ .getPoolDetail(poolId)
|
|
|
|
|
+ .then((detailRes: any) => {
|
|
|
|
|
+ const goods = detailRes?.luckGoodsList || [];
|
|
|
|
|
+ setPool(goods);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => setPool(list));
|
|
|
|
|
+ } else if (!isGrid) {
|
|
|
|
|
+ setPool(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Auto show result after animation
|
|
|
|
|
+ if (timerRef.current) clearTimeout(timerRef.current);
|
|
|
|
|
|
|
|
- // Auto show result after animation
|
|
|
|
|
- if (timerRef.current) clearTimeout(timerRef.current);
|
|
|
|
|
-
|
|
|
|
|
- // Check for Level A video
|
|
|
|
|
- const hasLevelA = list.some((item: any) =>
|
|
|
|
|
- ["A", "a"].includes(item.level),
|
|
|
|
|
- );
|
|
|
|
|
- // Also check res.video if available
|
|
|
|
|
- const playVideoUrl =
|
|
|
|
|
- res.video || (hasLevelA ? DEFAULT_JACKPOT_VIDEO : "");
|
|
|
|
|
-
|
|
|
|
|
- if (playVideoUrl) {
|
|
|
|
|
- console.log("Found Level A, preparing video:", playVideoUrl);
|
|
|
|
|
- setVideoUrl(playVideoUrl);
|
|
|
|
|
- setVideoVisible(true);
|
|
|
|
|
- // Do NOT set timer here, wait for video to finish
|
|
|
|
|
- } else {
|
|
|
|
|
- if (!isGrid) {
|
|
|
|
|
- // Reel mode uses timer
|
|
|
|
|
- timerRef.current = setTimeout(() => {
|
|
|
|
|
- handleFinish(list);
|
|
|
|
|
- }, 2800);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // Check for Level A video
|
|
|
|
|
+ const hasLevelA = list.some((item: any) =>
|
|
|
|
|
+ ["A", "a"].includes(item.level),
|
|
|
|
|
+ );
|
|
|
|
|
+ const playVideoUrl =
|
|
|
|
|
+ videoFromRes || (hasLevelA ? DEFAULT_JACKPOT_VIDEO : "");
|
|
|
|
|
+
|
|
|
|
|
+ if (playVideoUrl) {
|
|
|
|
|
+ console.log("Found Level A, preparing video:", playVideoUrl);
|
|
|
|
|
+ setVideoUrl(playVideoUrl);
|
|
|
|
|
+ setVideoVisible(true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (!isGrid) {
|
|
|
|
|
+ timerRef.current = setTimeout(() => {
|
|
|
|
|
+ handleFinish(list);
|
|
|
|
|
+ }, 2800);
|
|
|
}
|
|
}
|
|
|
- // Grid mode handles finish via callback
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error("Load Data Error", error);
|
|
|
|
|
- // Safety fallback?
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error("Load Data Error", error);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|