feat: 优化任务进度获取与聚合逻辑,并为扫雷游戏添加 gameToken 状态管理
This commit is contained in:
parent
0f7255783a
commit
1d1c4f29d6
@ -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;
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user