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

View File

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