From c0b24b804539df3a40a0be613b44562c7e073005 Mon Sep 17 00:00:00 2001 From: whycq <10027870+whycq@user.noreply.gitee.com> Date: 星期四, 20 四月 2023 10:43:46 +0800 Subject: [PATCH] # --- App.vue | 68 ++++++++++++++++++++++++++++++++-- 1 files changed, 64 insertions(+), 4 deletions(-) diff --git a/App.vue b/App.vue index c8fed19..c206b2f 100644 --- a/App.vue +++ b/App.vue @@ -4,6 +4,7 @@ globalData: { baseHttp: '', baseUrll: '', + upVersion: 0, }, onLaunch: function() { Vue.prototype.ColorList = [{ @@ -86,7 +87,6 @@ onShow: function() { this.getVersion(); this.baseUrll = uni.getStorageSync("baseUrl") - // console.log(this.baseUrll); console.log('App Show') }, onHide: function() { @@ -117,11 +117,16 @@ getUpdateVersion() { let that = this; uni.request({ - url: that.baseUrll + "/appUpdate/queryUpdate", + url: that.baseUrll + "/mobile/appUpdate/queryUpdate", method:'GET', - data: {combParam: 'asd'}, success(res) { - console.log(res); + // 鏂癮pp鐗堟湰 + that.upVersion = Number(res.data.data) + // 褰撳墠app鐗堟湰 + let currentVersion = Number(that.version) + if(that.upVersion > currentVersion) { + that.downWgt(); //涓嬭浇鏂囦欢 + } } }) return @@ -177,6 +182,61 @@ }); 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> -- Gitblit v1.9.1