初始化足球投注平台 MVP Monorepo
包含 NestJS 后端、三端前端、Prisma 数据模型、结算引擎测试与 PRD 文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
25
apps/player/src/stores/auth.ts
Normal file
25
apps/player/src/stores/auth.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import api from '../api';
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const token = ref(localStorage.getItem('token') || '');
|
||||
const user = ref(JSON.parse(localStorage.getItem('user') || 'null'));
|
||||
|
||||
async function login(username: string, password: string) {
|
||||
const { data } = await api.post('/player/auth/login', { username, password });
|
||||
token.value = data.data.token;
|
||||
user.value = data.data.user;
|
||||
localStorage.setItem('token', token.value);
|
||||
localStorage.setItem('user', JSON.stringify(user.value));
|
||||
}
|
||||
|
||||
function logout() {
|
||||
token.value = '';
|
||||
user.value = null;
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
}
|
||||
|
||||
return { token, user, login, logout };
|
||||
});
|
||||
74
apps/player/src/stores/betSlip.ts
Normal file
74
apps/player/src/stores/betSlip.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
export interface SlipItem {
|
||||
selectionId: string;
|
||||
oddsVersion: string;
|
||||
matchId: string;
|
||||
matchName: string;
|
||||
selectionName: string;
|
||||
odds: number;
|
||||
marketType: string;
|
||||
}
|
||||
|
||||
export const useBetSlipStore = defineStore('betSlip', () => {
|
||||
const items = ref<SlipItem[]>([]);
|
||||
const stake = ref<number>(10);
|
||||
const mode = ref<'single' | 'parlay'>('single');
|
||||
|
||||
const count = computed(() => items.value.length);
|
||||
const isParlay = computed(() => items.value.length >= 2);
|
||||
|
||||
function addItem(item: SlipItem) {
|
||||
const existing = items.value.findIndex(
|
||||
(i) => i.selectionId === item.selectionId,
|
||||
);
|
||||
if (existing >= 0) {
|
||||
items.value.splice(existing, 1);
|
||||
return;
|
||||
}
|
||||
items.value.push(item);
|
||||
if (items.value.length >= 2) mode.value = 'parlay';
|
||||
}
|
||||
|
||||
function removeItem(selectionId: string) {
|
||||
items.value = items.value.filter((i) => i.selectionId !== selectionId);
|
||||
if (items.value.length < 2) mode.value = 'single';
|
||||
}
|
||||
|
||||
function clear() {
|
||||
items.value = [];
|
||||
mode.value = 'single';
|
||||
}
|
||||
|
||||
const totalOdds = computed(() =>
|
||||
items.value.reduce((acc, i) => acc * i.odds, 1),
|
||||
);
|
||||
|
||||
const potentialReturn = computed(() =>
|
||||
mode.value === 'parlay'
|
||||
? stake.value * totalOdds.value
|
||||
: items.value.length === 1
|
||||
? stake.value * items.value[0].odds
|
||||
: 0,
|
||||
);
|
||||
|
||||
const hasSameMatch = computed(() => {
|
||||
const matchIds = items.value.map((i) => i.matchId);
|
||||
return new Set(matchIds).size !== matchIds.length;
|
||||
});
|
||||
|
||||
return {
|
||||
items,
|
||||
stake,
|
||||
mode,
|
||||
count,
|
||||
isParlay,
|
||||
totalOdds,
|
||||
potentialReturn,
|
||||
hasSameMatch,
|
||||
addItem,
|
||||
removeItem,
|
||||
clear,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user