初始化足球投注平台 MVP Monorepo

包含 NestJS 后端、三端前端、Prisma 数据模型、结算引擎测试与 PRD 文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-02 14:35:48 +08:00
commit 14e49374ac
118 changed files with 15944 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
<script setup lang="ts">
import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useBetSlipStore } from '../stores/betSlip';
import api from '../api';
const props = defineProps<{ modelValue: boolean }>();
const emit = defineEmits<{ 'update:modelValue': [boolean] }>();
const { t } = useI18n();
const slip = useBetSlipStore();
const show = computed({
get: () => props.modelValue,
set: (v) => emit('update:modelValue', v),
});
const loading = ref(false);
const error = ref('');
const success = ref('');
function genId() {
return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
}
async function placeBet() {
if (!slip.items.length) return;
loading.value = true;
error.value = '';
success.value = '';
try {
const requestId = genId();
if (slip.mode === 'parlay' && slip.items.length >= 2) {
if (slip.hasSameMatch) {
error.value = '同一场比赛不能串关';
return;
}
await api.post('/player/bets/parlay', {
legs: slip.items.map((i) => ({
selectionId: i.selectionId,
oddsVersion: i.oddsVersion,
})),
stake: slip.stake,
requestId,
});
} else if (slip.items.length === 1) {
const item = slip.items[0];
await api.post('/player/bets/single', {
selectionId: item.selectionId,
oddsVersion: item.oddsVersion,
stake: slip.stake,
requestId,
});
} else {
error.value = '请选择投注项';
return;
}
success.value = '下注成功!';
slip.clear();
setTimeout(() => { show.value = false; success.value = ''; }, 1500);
} catch (e: unknown) {
error.value = (e as { response?: { data?: { error?: string } } })?.response?.data?.error || '下注失败';
} finally {
loading.value = false;
}
}
</script>
<template>
<div v-if="show" class="overlay" @click.self="show = false">
<div class="drawer">
<div class="drawer-header">
<h3>{{ t('bet.bet_slip') }} ({{ slip.count }})</h3>
<button @click="show = false"></button>
</div>
<div v-if="!slip.items.length" class="empty">点击赔率添加投注</div>
<div v-for="item in slip.items" :key="item.selectionId" class="slip-item">
<div class="item-name">{{ item.matchName }}</div>
<div class="item-sel">{{ item.selectionName }} @ {{ item.odds }}</div>
<button class="remove" @click="slip.removeItem(item.selectionId)">移除</button>
</div>
<div v-if="slip.hasSameMatch" class="warn">同场比赛不能串关可作为单关分别投注</div>
<div v-if="slip.items.length" class="stake-area">
<label>{{ t('bet.stake') }}</label>
<input v-model.number="slip.stake" type="number" min="1" />
<div v-if="slip.isParlay" class="mode-tag">{{ t('bet.parlay') }} · 赔率 {{ slip.totalOdds.toFixed(2) }}</div>
<div class="return">预计返还: {{ slip.potentialReturn.toFixed(2) }}</div>
</div>
<p v-if="error" class="error">{{ error }}</p>
<p v-if="success" class="success">{{ success }}</p>
<button class="btn-primary" :disabled="loading || !slip.items.length" @click="placeBet">
{{ t('bet.place_bet') }}
</button>
</div>
</div>
</template>
<style scoped>
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; display: flex; align-items: flex-end; }
.drawer { background: #1a2332; width: 100%; max-height: 80vh; border-radius: 16px 16px 0 0; padding: 16px; overflow-y: auto; }
.drawer-header { display: flex; justify-content: space-between; margin-bottom: 16px; }
.drawer-header button { background: none; color: var(--text-muted); font-size: 20px; }
.slip-item { padding: 12px; background: var(--bg-hover); border-radius: 6px; margin-bottom: 8px; }
.item-name { font-size: 13px; font-weight: 600; }
.item-sel { font-size: 12px; color: var(--text-muted); }
.remove { background: none; color: var(--danger); font-size: 12px; margin-top: 4px; }
.stake-area { margin: 16px 0; }
.stake-area label { font-size: 13px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.return { font-size: 14px; color: #ffd700; margin-top: 8px; }
.mode-tag { font-size: 12px; color: var(--primary); margin-top: 4px; }
.warn { color: #ff9800; font-size: 12px; margin-bottom: 8px; }
.error { color: var(--danger); font-size: 13px; }
.success { color: var(--primary); font-size: 13px; }
.empty { text-align: center; color: var(--text-muted); padding: 24px; }
</style>