优化总点数显示逻辑,调整初始值为null并从API获取真实数据,改进游戏界面状态处理,提升用户体验
This commit is contained in:
@@ -23,7 +23,7 @@ export function usePlayState() {
|
||||
qrInfo: null,
|
||||
assets: null,
|
||||
currentPoints: 0,
|
||||
totalPoints: 1000,
|
||||
totalPoints: null, // 修改:初始值改为null,等待从API获取真实数据
|
||||
completedPoints: 0,
|
||||
progressDisplayFormat: '1',
|
||||
error: null,
|
||||
@@ -57,6 +57,32 @@ export function usePlayState() {
|
||||
const response = await getLinkStatus(state.code)
|
||||
const data = response.data
|
||||
await updateStateFromResponse(data)
|
||||
|
||||
// 如果是NEW状态,尝试获取游戏界面数据以获取totalPoints
|
||||
if (data.status === 'NEW') {
|
||||
try {
|
||||
const gameResponse = await getGameInterfaceAPI(state.code)
|
||||
const gameData = gameResponse.data
|
||||
console.log('NEW状态 - 游戏界面数据:', gameData)
|
||||
|
||||
// 更新totalPoints和其他可用数据
|
||||
if (gameData.totalPoints !== undefined && gameData.totalPoints !== null) {
|
||||
state.totalPoints = gameData.totalPoints
|
||||
console.log('从游戏界面获取到totalPoints:', state.totalPoints)
|
||||
}
|
||||
|
||||
if (gameData.completedPoints !== undefined) {
|
||||
state.completedPoints = gameData.completedPoints
|
||||
}
|
||||
|
||||
if (gameData.progressDisplayFormat) {
|
||||
state.progressDisplayFormat = String(gameData.progressDisplayFormat)
|
||||
}
|
||||
} catch (gameError) {
|
||||
// 游戏界面数据获取失败不影响主流程,只记录日志
|
||||
console.log('NEW状态获取游戏界面数据失败(这是正常的):', gameError.message)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
@@ -239,7 +265,8 @@ export function usePlayState() {
|
||||
state.qrExpireAt = data.qrExpireAt
|
||||
}
|
||||
|
||||
if (data.totalPoints) {
|
||||
// 优先使用 data.totalPoints,确保在NEW状态也能获取到目标点数
|
||||
if (data.totalPoints !== undefined && data.totalPoints !== null) {
|
||||
state.totalPoints = data.totalPoints
|
||||
}
|
||||
|
||||
@@ -251,7 +278,8 @@ export function usePlayState() {
|
||||
state.progressDisplayFormat = String(data.progressDisplayFormat)
|
||||
}
|
||||
|
||||
if (data.assets && data.assets.totalPoints) {
|
||||
// 如果assets中有totalPoints,也更新
|
||||
if (data.assets && data.assets.totalPoints !== undefined && data.assets.totalPoints !== null) {
|
||||
state.totalPoints = data.assets.totalPoints
|
||||
if (state.currentPoints === undefined) {
|
||||
state.currentPoints = 0
|
||||
@@ -263,7 +291,8 @@ export function usePlayState() {
|
||||
dataRegion: data.region,
|
||||
stateRegion: state.region,
|
||||
mecmachineId: data.mecmachineId,
|
||||
totalPoints: state.totalPoints,
|
||||
dataTotalPoints: data.totalPoints,
|
||||
stateTotalPoints: state.totalPoints,
|
||||
completedPoints: state.completedPoints,
|
||||
skipQrProcessing
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user