feat: 支持分享关卡通关上报
This commit is contained in:
@@ -688,12 +688,15 @@ export class PageLevel extends BaseView {
|
||||
// 播放成功音效
|
||||
this.playSuccessSound();
|
||||
|
||||
// 通关奖励:分享模式下不增加积分
|
||||
const levelId = this._currentConfig?.id ?? '';
|
||||
const timeSpent = 60 - this._countdown;
|
||||
|
||||
if (!this._isShareMode) {
|
||||
const levelId = this._currentConfig?.id ?? '';
|
||||
const timeSpent = 60 - this._countdown;
|
||||
await UserAssetsManager.instance.earnPoint(levelId, timeSpent);
|
||||
this.updatePointsLabel();
|
||||
} else {
|
||||
// fire-and-forget: errors are logged inside reportLevelProgress
|
||||
void ShareManager.instance.reportLevelProgress(levelId, true, timeSpent);
|
||||
}
|
||||
|
||||
// 显示通关弹窗
|
||||
|
||||
@@ -15,6 +15,7 @@ export const API_ENDPOINTS = {
|
||||
USER_GAME_DATA: `${API_BASE}/user/game-data`,
|
||||
LEVELS: `${API_BASE}/wechat-game/levels`,
|
||||
SHARE_CREATE: `${API_BASE}/share`,
|
||||
SHARE_PROGRESS: `${API_BASE}/share/progress`,
|
||||
USER_INFO: `${API_BASE}/user/info`,
|
||||
} as const;
|
||||
|
||||
|
||||
@@ -55,3 +55,10 @@ export interface JoinShareData {
|
||||
title: string;
|
||||
levels: ShareLevelData[];
|
||||
}
|
||||
|
||||
/** 上报关卡进度响应 */
|
||||
export interface ReportProgressData {
|
||||
passed: boolean;
|
||||
timeLimit: number | null;
|
||||
withinTimeLimit: boolean;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ 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 { ApiEnvelope, CreateShareData, JoinShareData, ShareLevelData } from '../types/ApiTypes';
|
||||
import { ApiEnvelope, CreateShareData, JoinShareData, ReportProgressData, ShareLevelData } from '../types/ApiTypes';
|
||||
import { RuntimeLevelConfig } from '../types/LevelTypes';
|
||||
|
||||
/**
|
||||
@@ -127,6 +127,44 @@ 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> {
|
||||
if (!this._shareCode) {
|
||||
console.warn('[ShareManager] reportLevelProgress: 无分享码,跳过上报');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await HttpUtil.post<ApiEnvelope<ReportProgressData>>(
|
||||
API_ENDPOINTS.SHARE_PROGRESS,
|
||||
{ shareCode: this._shareCode, levelId, passed, timeSpent },
|
||||
API_TIMEOUT.DEFAULT,
|
||||
);
|
||||
|
||||
if (!response.success || !response.data) {
|
||||
console.error('[ShareManager] 上报进度失败:', response.message);
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[ShareManager] 上报成功: passed=${response.data.passed}, withinTimeLimit=${response.data.withinTimeLimit}`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
console.error('[ShareManager] 上报进度异常:', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
triggerWxShare(title: string, shareCode: string): void {
|
||||
WxSDK.shareAppMessage({
|
||||
title: title || '来挑战我出的谐音梗吧!',
|
||||
|
||||
Reference in New Issue
Block a user