| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import JsbSystem from "../../../mk/system/JsbSystem";
- import { UpdateState } from "../../data/AppData";
- import { AUDIO_TYPE } from "../../data/GameData";
- /** 最新版本下载 */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class ForceUpdate extends cc.Component {
- @property(cc.Label)
- labUpdate: cc.Label = null
- @property(cc.Label)
- labFix: cc.Label = null
- @property(cc.Node)
- btnSure: cc.Node = null
- @property(cc.Node)
- btnCancel: cc.Node = null
- @property(cc.Sprite)
- fileProgress: cc.Sprite = null
- @property(cc.Label)
- labPro: cc.Label = null
- start() {
- this.setText()
- }
- clickDownLoad() {
- mk.audio.playEffect("ef_button_click")
- this.btnSure.active = false
- this.btnCancel.active = false
- this.fileProgress.node.parent.active = true
- let apkUrl = gData.appData.installUrl
- let arr = apkUrl.split('/')
- let apkName = arr[arr.length - 1]
- console.log('apkName ', apkName)
- let installUrl = apkName.replace('.apk', '');
- if (JsbSystem.isFileExist(installUrl)) {
- console.log('installUrl ', installUrl)
- //已下载过
- JsbSystem.installApk(installUrl);
- return null;
- }
- //未下载过
- JsbSystem.downFile2Local(apkUrl, apkName,
- (locaPath) => {
- setTimeout(() => {
- JsbSystem.installApk(installUrl)
- }, 1)
- },
- (locaPath) => {
- let str = '下载失败,请检查网络后重试'
- mk.tip.pop(str);
- this.fileProgress.node.parent.active = false
- this.fileProgress.fillRange = 0
- this.labPro.string = '0%'
- this.btnSure.active = true
- this.btnCancel.active = false
- },
- (bytesReceived, totalBytesReceived, totalBytesExpected) => {
- let pro = totalBytesReceived / totalBytesExpected
- this.setPro(pro)
- })
- }
- //更新进度
- setPro(pro) {
- this.labPro.string = `${Math.floor(pro * 100)}%`
- this.fileProgress.fillRange = pro
- }
- clickSkip() {
- mk.audio.playEffect(AUDIO_TYPE.button)
- mk.ui.closePanel(this.node.name);
- gData.appData.updateState = UpdateState.ForceUpdateFinish;
- }
- /** 设置文本 */
- setText() {
- this.labUpdate.string = gData.appData.updateDes;
- this.labFix.string = gData.appData.fixDes;
- }
- }
|