import Util from "../../../before/util/Util"; import MKSwitch from "../../../mk/MKSwitch"; import JsbSystem from "../../../mk/system/JsbSystem"; import LoadingBar from "../../component/LoadingBar"; import { UpdateState } from "../../data/AppData"; import HotUpdatePanel from "../hotUpdate/HotUpdatePanel"; const { ccclass, property } = cc._decorator; @ccclass export default class Login extends cc.Component { @property(LoadingBar) private bar: LoadingBar = null; @property({ displayName: '加载文字', type: cc.Label }) private lbl_progress: cc.Label = 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 hasCheckAnti = false; private loadSceneState = false; private hasCheckPermission = false; private hasCheckPrivacy = false; onLoad() { this.setProgress(0); this.node_loadPart.active = true; this.node_btnLogin.active = false; } start() { if (mk.storage.getStorage("alifengkong") == 1) { return; } if (CC_DEBUG) { mk.aliRiskManager.getRiskCode = true; gData.appData.getDeviceInfoCompelete = true; mk.shuzilmM.hasGot = true; mk.tongdunM.hasGot = true; } else { mk.aliRiskManager.init(); mk.tongdunM.init(); mk.shuzilmM.init(); } gData.loginData.loadLocalRes(); } update() { if (!mk.shuzilmM.hasGot || !mk.tongdunM.hasGot) { return; } if (!this.hasDeviceBackInit) { this.hasDeviceBackInit = true; this.getAppVersion(); } // if (!this.hasDeviceBackInit) { // this.hasDeviceBackInit = true; // this.getDeviceInfoBack(); // } //如果更新没有结束,就不进入正常加载流程 if (gData.appData.updateState == UpdateState.ForceUpdateFinish) { gData.appData.updateState = UpdateState.CheckHot; this.checkHotUpdate(); } if (gData.appData.updateState == UpdateState.IsUpdate) { this.lbl_progress.string = '正在更新中,请耐心等待'; this.bar.setProgress(gData.appData.updatePercent); return; } if (gData.appData.updateState != UpdateState.UpdateFinish) { return; } 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 (!CC_DEBUG) { if (gData.loginData.popIdentifySwitch) { if (!this.hasCheckAnti) { this.hasCheckAnti = true // this.checkShowIdentification() JsbSystem.ysdkInit(); JsbSystem.autologin(); } if (!gData.loginData.passAnti) { return } } } if (this.process < 100) { this.process += 2; this.setProgress(this.process); } if (gData.loginData.loadResCompelete) { if (mk.aliRiskManager.getRiskCode) { mk.aliRiskManager.getRiskCode = false; 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; } gData.gameData.dataFinish = false; } } else { gData.loginData.loadLocalRes(); } } private async loadMain() { mk.ui.openPanel("game/prefab/game"); console.log("===[Jsbsystem 显示开屏广告================================") JsbSystem.showSplash(); } private checkPrivacy() { if (mk.storage.getStorage("agreementTip") != 1) { mk.ui.openPanel("module/login/agreementTip"); } else { gData.loginData.passPrivacy = true; } } /** 设置进度 */ private setProgress(current) { this.bar.setProgress(current); this.lbl_progress.string = "加载不消耗流量 " + current + "%"; } // /** 初始化 */ // public async init() { // //获取appid 和 配置version // JsbSystem.getWxAppId(); // //获取手机授权 // JsbSystem.checkPermission(); // } /** 获取设备信息后 */ public async getDeviceInfoBack() { //获取登录需要的sessionkey gData.loginData.init(); await this.checkForceUpate(); this.checkRemoveLocalHot(); mk.audio.init(); } /** 获取appid 和 version */ 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); cc.audioEngine.stopAll(); cc.game.restart(); } } } } /** 检测强制更新 */ 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.5.1"; } 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 login() { //初始化相关数据 mk.pool.init(gData.gameData.pools); gData.appData.init(); 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(); } }