feat: 添加扫雷游戏在线人数显示及定时更新功能

This commit is contained in:
邹方成 2026-01-04 20:26:16 +08:00
parent 41ab104f83
commit 420912b3a7
2 changed files with 31 additions and 0 deletions

View File

@ -375,6 +375,16 @@
font-weight: 500; font-weight: 500;
} }
.online-number {
color: $accent-orange;
font-weight: 700;
font-size: 36rpx;
}
.online-count-row {
margin-top: $spacing-sm;
}
// 按钮使用全局定义 // 按钮使用全局定义
.start-btn { .start-btn {
width: 380rpx; width: 380rpx;

View File

@ -53,6 +53,10 @@
<text class="intro-icon">🏆</text> <text class="intro-icon">🏆</text>
<text class="intro-text">胜者赢取全额奖励</text> <text class="intro-text">胜者赢取全额奖励</text>
</view> </view>
<view class="intro-item online-count-row">
<text class="intro-icon">👥</text>
<text class="intro-text">当前在线: <text class="online-number">{{ onlineCount }}</text> </text>
</view>
</view> </view>
<view class="btn-primary start-btn" @tap="startMatchmaking"> <view class="btn-primary start-btn" @tap="startMatchmaking">
@ -329,6 +333,8 @@ export default {
showSettlement: false, showSettlement: false,
settlementWinnerId: '', settlementWinnerId: '',
showResultModal: false, showResultModal: false,
onlineCount: 0,
onlineCountInterval: null,
// Timers // Timers
matchInterval: null, matchInterval: null,
turnInterval: null, turnInterval: null,
@ -482,6 +488,10 @@ export default {
this.addLog('system', '✅ 已连接到远程节点'); this.addLog('system', '✅ 已连接到远程节点');
this.setupSocketListeners(); this.setupSocketListeners();
// 线
this.fetchOnlineCount();
this.onlineCountInterval = setInterval(() => this.fetchOnlineCount(), 10000);
// RPC // RPC
if (!this.matchId) { if (!this.matchId) {
try { try {
@ -862,8 +872,19 @@ export default {
cleanup() { cleanup() {
clearInterval(this.matchInterval); clearInterval(this.matchInterval);
clearInterval(this.turnInterval); clearInterval(this.turnInterval);
clearInterval(this.onlineCountInterval);
nakamaManager.disconnect(); nakamaManager.disconnect();
}, },
async fetchOnlineCount() {
try {
const result = await nakamaManager.rpc('get_online_count', {});
if (result && typeof result.online_count === 'number') {
this.onlineCount = result.online_count;
}
} catch (e) {
console.warn('获取在线人数失败:', e);
}
},
getItemIcon(itemId) { getItemIcon(itemId) {
const map = { medkit: '💊', bomb_timer: '⏰', poison: '☠️', shield: '🛡️', skip: '⏭️', magnifier: '🔍', knife: '🔪', revive: '💖', lightning: '⚡', chest: '📦', curse: '👻' }; const map = { medkit: '💊', bomb_timer: '⏰', poison: '☠️', shield: '🛡️', skip: '⏭️', magnifier: '🔍', knife: '🔪', revive: '💖', lightning: '⚡', chest: '📦', curse: '👻' };
return map[itemId] || '🎁'; return map[itemId] || '🎁';