| | |
| | | globalData: { |
| | | baseHttp: '', |
| | | baseUrll: '', |
| | | upVersion: 0, |
| | | }, |
| | | onLaunch: function() { |
| | | Vue.prototype.ColorList = [{ |
| | |
| | | let that = this; |
| | | uni.request({ |
| | | url: that.baseUrll + "/mobile/appUpdate/queryUpdate", |
| | | // data: {combParam: 'asd'}, |
| | | method:'GET', |
| | | success(res) { |
| | | console.log(res); |
| | | // 新app版本 |
| | | that.upVersion = Number(res.data.data) |
| | | // 当前app版本 |
| | | let currentVersion = Number(that.version) |
| | | if(that.upVersion > currentVersion) { |
| | | that.downWgt(); //下载文件 |
| | | } |
| | | } |
| | | }) |
| | | return |
| | |
| | | }); |
| | | complete: () => {} |
| | | }, |
| | | downWgt() { |
| | | let that = this; |
| | | const downloadUrl = that.baseUrll + "/static/appupload/" + that.upVersion + ".apk" |
| | | uni.showLoading({ |
| | | title: '更新中……' |
| | | }) |
| | | // return |
| | | const downloadTask = uni.downloadFile({ //执行下载 |
| | | url: downloadUrl, //下载地址 |
| | | timeout: 1000 * 30, //30秒超时时间 |
| | | success: downloadResult => { //下载成功 |
| | | console.log(downloadResult); |
| | | that.showdownLine = false |
| | | uni.hideLoading(); |
| | | console.log('downloadResult.statusCode' + downloadResult.statusCode) |
| | | if (downloadResult.statusCode == 200) { |
| | | console.log('更新中') |
| | | uni.showModal({ |
| | | title: '', |
| | | content: '更新成功,确定现在重启吗?', |
| | | confirmText: '重启', |
| | | confirmColor: '#EE8F57', |
| | | success: function(res) { |
| | | if (res.confirm == true) { |
| | | plus.runtime.install( //安装 |
| | | downloadResult.tempFilePath, { |
| | | force: true |
| | | }, |
| | | function(res) { |
| | | utils.showToast('更新成功,重启中'); |
| | | plus.runtime.restart(); |
| | | } |
| | | ); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }, |
| | | fail: err => { |
| | | uni.hideLoading(); |
| | | that.showdownLine = false |
| | | that.$u.toast(err.errMsg) |
| | | console.log(err) |
| | | }, |
| | | complete: com => { |
| | | console.log(com) |
| | | } |
| | | }); |
| | | |
| | | // 下载进度 |
| | | downloadTask.onProgressUpdate(res => { |
| | | that.downloadNum = res.progress |
| | | console.log('下载进度' + that.downloadNum); |
| | | }); |
| | | }, |
| | | } |
| | | } |
| | | </script> |