feat: 完善分享模式
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import { SpriteFrame, Texture2D, ImageAsset, assetManager } from 'cc';
|
||||
import { HttpUtil } from './HttpUtil';
|
||||
import { WxSDK } from './WxSDK';
|
||||
import { API_ENDPOINTS, getShareJoinUrl, API_TIMEOUT } from '../config/ApiConfig';
|
||||
import { API_ENDPOINTS, getShareJoinUrl, getShareSubmitUrl, API_TIMEOUT } from '../config/ApiConfig';
|
||||
import {
|
||||
ApiEnvelope,
|
||||
CreateShareData,
|
||||
JoinShareData,
|
||||
ReportProgressData,
|
||||
ShareLevelData,
|
||||
CreatedShareItem,
|
||||
CreatedShareListData,
|
||||
SubmitShareData,
|
||||
SubmitShareLevel,
|
||||
} from '../types/ApiTypes';
|
||||
import { RuntimeLevelConfig } from '../types/LevelTypes';
|
||||
|
||||
@@ -50,6 +51,14 @@ export class ShareManager {
|
||||
return [...this._createdShares];
|
||||
}
|
||||
|
||||
get shareCode(): string | null {
|
||||
return this._shareCode;
|
||||
}
|
||||
|
||||
get shareTitle(): string {
|
||||
return this._shareTitle;
|
||||
}
|
||||
|
||||
async createShare(title: string, levelIds: string[]): Promise<string | null> {
|
||||
try {
|
||||
const response = await HttpUtil.post<ApiEnvelope<CreateShareData>>(
|
||||
@@ -101,6 +110,7 @@ export class ShareManager {
|
||||
clue3: level.hint3,
|
||||
answer: level.answer,
|
||||
completed: false,
|
||||
timeLimit: null,
|
||||
}));
|
||||
|
||||
// 预加载首关图片(两张并行加载)
|
||||
@@ -178,40 +188,34 @@ export class ShareManager {
|
||||
return this._shareLevels?.length ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报单关通关进度
|
||||
* @param levelId 关卡 ID
|
||||
* @param passed 是否通过
|
||||
* @param timeSpent 用时(秒)
|
||||
*/
|
||||
async reportLevelProgress(
|
||||
levelId: string,
|
||||
passed: boolean,
|
||||
timeSpent: number,
|
||||
): Promise<ReportProgressData | null> {
|
||||
getShareLevelIds(): string[] {
|
||||
return this._shareApiLevels.map(level => level.id);
|
||||
}
|
||||
|
||||
async submitShareChallenge(levels: SubmitShareLevel[]): Promise<SubmitShareData | null> {
|
||||
if (!this._shareCode) {
|
||||
console.warn('[ShareManager] reportLevelProgress: 无分享码,跳过上报');
|
||||
console.warn('[ShareManager] submitShareChallenge: 无分享码,跳过提交');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await HttpUtil.post<ApiEnvelope<ReportProgressData>>(
|
||||
API_ENDPOINTS.SHARE_PROGRESS,
|
||||
{ shareCode: this._shareCode, levelId, passed, timeSpent },
|
||||
const response = await HttpUtil.post<ApiEnvelope<SubmitShareData>>(
|
||||
getShareSubmitUrl(this._shareCode),
|
||||
{ levels },
|
||||
API_TIMEOUT.DEFAULT,
|
||||
);
|
||||
|
||||
if (!response.success || !response.data) {
|
||||
console.error('[ShareManager] 上报进度失败:', response.message);
|
||||
console.error('[ShareManager] 提交挑战结果失败:', response.message);
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[ShareManager] 上报成功: passed=${response.data.passed}, withinTimeLimit=${response.data.withinTimeLimit}`,
|
||||
`[ShareManager] 提交挑战结果成功: rank=${response.data.rank}, correct=${response.data.correctCount}/${response.data.levelCount}`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
console.error('[ShareManager] 上报进度异常:', err);
|
||||
console.error('[ShareManager] 提交挑战结果异常:', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user