feat: 进入关卡时 toast 提示体力消耗,修复 StorageManager 接口位置和 WxSDK 访问级别
- 进入关卡成功后显示 toast 提示消耗体力及剩余体力 - 将 StorageManager 中 UserInfo 接口移至模块顶层,修复嵌套接口语法问题 - WxSDK.getWx() 改为 static 公开方法,便于外部调用
This commit is contained in:
@@ -15,8 +15,6 @@ export class AuthManager {
|
||||
private _isLoggedIn: boolean = false;
|
||||
/** 服务端返回的已完成关卡 ID(登录后暂存,等 LevelDataManager 就绪后同步) */
|
||||
private _completedLevelIds: string[] = [];
|
||||
/** 服务端返回的已完成关卡 ID(登录后暂存,等 LevelDataManager 就绪后同步) */
|
||||
private _completedLevelIds: string[] = [];
|
||||
|
||||
static get instance(): AuthManager {
|
||||
if (!this._instance) {
|
||||
@@ -88,12 +86,14 @@ export class AuthManager {
|
||||
|
||||
this._userId = user.id;
|
||||
this._isLoggedIn = true;
|
||||
StorageManager.setPoints(user.points);
|
||||
|
||||
// 获取通关进度
|
||||
await this.fetchCompletedLevels();
|
||||
// 登录响应中 stamina 是原始数值(不含实时恢复),先存储默认体力
|
||||
// 后续通过 game-data 接口获取完整 StaminaInfo
|
||||
console.log(`[AuthManager] 登录成功,用户: ${user.id},体力: ${user.stamina}`);
|
||||
|
||||
// 获取通关进度和完整体力信息
|
||||
await this.fetchGameData();
|
||||
|
||||
console.log(`[AuthManager] 登录成功,用户: ${user.id},积分: ${user.points}`);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('[AuthManager] 登录异常:', err);
|
||||
@@ -102,45 +102,42 @@ export class AuthManager {
|
||||
}
|
||||
|
||||
private async validateToken(): Promise<boolean> {
|
||||
try {
|
||||
const response = await HttpUtil.get<ApiEnvelope<GameData>>(
|
||||
API_ENDPOINTS.USER_GAME_DATA,
|
||||
API_TIMEOUT.SHORT
|
||||
);
|
||||
const gameData = await this._fetchGameData();
|
||||
if (!gameData) return false;
|
||||
|
||||
if (!response.success || !response.data) {
|
||||
return false;
|
||||
}
|
||||
this._userId = gameData.user.id;
|
||||
this._isLoggedIn = true;
|
||||
StorageManager.setStamina(gameData.user.stamina);
|
||||
this._completedLevelIds = gameData.completedLevelIds;
|
||||
|
||||
this._userId = response.data.user.id;
|
||||
this._isLoggedIn = true;
|
||||
StorageManager.setPoints(response.data.user.points);
|
||||
this._completedLevelIds = response.data.completedLevelIds;
|
||||
console.log(`[AuthManager] Token 验证成功,体力: ${gameData.user.stamina.current}/${gameData.user.stamina.max},已完成: ${this._completedLevelIds.length} 关`);
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log(`[AuthManager] Token 验证成功,积分: ${response.data.user.points},已完成: ${this._completedLevelIds.length} 关`);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
/**
|
||||
* 登录成功后获取游戏数据(体力 + 通关进度)
|
||||
*/
|
||||
private async fetchGameData(): Promise<void> {
|
||||
const gameData = await this._fetchGameData();
|
||||
if (gameData) {
|
||||
this._completedLevelIds = gameData.completedLevelIds;
|
||||
StorageManager.setStamina(gameData.user.stamina);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录成功后获取通关进度
|
||||
* 从服务端获取游戏数据(共用方法)
|
||||
*/
|
||||
private async fetchCompletedLevels(): Promise<void> {
|
||||
private async _fetchGameData(): Promise<GameData | null> {
|
||||
try {
|
||||
const response = await HttpUtil.get<ApiEnvelope<GameData>>(
|
||||
API_ENDPOINTS.USER_GAME_DATA,
|
||||
API_TIMEOUT.SHORT
|
||||
);
|
||||
|
||||
if (response.success && response.data) {
|
||||
this._completedLevelIds = response.data.completedLevelIds;
|
||||
// 同步最新积分
|
||||
StorageManager.setPoints(response.data.user.points);
|
||||
}
|
||||
return (response.success && response.data) ? response.data : null;
|
||||
} catch {
|
||||
console.warn('[AuthManager] 获取通关进度失败');
|
||||
console.warn('[AuthManager] 获取游戏数据失败');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user