import { getApkVersion } from '@/api/auth' import { IMGHOST } from '@/config' export default { data() { return { version:0 }; }, onLoad(){ // #ifdef APP-PLUS plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{ this.version = wgtinfo.versionCode }); uni.getSystemInfo({ success:(res) => { //检测当前平台,如果是安卓则启动安卓更新 if(res.platform=="android"){ this.androidCheckUpdate() } } }) // #endif }, methods: { androidCheckUpdate(){ getApkVersion().then(res=>{ console.log(res) if(res.code == 1){ let version = res.data.version let mustUpdate = res.data.mustUpdate let singer = mustUpdate == 1 ? true : false if(version <= this.version){ return false } if(plus.networkinfo.getCurrentType()!=3){ let that = this that.$util.confirmModal({content:'新版本更新',cancelText:'稍后',okText:'使用流量更新'},() => { this.install(version) }) }else{ let that = this that.$util.confirmModal({content:'新版本更新',singer:singer},() => { this.install(version) }) } } }) }, install(version){ console.log(IMGHOST+'/apk/hd/'+version+'.apk') uni.showToast({ title: '后台下载中...', mask: false, duration: 1200,icon:"none"}) var dtask = plus.downloader.createDownload( IMGHOST+'/apk/hd/'+version+'.apk', {}, function ( d, status ) { // 下载完成 if ( status == 200 ) { plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){ uni.showToast({ title: '安装失败', mask: false, duration: 1500,icon:"none" }) }) } else { uni.showToast({ title: '更新失败', mask: false, duration: 1500,icon:"none" }) } }); dtask.start() } } }