import PoolMgr, { NODEPOOLPREFABTYPE } from "../../../before/mgr/PoolMgr"; import Util from "../../../before/util/Util"; import JsbSystem from "../../../mk/system/JsbSystem"; import { OpenActionType } from "../../../mk/system/UISystem"; import { UpdateState } from "../../data/AppData"; import { DataEventId } from "../../data/GameData"; import HotUpdatePanel from "../hotUpdate/HotUpdatePanel"; const { ccclass, property } = cc._decorator; @ccclass export default class Login extends cc.Component { @property(cc.Sprite) private bar: cc.Sprite = null; @property({ displayName: '更新文本', type: cc.Label }) private lbl_progress: cc.Label = null; @property({ displayName: '加载动画节点', type: cc.Node }) private node_load: cc.Node = null; @property({ displayName: '服务协议', type: cc.Label }) private lbl_server: cc.Label = null; @property({ displayName: '隐私协议', type: cc.Label }) private lbl_privacy: cc.Label = null; @property({ displayName: '加载部分', type: cc.Node }) private node_loadPart: cc.Node = null; @property({ displayName: '登录按钮', type: cc.Node }) private node_btnLogin: cc.Node = null; /** 加载进度 */ private process: number = 0; /** 热更脚本(onLoad应先于Login) */ public hotUpdatePanel: HotUpdatePanel = null; private hasDeviceBackInit = false; private hasLogin = false; private hasCheckPermission = false; private hasCheckPrivacy = false; private loadSceneState = false; private coreGame = null; private isLoadComplete = false; private hasCheckChannel = false; private initShuzilm = false; //debug使用 private initOrderInfo = false; onLoad() { this.lbl_progress.node.active = false; this.node_load.active = true; this.node_loadPart.active = true; this.node_btnLogin.active = false; this.setProgress(0); gData.loginData.loadLocalRes(); } async start() { if (mk.aliRiskManager.ifIsBlock()) { return; } if (CC_DEBUG) { mk.aliRiskManager.getRiskCode = true; mk.tongdunM.hasGot = true; mk.shuzilmM.hasGot = true; } else { mk.aliRiskManager.init(); } mk.tongdunM.tongdunInit(); this.loadMain(); let value = mk.storage.getStorage('loadingStart'); if (!value) { mk.storage.setStorage('loadingStart', 1); mk.data.sendDataEvent(DataEventId.loading, 'loading开始'); } } addTime = 0; update() { gData.loginData.curTime += 1; //隐私弹窗 if (!this.hasCheckPrivacy) { this.hasCheckPrivacy = true this.checkPrivacy() } if (!gData.loginData.passPrivacy) { return; } if (!this.hasCheckPermission) { this.hasCheckPermission = true; //获取手机授权 JsbSystem.checkPermission(); } if (!gData.appData.getDeviceInfoCompelete) { return } if (!this.hasDeviceBackInit) { this.hasDeviceBackInit = true; this.getAppVersion(); } //如果更新没有结束,就不进入正常加载流程 if (gData.appData.updateState == UpdateState.ForceUpdateFinish) { gData.appData.updateState = UpdateState.CheckHot; this.checkHotUpdate(); } if (gData.appData.updateState == UpdateState.IsUpdate) { this.lbl_progress.node.active = true; this.node_load.active = false; this.setProgress(gData.appData.updatePercent * 100); return; } if (gData.appData.updateState != UpdateState.UpdateFinish) { return; } if (this.addTime < 120) { this.addTime += 1; this.setProgress(this.addTime); } if (gData.loginData.loadResCompelete) { //数盟初始化 if (!this.initShuzilm) { console.log(`数盟初始化========${gData.loginData.curTime}`); this.initShuzilm = true; mk.shuzilmM.init(); return; } if (mk.shuzilmM.hasGot && mk.tongdunM.hasGot && mk.aliRiskManager.getRiskCode) { //开始登陆 if (!this.hasLogin) { this.hasLogin = true; console.log(`开始登陆========${gData.loginData.curTime}`); this.login(); } else if (gData.gameData.dataFinish) {//登录流程完毕 //微信登录按钮 注释 // if (gData.loginData.isAuth || CC_DEBUG) { // if (!this.loadSceneState) { // this.loadSceneState = true; // this.loadMain(); // } // } // else { // this.node_loadPart.active = false; // this.node_btnLogin.active = true; // } if (!CC_DEBUG) { //检查用户来源渠道 if (!this.hasCheckChannel) { console.log(`检查用户来源渠道========${gData.loginData.curTime}`); this.hasCheckChannel = true; gData.loginData.getUserChannel(); } if (!gData.loginData.passAnti) { return } } else { if (!this.initOrderInfo) { this.initOrderInfo = true; gData.adData.getOrderTaskInfo(1); } } if (this.isLoadComplete) { if (this.addTime >= 120) { this.addToScene(); this.isLoadComplete = false; } else { return; } } else { return; } gData.gameData.dataFinish = false; } } } } private async loadMain() { this.coreGame = await mk.loader.load('game/coregame/coregame', cc.Prefab); this.isLoadComplete = true; //this.addToScene(); } private addToScene() { let mainNode = cc.find('Canvas/主容器'); let node = cc.find('Canvas/主界面层'); mk.ui.openPanel("game/prefab/game", OpenActionType.closeOther, node); mainNode.addChild(cc.instantiate(this.coreGame)); } private checkPrivacy() { if (mk.storage.getStorage("agreementTip") != 1) { mk.ui.openPanel("module/login/agreementTip"); } else { gData.loginData.passPrivacy = true; } } /** 设置进度 */ private setProgress(current) { let cur = current / 120; if (this.bar) { if (cur > this.bar.fillRange) { this.bar.fillRange = cur; this.lbl_progress.string = "加载中 " + current + "%"; } } } /** 获取设备信息后 */ public async getAppVersion() { //获取appid 和 配置version JsbSystem.getWxAppId(); //获取登录需要的sessionkey gData.loginData.init(); await this.checkForceUpate(); this.checkRemoveLocalHot(); mk.audio.init(); } //整包更新和新流程-------------------------------------------------------- /** 新包覆盖安装后清除热更版本,重启 */ checkRemoveLocalHot() { let currentVersion = mk.storage.getStorage('currentVersion'); mk.storage.setStorage('currentVersion', gData.appData.appVersion); if (currentVersion) { let compareVer = Util.versionCompareHandle(currentVersion, gData.appData.appVersion) console.log('compareVer ', compareVer) if (compareVer < 0) { // 热更新的储存路径,如果旧版本中有多个,可能需要记录在列表中,全部清理 var storagePath = localStorage.getItem('HotUpdateSearchPaths'); if (storagePath) { let storageArr = JSON.parse(storagePath) let len = storageArr.length - 2 for (var i = 0; i < len; i++) { let path = storageArr.shift() jsb.fileUtils.removeDirectory(path); } cc.sys.localStorage.removeItem('HotUpdateSearchPaths'); jsb.fileUtils.setSearchPaths(storageArr); setTimeout(() => { cc.audioEngine.stopAll(); cc.game.restart(); }, 500); } } } } /** 检测强制更新 */ public async checkForceUpate() { await this.getForceVersionInfo(); if (gData.appData.needForceUpdate === 1) { mk.ui.openPanel('module/forceUpdate/forceUpdate'); } else { await this.checkHotUpdate(); } } //发送请求整包更新 public async getForceVersionInfo() { if (CC_DEBUG) { //测试用配置版本号 gData.appData.tfChannel = "1"; gData.appData.appVersion = "1.1.9"; } let data: any = { appId: gData.appData.appId, channel: gData.appData.tfChannel, version: gData.appData.appVersion } mk.console.logSingle('getForceVersionInfo ', data); let response = await mk.http.sendRequest("getForceVersionInfo", 'POST', JSON.stringify(data), false, false) if (response.data) { gData.appData.needForceUpdate = response.data.isForceUpdate; gData.appData.installVersion = response.data.version; gData.appData.installUrl = response.data.downloadAddress; gData.appData.updateDes = response.data.versionRemark; gData.appData.fixDes = response.data.bugRestoreRemark; } else { gData.appData.needForceUpdate = 0; console.error("[Login]无response.data 请检查."); } mk.console.logSingle("===[Login] gData.appData.needForceUpdate", response); } //热更新----------------------------------------------------------------- /** 检测热更新 */ public async checkHotUpdate() { //热更脚本交互 this.hotUpdatePanel = this.node.getComponent(HotUpdatePanel); if (!this.hotUpdatePanel) { console.error("===[login] 登录界面,没有挂载热更脚本"); gData.appData.updateState = UpdateState.UpdateFinish; } else { console.log("===[login] 登录界面,挂载热更脚本"); this.hotUpdatePanel.checkHotUpdate(); } } public async login() { //初始化相关数据 mk.pool.init(gData.gameData.pools); PoolMgr.Inst.initPoolPrefab(); PoolMgr.Inst.initPoolPrefabByNum(NODEPOOLPREFABTYPE.CellItem, 64); //本地读取配置 await gData.configData.loadConfig(); gData.adData.init(); mk.console.log("[FC] gData.appData.appId", gData.appData.appId); //登录 gData.loginData.login(); } /** 检查认证和防沉迷 */ checkShowIdentification() { let identification = mk.storage.getStorage('identification'); if (identification == 1) { gData.loginData.passAnti = true; } else { mk.ui.openPanel('module/certification/CertificationNode'); } } private cool = false; clickLogin() { mk.audio.playEffect('button'); if (this.cool) { return; } this.cool = true; this.scheduleOnce(() => { this.cool = false; }, 3) JsbSystem.WxAuth(); } }