| 123456789101112131415161718192021222324252627282930313233343536 |
- import { _decorator, Component, ProgressBar } from 'cc';
- import { Http } from '../core/net/Http';
- import { BitmapFont } from '../core/ui/BitmapFont';
- import { Utils } from '../core/utils/Utils';
- import { g } from '../Data/g';
- import { platform } from '../Data/platform';
- const { ccclass, property } = _decorator;
- @ccclass('AppUpdate')
- export class AppUpdate extends Component {
- @property({ tooltip: "网络请求对象", type: Http })
- public http: Http;
- @property({ type: ProgressBar, tooltip: "加载进度条组件" })
- public progressBar: ProgressBar;
- @property({ type: BitmapFont, tooltip: "加载进度" })
- loadProgressBitmapFont: BitmapFont;
- public versionIsNew: number = -1;
- public async checkNativeVersion(version: string) {
- let versionData = await this.http.send("/version", { game: "fixmix-fs", channel: g.deviceData.channel });
- if (versionData.code == 0) {
- this.versionIsNew = Utils.compareVersion(version, versionData.data.version);
- console.log("是否是最新" + this.versionIsNew);
- this.versionIsNew == -1 && this.downloadAPK(versionData.data.apk);//如果版本较老则下载APK
- }
- }
- public downloadAPK(url: string) {
- g.deviceData.apkDownloading = true;
- platform.downloadAPK(url, "mix-fs.apk");
- }
- public setDownloadAPKProgress() {
- //根据APK下载进度设置UI
- this.progressBar.progress = g.deviceData.downloadAPKProgress;
- // this.loadProgressBitmapFont.string = Math.floor(g.deviceData.downloadAPKProgress / totalCount * 100) + '%'
- }
- }
|