869 lines
27 KiB
HTML
Executable File
869 lines
27 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Xóc Đĩa 游戏 - 前端测试页面</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Microsoft YaHei', Arial, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.header {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
margin-bottom: 20px;
|
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.header h1 {
|
|
color: #333;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header .status {
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.status-item {
|
|
background: #f5f5f5;
|
|
padding: 10px 20px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
.status-item label {
|
|
color: #666;
|
|
font-size: 12px;
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.status-item .value {
|
|
color: #333;
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.game-area {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 20px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.card {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.card h2 {
|
|
color: #333;
|
|
margin-bottom: 15px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 2px solid #667eea;
|
|
}
|
|
|
|
.result-display {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
gap: 10px;
|
|
padding: 30px;
|
|
background: #f9f9f9;
|
|
border-radius: 10px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.coin {
|
|
width: 60px;
|
|
height: 60px;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 40px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
|
animation: flip 0.6s ease;
|
|
}
|
|
|
|
.coin.red {
|
|
background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
|
|
color: white;
|
|
}
|
|
|
|
.coin.white {
|
|
background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
|
|
color: #333;
|
|
}
|
|
|
|
@keyframes flip {
|
|
0%, 100% { transform: rotateY(0deg); }
|
|
50% { transform: rotateY(180deg); }
|
|
}
|
|
|
|
.result-text {
|
|
text-align: center;
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
color: #667eea;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.betting-area {
|
|
display: grid;
|
|
grid-template-columns: repeat(2, 1fr);
|
|
gap: 10px;
|
|
}
|
|
|
|
.bet-button {
|
|
padding: 15px;
|
|
border: 2px solid #ddd;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
background: white;
|
|
}
|
|
|
|
.bet-button:hover {
|
|
background: #f0f0f0;
|
|
border-color: #667eea;
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.bet-button.active {
|
|
background: #667eea;
|
|
color: white;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.bet-button .bet-name {
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.bet-button .bet-odds {
|
|
font-size: 14px;
|
|
color: #666;
|
|
}
|
|
|
|
.bet-button.active .bet-odds {
|
|
color: #fff;
|
|
}
|
|
|
|
.bet-amount-input {
|
|
margin: 15px 0;
|
|
}
|
|
|
|
.bet-amount-input input {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #ddd;
|
|
border-radius: 5px;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.quick-amounts {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.quick-amount {
|
|
flex: 1;
|
|
padding: 10px;
|
|
background: #f5f5f5;
|
|
border: 2px solid #ddd;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
text-align: center;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.quick-amount:hover {
|
|
background: #e0e0e0;
|
|
}
|
|
|
|
.submit-bet {
|
|
width: 100%;
|
|
padding: 15px;
|
|
background: linear-gradient(135deg, #667eea, #764ba2);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.submit-bet:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
|
|
}
|
|
|
|
.submit-bet:disabled {
|
|
background: #ccc;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.countdown {
|
|
text-align: center;
|
|
font-size: 48px;
|
|
font-weight: bold;
|
|
color: #667eea;
|
|
padding: 20px;
|
|
background: #f9f9f9;
|
|
border-radius: 10px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.countdown.urgent {
|
|
color: #ff6b6b;
|
|
animation: pulse 1s infinite;
|
|
}
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { transform: scale(1); }
|
|
50% { transform: scale(1.1); }
|
|
}
|
|
|
|
.logs {
|
|
background: #1e1e1e;
|
|
color: #00ff00;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 12px;
|
|
height: 300px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.log-item {
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.log-item.error {
|
|
color: #ff6b6b;
|
|
}
|
|
|
|
.log-item.success {
|
|
color: #51cf66;
|
|
}
|
|
|
|
.log-item.info {
|
|
color: #339af0;
|
|
}
|
|
|
|
.my-bets {
|
|
max-height: 400px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.bet-item {
|
|
padding: 10px;
|
|
background: #f9f9f9;
|
|
border-radius: 5px;
|
|
margin-bottom: 10px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.bet-item.win {
|
|
background: #d3f9d8;
|
|
border-left: 4px solid #51cf66;
|
|
}
|
|
|
|
.bet-item.lose {
|
|
background: #ffe0e0;
|
|
border-left: 4px solid #ff6b6b;
|
|
}
|
|
|
|
.bet-item.pending {
|
|
background: #fff3bf;
|
|
border-left: 4px solid #ffd43b;
|
|
}
|
|
|
|
.toast {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
background: white;
|
|
padding: 15px 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
|
|
z-index: 1000;
|
|
animation: slideIn 0.3s ease;
|
|
}
|
|
|
|
@keyframes slideIn {
|
|
from {
|
|
transform: translateX(400px);
|
|
opacity: 0;
|
|
}
|
|
to {
|
|
transform: translateX(0);
|
|
opacity: 1;
|
|
}
|
|
}
|
|
|
|
.toast.success {
|
|
border-left: 4px solid #51cf66;
|
|
}
|
|
|
|
.toast.error {
|
|
border-left: 4px solid #ff6b6b;
|
|
}
|
|
|
|
.ws-status {
|
|
display: inline-block;
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.ws-status.connected {
|
|
background: #d3f9d8;
|
|
color: #2b8a3e;
|
|
}
|
|
|
|
.ws-status.disconnected {
|
|
background: #ffe0e0;
|
|
color: #c92a2a;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<!-- 顶部状态栏 -->
|
|
<div class="header">
|
|
<h1>🎲 Xóc Đĩa 游戏测试页面</h1>
|
|
<p style="color: #666; margin-top: 5px;">前端 API 集成测试 - 房间 #1</p>
|
|
<div class="status">
|
|
<div class="status-item">
|
|
<label>WebSocket 状态</label>
|
|
<div class="value">
|
|
<span class="ws-status disconnected" id="ws-status">未连接</span>
|
|
</div>
|
|
</div>
|
|
<div class="status-item">
|
|
<label>当前期号</label>
|
|
<div class="value" id="period-number">-</div>
|
|
</div>
|
|
<div class="status-item">
|
|
<label>游戏状态</label>
|
|
<div class="value" id="game-state">等待中</div>
|
|
</div>
|
|
<div class="status-item">
|
|
<label>用户余额</label>
|
|
<div class="value" id="balance" style="color: #667eea;">-</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 游戏区域 -->
|
|
<div class="game-area">
|
|
<!-- 左侧:开奖结果 -->
|
|
<div class="card">
|
|
<h2>📊 开奖结果</h2>
|
|
|
|
<div class="countdown" id="countdown">00</div>
|
|
|
|
<div class="result-display" id="result-display">
|
|
<div class="coin white">●</div>
|
|
<div class="coin white">●</div>
|
|
<div class="coin white">●</div>
|
|
<div class="coin white">●</div>
|
|
</div>
|
|
<div class="result-text" id="result-text">等待开奖...</div>
|
|
|
|
<h3 style="margin-top: 20px; margin-bottom: 10px;">我的投注</h3>
|
|
<div class="my-bets" id="my-bets">
|
|
<p style="text-align: center; color: #999;">暂无投注</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 右侧:投注区域 -->
|
|
<div class="card">
|
|
<h2>💰 投注区域</h2>
|
|
|
|
<div class="betting-area" id="betting-area">
|
|
<div class="bet-button" data-type="even">
|
|
<div class="bet-name">双 (Chẵn)</div>
|
|
<div class="bet-odds">赔率 1:1.0</div>
|
|
</div>
|
|
<div class="bet-button" data-type="odd">
|
|
<div class="bet-name">单 (Lẻ)</div>
|
|
<div class="bet-odds">赔率 1:1.0</div>
|
|
</div>
|
|
<div class="bet-button" data-type="four_red">
|
|
<div class="bet-name">4 红</div>
|
|
<div class="bet-odds">赔率 1:10.0</div>
|
|
</div>
|
|
<div class="bet-button" data-type="four_white">
|
|
<div class="bet-name">4 白</div>
|
|
<div class="bet-odds">赔率 1:10.0</div>
|
|
</div>
|
|
<div class="bet-button" data-type="three_red">
|
|
<div class="bet-name">3 红 1 白</div>
|
|
<div class="bet-odds">赔率 1:3.5</div>
|
|
</div>
|
|
<div class="bet-button" data-type="three_white">
|
|
<div class="bet-name">1 红 3 白</div>
|
|
<div class="bet-odds">赔率 1:3.5</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bet-amount-input">
|
|
<label style="display: block; margin-bottom: 5px; color: #666;">投注金额</label>
|
|
<input type="number" id="bet-amount" placeholder="请输入金额" value="100" min="10">
|
|
</div>
|
|
|
|
<div class="quick-amounts">
|
|
<div class="quick-amount" data-amount="100">100</div>
|
|
<div class="quick-amount" data-amount="500">500</div>
|
|
<div class="quick-amount" data-amount="1000">1000</div>
|
|
<div class="quick-amount" data-amount="5000">5000</div>
|
|
</div>
|
|
|
|
<button class="submit-bet" id="submit-bet" disabled>请选择投注项</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 日志区域 -->
|
|
<div class="card">
|
|
<h2>📝 WebSocket 日志</h2>
|
|
<div class="logs" id="logs">
|
|
<div class="log-item info">[INFO] 页面加载完成,等待连接...</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// ==================== 全局变量 ====================
|
|
let ws = null;
|
|
let currentPeriodId = null;
|
|
let selectedBetType = null;
|
|
let userBets = [];
|
|
let balance = 10000; // 模拟初始余额
|
|
let countdownInterval = null;
|
|
|
|
// ==================== WebSocket 连接 ====================
|
|
function connectWebSocket() {
|
|
// ⚠️ 修改为实际的 WebSocket 地址
|
|
const wsUrl = 'ws://localhost:8080/ws/xocdia'; // 请修改为实际地址
|
|
|
|
addLog('info', `[INFO] 正在连接 WebSocket: ${wsUrl}`);
|
|
|
|
ws = new WebSocket(wsUrl);
|
|
|
|
ws.onopen = () => {
|
|
addLog('success', '[SUCCESS] WebSocket 连接成功');
|
|
document.getElementById('ws-status').textContent = '已连接';
|
|
document.getElementById('ws-status').className = 'ws-status connected';
|
|
|
|
// 订阅房间
|
|
sendMessage({
|
|
action: 'SUBSCRIBE_ROOM',
|
|
data: { room_id: 1 }
|
|
});
|
|
|
|
// 获取当前游戏状态
|
|
sendMessage({
|
|
action: 'GET_GAME_STATE',
|
|
data: { room_id: 1 }
|
|
});
|
|
};
|
|
|
|
ws.onmessage = (event) => {
|
|
const message = JSON.parse(event.data);
|
|
addLog('info', `[RECV] ${message.event}: ${JSON.stringify(message.data).substring(0, 100)}...`);
|
|
handleServerEvent(message);
|
|
};
|
|
|
|
ws.onerror = (error) => {
|
|
addLog('error', `[ERROR] WebSocket 错误: ${error}`);
|
|
};
|
|
|
|
ws.onclose = () => {
|
|
addLog('error', '[ERROR] WebSocket 连接关闭,3秒后重连...');
|
|
document.getElementById('ws-status').textContent = '已断开';
|
|
document.getElementById('ws-status').className = 'ws-status disconnected';
|
|
|
|
setTimeout(connectWebSocket, 3000);
|
|
};
|
|
}
|
|
|
|
// ==================== 发送消息 ====================
|
|
function sendMessage(data) {
|
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
ws.send(JSON.stringify(data));
|
|
addLog('info', `[SEND] ${data.action}: ${JSON.stringify(data.data)}`);
|
|
} else {
|
|
addLog('error', '[ERROR] WebSocket 未连接');
|
|
}
|
|
}
|
|
|
|
// ==================== 处理服务器事件 ====================
|
|
function handleServerEvent(message) {
|
|
switch (message.event) {
|
|
case 'GAME_START':
|
|
handleGameStart(message.data);
|
|
break;
|
|
|
|
case 'COUNTDOWN_UPDATE':
|
|
handleCountdownUpdate(message.data);
|
|
break;
|
|
|
|
case 'BET_SUCCESS':
|
|
handleBetSuccess(message.data);
|
|
break;
|
|
|
|
case 'BETTING_CLOSED':
|
|
handleBettingClosed(message.data);
|
|
break;
|
|
|
|
case 'GAME_RESULT':
|
|
handleGameResult(message.data);
|
|
break;
|
|
|
|
case 'GAME_STATE':
|
|
handleGameState(message.data);
|
|
break;
|
|
|
|
case 'ERROR':
|
|
handleError(message.data);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// ==================== 游戏开始 ====================
|
|
function handleGameStart(data) {
|
|
currentPeriodId = data.period_id;
|
|
userBets = [];
|
|
|
|
document.getElementById('period-number').textContent = data.period_number;
|
|
document.getElementById('game-state').textContent = '下注中';
|
|
|
|
startCountdown(data.countdown);
|
|
enableBetting();
|
|
clearMyBets();
|
|
|
|
showToast('新期号开始,快来下注吧!', 'success');
|
|
}
|
|
|
|
// ==================== 倒计时更新 ====================
|
|
function handleCountdownUpdate(data) {
|
|
updateCountdown(data.remaining);
|
|
}
|
|
|
|
// ==================== 投注成功 ====================
|
|
function handleBetSuccess(data) {
|
|
balance = data.remaining_balance;
|
|
updateBalance();
|
|
|
|
userBets.push({
|
|
bet_type: data.bet_type,
|
|
bet_amount: data.bet_amount,
|
|
potential_win: data.potential_win,
|
|
status: 'pending'
|
|
});
|
|
|
|
renderMyBets();
|
|
showToast('投注成功!', 'success');
|
|
}
|
|
|
|
// ==================== 封盘 ====================
|
|
function handleBettingClosed(data) {
|
|
document.getElementById('game-state').textContent = '摇碟中';
|
|
disableBetting();
|
|
stopCountdown();
|
|
|
|
document.getElementById('countdown').textContent = '🎲';
|
|
showToast('封盘了,等待开奖...', 'info');
|
|
}
|
|
|
|
// ==================== 开奖结果 ====================
|
|
function handleGameResult(data) {
|
|
document.getElementById('game-state').textContent = '已开奖';
|
|
|
|
// 显示开奖结果
|
|
showResult(data.result);
|
|
|
|
// 更新余额
|
|
balance = data.settlement.new_balance;
|
|
updateBalance();
|
|
|
|
// 更新投注状态
|
|
data.settlement.your_bets.forEach(bet => {
|
|
const userBet = userBets.find(b => b.bet_type === bet.bet_type);
|
|
if (userBet) {
|
|
userBet.status = bet.status;
|
|
userBet.net_profit = bet.net_profit;
|
|
}
|
|
});
|
|
|
|
renderMyBets();
|
|
|
|
// 显示结果提示
|
|
const netProfit = data.settlement.net_profit;
|
|
if (netProfit > 0) {
|
|
showToast(`恭喜!赢了 ${netProfit} 元`, 'success');
|
|
} else if (netProfit < 0) {
|
|
showToast(`很遗憾,输了 ${Math.abs(netProfit)} 元`, 'error');
|
|
} else {
|
|
showToast('平局,退款', 'info');
|
|
}
|
|
}
|
|
|
|
// ==================== 游戏状态(恢复) ====================
|
|
function handleGameState(data) {
|
|
if (data.current_period) {
|
|
currentPeriodId = data.current_period.period_id;
|
|
document.getElementById('period-number').textContent = data.current_period.period_number;
|
|
document.getElementById('game-state').textContent = data.current_period.state;
|
|
|
|
if (data.current_period.state === 'betting') {
|
|
startCountdown(data.current_period.countdown);
|
|
enableBetting();
|
|
}
|
|
|
|
userBets = data.your_bets || [];
|
|
renderMyBets();
|
|
}
|
|
}
|
|
|
|
// ==================== 错误处理 ====================
|
|
function handleError(data) {
|
|
showToast(data.message, 'error');
|
|
}
|
|
|
|
// ==================== 投注操作 ====================
|
|
function placeBet() {
|
|
if (!selectedBetType) {
|
|
showToast('请选择投注项', 'error');
|
|
return;
|
|
}
|
|
|
|
const amount = parseFloat(document.getElementById('bet-amount').value);
|
|
|
|
if (amount < 10) {
|
|
showToast('最小投注 10 元', 'error');
|
|
return;
|
|
}
|
|
|
|
if (amount > balance) {
|
|
showToast('余额不足', 'error');
|
|
return;
|
|
}
|
|
|
|
sendMessage({
|
|
action: 'PLACE_BET',
|
|
data: {
|
|
room_id: 1,
|
|
period_id: currentPeriodId,
|
|
bet_type: selectedBetType,
|
|
bet_amount: amount,
|
|
client_timestamp: new Date().toISOString()
|
|
}
|
|
});
|
|
}
|
|
|
|
// ==================== UI 更新函数 ====================
|
|
function updateBalance() {
|
|
document.getElementById('balance').textContent = balance.toFixed(2);
|
|
}
|
|
|
|
function startCountdown(seconds) {
|
|
stopCountdown();
|
|
let remaining = seconds;
|
|
|
|
const countdownEl = document.getElementById('countdown');
|
|
countdownEl.textContent = remaining;
|
|
|
|
countdownInterval = setInterval(() => {
|
|
remaining--;
|
|
countdownEl.textContent = remaining;
|
|
|
|
if (remaining <= 5) {
|
|
countdownEl.classList.add('urgent');
|
|
} else {
|
|
countdownEl.classList.remove('urgent');
|
|
}
|
|
|
|
if (remaining <= 0) {
|
|
stopCountdown();
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
function stopCountdown() {
|
|
if (countdownInterval) {
|
|
clearInterval(countdownInterval);
|
|
countdownInterval = null;
|
|
}
|
|
}
|
|
|
|
function updateCountdown(remaining) {
|
|
document.getElementById('countdown').textContent = remaining;
|
|
|
|
if (remaining <= 5) {
|
|
document.getElementById('countdown').classList.add('urgent');
|
|
}
|
|
}
|
|
|
|
function showResult(result) {
|
|
const container = document.getElementById('result-display');
|
|
container.innerHTML = '';
|
|
|
|
result.coins.forEach(coin => {
|
|
const coinEl = document.createElement('div');
|
|
coinEl.className = coin === 1 ? 'coin red' : 'coin white';
|
|
coinEl.textContent = '●';
|
|
container.appendChild(coinEl);
|
|
});
|
|
|
|
document.getElementById('result-text').textContent = result.display_text || result.pattern;
|
|
}
|
|
|
|
function renderMyBets() {
|
|
const container = document.getElementById('my-bets');
|
|
|
|
if (userBets.length === 0) {
|
|
container.innerHTML = '<p style="text-align: center; color: #999;">暂无投注</p>';
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = userBets.map(bet => {
|
|
const statusClass = bet.status || 'pending';
|
|
const statusText = {
|
|
'pending': '等待开奖',
|
|
'win': `赢 ${bet.net_profit}`,
|
|
'lose': `输 ${bet.bet_amount}`,
|
|
'refund': '退款'
|
|
}[statusClass] || statusClass;
|
|
|
|
return `
|
|
<div class="bet-item ${statusClass}">
|
|
<div>
|
|
<strong>${getBetTypeLabel(bet.bet_type)}</strong>
|
|
<span style="margin-left: 10px; color: #666;">${bet.bet_amount} 元</span>
|
|
</div>
|
|
<div style="font-weight: bold;">${statusText}</div>
|
|
</div>
|
|
`;
|
|
}).join('');
|
|
}
|
|
|
|
function clearMyBets() {
|
|
userBets = [];
|
|
renderMyBets();
|
|
}
|
|
|
|
function enableBetting() {
|
|
document.getElementById('submit-bet').disabled = false;
|
|
document.querySelectorAll('.bet-button').forEach(btn => {
|
|
btn.style.opacity = '1';
|
|
btn.style.pointerEvents = 'auto';
|
|
});
|
|
}
|
|
|
|
function disableBetting() {
|
|
document.getElementById('submit-bet').disabled = true;
|
|
document.querySelectorAll('.bet-button').forEach(btn => {
|
|
btn.style.opacity = '0.5';
|
|
btn.style.pointerEvents = 'none';
|
|
});
|
|
}
|
|
|
|
function getBetTypeLabel(type) {
|
|
const labels = {
|
|
'even': '双 (Chẵn)',
|
|
'odd': '单 (Lẻ)',
|
|
'four_red': '4红',
|
|
'four_white': '4白',
|
|
'three_red': '3红1白',
|
|
'three_white': '1红3白'
|
|
};
|
|
return labels[type] || type;
|
|
}
|
|
|
|
// ==================== 日志和提示 ====================
|
|
function addLog(type, message) {
|
|
const logsContainer = document.getElementById('logs');
|
|
const logItem = document.createElement('div');
|
|
logItem.className = `log-item ${type}`;
|
|
logItem.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
|
logsContainer.appendChild(logItem);
|
|
logsContainer.scrollTop = logsContainer.scrollHeight;
|
|
}
|
|
|
|
function showToast(message, type) {
|
|
const toast = document.createElement('div');
|
|
toast.className = `toast ${type}`;
|
|
toast.textContent = message;
|
|
document.body.appendChild(toast);
|
|
|
|
setTimeout(() => {
|
|
toast.remove();
|
|
}, 3000);
|
|
}
|
|
|
|
// ==================== 事件绑定 ====================
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// 初始化余额
|
|
updateBalance();
|
|
|
|
// 连接 WebSocket
|
|
connectWebSocket();
|
|
|
|
// 投注项选择
|
|
document.querySelectorAll('.bet-button').forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
document.querySelectorAll('.bet-button').forEach(btn => {
|
|
btn.classList.remove('active');
|
|
});
|
|
|
|
button.classList.add('active');
|
|
selectedBetType = button.dataset.type;
|
|
|
|
document.getElementById('submit-bet').textContent = `投注 ${getBetTypeLabel(selectedBetType)}`;
|
|
document.getElementById('submit-bet').disabled = false;
|
|
});
|
|
});
|
|
|
|
// 快捷金额
|
|
document.querySelectorAll('.quick-amount').forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
document.getElementById('bet-amount').value = button.dataset.amount;
|
|
});
|
|
});
|
|
|
|
// 提交投注
|
|
document.getElementById('submit-bet').addEventListener('click', placeBet);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|