import PlatformData from "../Data/PlatformData"; import { Recommend } from "./Recommend"; export class WXRecommend extends Recommend{ private _base = null; private recommendPageManager; private mPlatformData: PlatformData; private isInit: boolean = false; private _showCallBack:Function; private _DestroyCallBack:Function; get InitComplete(){ return this.isInit; } init(platformData: PlatformData) { this.mPlatformData = platformData; this._base = window["wx"]; //测试链接 //this.mPlatformData.openlink = `TWFRCqV5WeM2AkMXhKwJ03MhfPOieJfAsvXKUbWvQFQtLyyA5etMPabBehga950uzfZcH3Vi3QeEh41xRGEVFw`; if(!platformData.RecomOpenlink || !platformData.RecomOpenlink.length){ ConsoleEx.Error("推荐功能未启用!") return; } this.loadRecommend(); } async show(callBack: Function) { if (!this.isInit) { callBack(false); console.warn("推荐功能还未初始化完成!") return; } this._DestroyCallBack = callBack; this.recommendPageManager.show(); } /**游戏内提前加载推荐组件数据 */ async loadRecommend() { if (!this._base.createPageManager) { throw '当前基础库版本暂不支持。'; } this.recommendPageManager = this._base.createPageManager(); this.recommendPageManager.on( 'show', // show | destroy | error () => { this._showCallBack && this._showCallBack(); console.log('recommend component show.'); }, ) this.recommendPageManager.on( 'error', // show | destroy | error (res) => { console.error('recommend component error.',res); }, ) this.recommendPageManager.on( 'destroy', // show | destroy | error (res) => { console.log('recommend component destroy:', res); this._DestroyCallBack && this._DestroyCallBack(res.isRecommended); }, ) this.recommendPageManager.load({ openlink: this.mPlatformData.RecomOpenlink, // 由不同渠道获得的OPENLINK值 }).then((res) => { // 加载成功,res 可能携带不同活动、功能返回的特殊回包信息(具体请参阅渠道说明) console.log("推荐功能加载成功", res); this.isInit = true; }).catch((err) => { // 加载失败,请查阅 err 给出的错误信息 console.error("推荐功能错误:", err); }) } }