feat: 优化任务进度获取与聚合逻辑,并为扫雷游戏添加 gameToken 状态管理

This commit is contained in:
邹方成 2026-01-04 12:13:04 +08:00
parent 0f7255783a
commit 1d1c4f29d6
2 changed files with 29 additions and 22 deletions

View File

@ -310,6 +310,7 @@ export default {
isConnected: false,
isMatching: false,
matchId: null,
gameToken: null,
myUserId: null,
floatingLabels: [],
showGuide: false,
@ -471,6 +472,7 @@ export default {
const serverUrl = server || 'wss://game.1024tool.vip';
const serverKey = key || 'defaultkey';
nakamaManager.initClient(serverUrl, serverKey);
this.gameToken = token;
const session = await nakamaManager.authenticateWithGameToken(token);
this.myUserId = session.user_id;
this.isConnected = true;

View File

@ -371,36 +371,41 @@ async function fetchData() {
expandedTasks[list[0].id] = true
}
// ()
//
if (list.length > 0) {
try {
const progressRes = await getTaskProgress(list[0].id, userId)
userProgress.orderCount = progressRes.order_count || 0
userProgress.orderAmount = progressRes.order_amount || 0
userProgress.inviteCount = progressRes.invite_count || 0
userProgress.firstOrder = progressRes.first_order || false
//
if (progressRes.claimed_tiers) {
userProgress.claimedTiers[list[0].id] = progressRes.claimed_tiers
}
} catch (e) {
console.error('获取进度失败:', e)
}
//
const otherTasks = list.slice(1)
const progressPromises = otherTasks.map(t =>
getTaskProgress(t.id, userId).catch(() => null)
//
userProgress.orderCount = 0
userProgress.orderAmount = 0
userProgress.inviteCount = 0
userProgress.firstOrder = false
userProgress.claimedTiers = {}
//
const progressPromises = list.map(t =>
getTaskProgress(t.id, userId).catch(err => {
console.warn(`[Tasks] 获取任务 ${t.id} 进度失败:`, err)
return null
})
)
const progressResults = await Promise.allSettled(progressPromises)
progressResults.forEach((result, index) => {
if (result.status === 'fulfilled' && result.value) {
const taskId = otherTasks[index].id
userProgress.claimedTiers[taskId] = result.value.claimed_tiers || []
const p = result.value
const taskId = list[index].id
// ()
userProgress.orderCount = Math.max(userProgress.orderCount, p.order_count || 0)
userProgress.orderAmount = Math.max(userProgress.orderAmount, p.order_amount || 0)
userProgress.inviteCount = Math.max(userProgress.inviteCount, p.invite_count || 0)
if (p.first_order) userProgress.firstOrder = true
//
userProgress.claimedTiers[taskId] = p.claimed_tiers || []
}
})
console.log('[Tasks] 汇总后的进度数据:', userProgress)
}
} catch (e) {
console.error('获取任务失败:', e)