import { Node, UIOpacity, _decorator, tween } from 'cc'; import BaseAppInit from '../../../extensions/app/assets/base/BaseAppInit'; import { LOGIN_TOKEN } from '../../res-native/network/HttpRequest'; import { Tools } from '../../res-native/tools/Tools'; import { app } from '../../app/app'; import { USERDATA } from '../../res-native/data/UserData'; import { LANG_SET, LANG_STRING, LangSet } from '../../res-native/setting/LangSet'; const { ccclass, property } = _decorator; @ccclass('AppInit') export class AppInit extends BaseAppInit { @property(Node) private logo: Node; /** * 获得用户资源总量,这里返回几,就需要用户自行调用几次nextInit */ protected getUserAssetNum(): number { return 1; } protected onLoad() { this.initToken(); if (LOGIN_TOKEN.access_token == "" || LOGIN_TOKEN.access_token == undefined) { //app.manager.ui.showToast("token init failed") return } Tools.httpReq("user/info", {}, (res:any) => { USERDATA.setUserData(res); this.nextInit(); }) // // 执行初始化操作 // const opacity = this.logo.getComponent(UIOpacity); // opacity.opacity = 0; // tween(opacity) // .to(0.5, { opacity: 255 }) // .delay(1) // .to(0.5, { opacity: 0 }) // .call(() => { // Tools.httpReq("prize-list", {}, (res:any) => { // USERDATA.setUserData(res); // this.nextInit(); // }) // }) // .start(); // Tools.httpReq("user/Login", { // username: "+60123456789", // password: "123456", // coin: 2000, // time: 1772692089 // }, (res:any) => { // LOGIN_TOKEN.setToken(res.token, res.token, "", "") // Tools.httpReq("user/info", {}, (res:any) => { // USERDATA.setUserData(res); // this.nextInit(); // }) // }) } /** 根据参数初始化TOKEN */ initToken(){ let str = window.location.search.slice(1) const pairs = str.split('&'); const params: { [key: string]: string } = {}; pairs.forEach(pair => { const [key, value] = pair.split('='); params[decodeURIComponent(key)] = decodeURIComponent(value || ''); }); // const at = Tools.parseJWT(params.access_token) // const actualKey = 'xyxfz83d'.substring(0, 8); // 取前8个字符 // // 解密appkey // const appkey = Tools.desEcbDecrypt(at.extend.channel, actualKey); // // 如果解密失败,尝试原始值 // if (!appkey) { // console.log('Failed to decrypt token, using original value'); // } LOGIN_TOKEN.setToken(params.token, params.token, "", "") LANG_SET.langIndex = LANG_STRING[params.lang as keyof typeof LANG_STRING] } // BaseAppInit中使用start方法作为初始化入口,如果重写start方法,请注意调用父类方法 // protected start() { } protected onFinish() { // 执行完成操作 this.node.destroy(); } }