|
|
@@ -0,0 +1,68 @@
|
|
|
+import { getApkVersion } from '@/api/auth'
|
|
|
+import { APIHOST } from '@/config'
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ version:0
|
|
|
+ };
|
|
|
+ },
|
|
|
+ onLoad(){
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
|
|
|
+ console.log(JSON.stringify(wgtinfo));
|
|
|
+ console.log(wgtinfo.version);
|
|
|
+ this.version = wgtinfo.version
|
|
|
+ });
|
|
|
+ uni.getSystemInfo({
|
|
|
+ success:(res) => {
|
|
|
+ console.log(res.platform);
|
|
|
+ //检测当前平台,如果是安卓则启动安卓更新
|
|
|
+ if(res.platform=="android"){
|
|
|
+ this.androidCheckUpdate()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // #endif
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ androidCheckUpdate(){
|
|
|
+ getApkVersion().then(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(APIHOST+'/apk/'+version+'.apk')
|
|
|
+ uni.showToast({ title: '后台下载中...', mask: false, duration: 1200,icon:"none"})
|
|
|
+ var dtask = plus.downloader.createDownload( APIHOST+'/apk/'+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()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|