feat: 接入我创建的挑战列表接口
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { _decorator, Node, Button } from 'cc';
|
||||
import { BaseView } from 'db://assets/scripts/core/BaseView';
|
||||
import { ViewManager } from 'db://assets/scripts/core/ViewManager';
|
||||
import { CreatedShareItem } from 'db://assets/scripts/types/ApiTypes';
|
||||
import { ShareManager } from 'db://assets/scripts/utils/ShareManager';
|
||||
import { ToastManager } from 'db://assets/scripts/utils/ToastManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PagePKData')
|
||||
@@ -8,6 +11,9 @@ export class PagePKData extends BaseView {
|
||||
@property({ type: Node, tooltip: '返回按钮' })
|
||||
backBtn: Node | null = null;
|
||||
|
||||
private _createdShares: CreatedShareItem[] = [];
|
||||
private _isLoading: boolean = false;
|
||||
|
||||
onViewLoad(): void {
|
||||
if (this.backBtn) {
|
||||
this.backBtn.on(Button.EventType.CLICK, this._onBackClick, this);
|
||||
@@ -15,6 +21,7 @@ export class PagePKData extends BaseView {
|
||||
}
|
||||
|
||||
onViewShow(): void {
|
||||
void this._loadCreatedShares();
|
||||
}
|
||||
|
||||
onViewHide(): void {
|
||||
@@ -24,6 +31,26 @@ export class PagePKData extends BaseView {
|
||||
ViewManager.instance.back();
|
||||
}
|
||||
|
||||
private async _loadCreatedShares(): Promise<void> {
|
||||
if (this._isLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isLoading = true;
|
||||
try {
|
||||
const items = await ShareManager.instance.fetchCreatedShares();
|
||||
if (!items) {
|
||||
ToastManager.instance.show('获取挑战列表失败,请稍后重试');
|
||||
return;
|
||||
}
|
||||
|
||||
this._createdShares = items;
|
||||
console.log('[PagePKData] 我创建的挑战列表:', this._createdShares);
|
||||
} finally {
|
||||
this._isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
onViewDestroy(): void {
|
||||
if (this.backBtn) {
|
||||
this.backBtn.off(Button.EventType.CLICK, this._onBackClick, this);
|
||||
|
||||
@@ -20,6 +20,7 @@ export const API_ENDPOINTS = {
|
||||
GAME_CONFIGS: `${API_BASE}/game-configs`,
|
||||
/** 分享相关 */
|
||||
SHARE_CREATE: `${API_BASE}/share`,
|
||||
SHARE_CREATED: `${API_BASE}/share/created`,
|
||||
SHARE_PROGRESS: `${API_BASE}/share/progress`,
|
||||
/** 用户信息 */
|
||||
USER_INFO: `${API_BASE}/user/info`,
|
||||
|
||||
@@ -97,9 +97,9 @@ export interface ShareLevelData {
|
||||
level: number;
|
||||
imageUrl: string;
|
||||
answer: string;
|
||||
hint1: string;
|
||||
hint2: string;
|
||||
hint3: string;
|
||||
hint1: string | null;
|
||||
hint2: string | null;
|
||||
hint3: string | null;
|
||||
sortOrder: number;
|
||||
}
|
||||
|
||||
@@ -116,3 +116,19 @@ export interface ReportProgressData {
|
||||
timeLimit: number | null;
|
||||
withinTimeLimit: boolean;
|
||||
}
|
||||
|
||||
/** 我创建的分享挑战条目 */
|
||||
export interface CreatedShareItem {
|
||||
id: string;
|
||||
shareCode: string;
|
||||
title: string;
|
||||
levelCount: number;
|
||||
participantCount: number;
|
||||
userRank: number | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
/** 我创建的分享挑战列表响应 */
|
||||
export interface CreatedShareListData {
|
||||
items: CreatedShareItem[];
|
||||
}
|
||||
|
||||
@@ -2,7 +2,15 @@ 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, ReportProgressData, ShareLevelData } from '../types/ApiTypes';
|
||||
import {
|
||||
ApiEnvelope,
|
||||
CreateShareData,
|
||||
JoinShareData,
|
||||
ReportProgressData,
|
||||
ShareLevelData,
|
||||
CreatedShareItem,
|
||||
CreatedShareListData,
|
||||
} from '../types/ApiTypes';
|
||||
import { RuntimeLevelConfig } from '../types/LevelTypes';
|
||||
|
||||
/**
|
||||
@@ -20,6 +28,7 @@ export class ShareManager {
|
||||
|
||||
private _shareTitle: string = '';
|
||||
private _shareCode: string | null = null;
|
||||
private _createdShares: CreatedShareItem[] = [];
|
||||
|
||||
/** 图片缓存:URL -> SpriteFrame */
|
||||
private _imageCache: Map<string, SpriteFrame> = new Map();
|
||||
@@ -37,6 +46,10 @@ export class ShareManager {
|
||||
return this._shareLevels !== null && this._shareLevels.length > 0;
|
||||
}
|
||||
|
||||
get createdShares(): CreatedShareItem[] {
|
||||
return [...this._createdShares];
|
||||
}
|
||||
|
||||
async createShare(title: string, levelIds: string[]): Promise<string | null> {
|
||||
try {
|
||||
const response = await HttpUtil.post<ApiEnvelope<CreateShareData>>(
|
||||
@@ -83,6 +96,7 @@ export class ShareManager {
|
||||
clue2: level.hint2,
|
||||
clue3: level.hint3,
|
||||
answer: level.answer,
|
||||
completed: false,
|
||||
}));
|
||||
|
||||
// 预加载首关图片
|
||||
@@ -102,6 +116,27 @@ export class ShareManager {
|
||||
}
|
||||
}
|
||||
|
||||
async fetchCreatedShares(): Promise<CreatedShareItem[] | null> {
|
||||
try {
|
||||
const response = await HttpUtil.get<ApiEnvelope<CreatedShareListData>>(
|
||||
API_ENDPOINTS.SHARE_CREATED,
|
||||
API_TIMEOUT.DEFAULT,
|
||||
);
|
||||
|
||||
if (!response.success || !response.data) {
|
||||
console.error('[ShareManager] 获取我创建的挑战列表失败:', response.message);
|
||||
return null;
|
||||
}
|
||||
|
||||
this._createdShares = response.data.items ?? [];
|
||||
console.log(`[ShareManager] 获取我创建的挑战列表成功: ${this._createdShares.length} 条`);
|
||||
return this.createdShares;
|
||||
} catch (err) {
|
||||
console.error('[ShareManager] 获取我创建的挑战列表异常:', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async ensureShareLevelReady(index: number): Promise<RuntimeLevelConfig | null> {
|
||||
if (!this._shareLevels || index < 0 || index >= this._shareLevels.length) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user