This commit is contained in:
wchino
2026-06-13 17:38:25 +08:00
parent e7e938f261
commit 7b33d9f9fa
190 changed files with 23222 additions and 4336 deletions

View File

@@ -20,40 +20,25 @@ export interface PlayerMatchSummary {
bettingOpen?: boolean;
matchPhase?: MatchPhase;
score?: {
htHome: number;
htAway: number;
ftHome: number;
ftAway: number;
htHome: number | null;
htAway: number | null;
ftHome: number | null;
ftAway: number | null;
homeCorners?: number | null;
awayCorners?: number | null;
homeYellowCards?: number | null;
awayYellowCards?: number | null;
homeRedCards?: number | null;
awayRedCards?: number | null;
homeCards?: number | null;
awayCards?: number | null;
} | null;
}
export interface ParlayMarketSelection {
id: string;
selectionCode: string;
selectionName: string;
odds: string;
oddsVersion: string;
}
export interface ParlayMarket {
id: string;
marketType: string;
lineValue?: string | number | null;
allowParlay?: boolean;
selections: ParlayMarketSelection[];
}
export interface ParlayMatch extends PlayerMatchSummary {
markets: ParlayMarket[];
}
const summaryMatches = shallowRef<PlayerMatchSummary[]>([]);
const parlayMatches = shallowRef<ParlayMatch[]>([]);
const summaryLoading = ref(false);
const parlayLoading = ref(false);
let summaryInflight: Promise<void> | null = null;
let parlayInflight: Promise<void> | null = null;
async function loadSummary(force = false): Promise<void> {
if (force) summaryMatches.value = [];
@@ -76,74 +61,10 @@ async function loadSummary(force = false): Promise<void> {
return summaryInflight;
}
async function loadParlay(force = false): Promise<void> {
if (force) parlayMatches.value = [];
const hadData = parlayMatches.value.length > 0;
if (!force && hadData) {
if (parlayInflight) return parlayInflight;
parlayInflight = (async () => {
try {
const { data } = await api.get('/player/matches', { params: { scope: 'parlay' } });
mergeParlayOdds((data.data ?? []) as ParlayMatch[]);
} finally {
parlayInflight = null;
}
})();
return parlayInflight;
}
if (parlayInflight) return parlayInflight;
parlayLoading.value = true;
parlayInflight = (async () => {
try {
const { data } = await api.get('/player/matches', { params: { scope: 'parlay' } });
parlayMatches.value = (data.data ?? []) as ParlayMatch[];
} catch {
parlayMatches.value = [];
} finally {
parlayLoading.value = false;
parlayInflight = null;
}
})();
return parlayInflight;
}
function mergeParlayOdds(fresh: ParlayMatch[]) {
const matchMap = new Map<string, ParlayMatch>();
for (const m of fresh) matchMap.set(m.id, m);
for (const match of parlayMatches.value) {
const freshMatch = matchMap.get(match.id);
if (!freshMatch) continue;
const marketMap = new Map<string, ParlayMarket>();
for (const mk of freshMatch.markets) marketMap.set(mk.id, mk);
for (const market of match.markets) {
const freshMarket = marketMap.get(market.id);
if (!freshMarket) continue;
const selMap = new Map<string, ParlayMarketSelection>();
for (const s of freshMarket.selections) selMap.set(s.id, s);
for (const sel of market.selections) {
const fs = selMap.get(sel.id);
if (fs) {
sel.odds = fs.odds;
sel.oddsVersion = fs.oddsVersion;
}
}
}
}
}
/** 赛事列表与串关共享缓存,避免重复拉取大 JSON */
export function usePlayerMatches() {
return {
summaryMatches,
parlayMatches,
summaryLoading,
parlayLoading,
loadSummary,
loadParlay,
};
}