From 18b475b713a1e8f1a98a85717ebec8c8804bfb23 Mon Sep 17 00:00:00 2001
From: whycq <10027870+whycq@user.noreply.gitee.com>
Date: 星期四, 23 十一月 2023 15:25:07 +0800
Subject: [PATCH] #

---
 pages/login/login.vue |  159 +++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 107 insertions(+), 52 deletions(-)

diff --git a/pages/login/login.vue b/pages/login/login.vue
index 2751946..1d24776 100644
--- a/pages/login/login.vue
+++ b/pages/login/login.vue
@@ -30,6 +30,15 @@
 		<view class="loging">
 			<button class="button" @click="onLogin()" :loading="load.loading">{{load.btnText}}</button>
 		</view>
+		
+		<view>
+			<!-- 鎻愮ず绐楃ず渚� -->
+			<uni-popup ref="upVersion" type="dialog">
+				<uni-popup-dialog :type="msgType" title="閫氱煡" :content="dialogContent" @confirm="dialogConfirm"
+					@close="dialogClose"></uni-popup-dialog>
+			</uni-popup>
+		</view>
+		
 		<!-- #ifdef APP-PLUS -->
 		<view class="version">
 			褰撳墠鐗堟湰: {{version}}
@@ -53,6 +62,9 @@
 					loading: false,
 					btnText: '鐧诲綍'
 				},
+				msgType: 'success',
+				filename: '',
+				dialogContent: ''
 			}
 		},
 		onLoad: function() {
@@ -64,87 +76,130 @@
 				that.version = wgtinfo.version
 			});
 			// #endif
+		},
+		onShow() {
 			this.getVersion()
-
 		},
 		methods: {
 			changePassword: function() {
 				this.showPassword = !this.showPassword;
 			},
+			//妫�娴嬪綋鍓嶅钩鍙帮紝濡傛灉鏄畨鍗撳垯鍚姩瀹夊崜鏇存柊
 			getVersion() {
 				let that = this;
 				uni.getSystemInfo({
 					success: (res) => {
-						//妫�娴嬪綋鍓嶅钩鍙帮紝濡傛灉鏄畨鍗撳垯鍚姩瀹夊崜鏇存柊  
 						if (res.platform == "android") {
 							that.AndroidCheckUpdate();
 						}
 					}
 				})
 			},
+			// 鑾峰彇褰撳墠鐗堟湰鍙�
 			AndroidCheckUpdate() {
 				let that = this;
 				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
 					that.version = wgtinfo.version //瀹㈡埛绔増鏈彿
-					console.log('褰撳墠app鐗堟湰淇℃伅锛�' + that.version);
 				})
-				that.getUpdateVersion()
+				setTimeout(()=>{
+					that.getUpdateVersion()
+				},100)
 			},
+			// 鏍¢獙鐗堟湰
 			getUpdateVersion() {
+				let that = this
+				let type = 0
+				if (that.baseUrl == 'http://undefined:undefined/undefined') {
+					return
+				}
+				
+				let url = that.baseUrl + '/appVersion/checkUpdate/' + that.version + '/' + type
+				uni.request({
+					url: url,
+					method: 'GET',
+					success(res) {
+						console.log(res);
+						var res = res.data
+						if (res.data) {
+							that.filename = res.data.path
+							that.dialogContent = '鍙戠幇鏂扮増鏈�:' + res.data.version + ', 鏄惁绔嬪嵆鏇存柊'
+							that.$refs.upVersion.open()
+						} else {
+							uni.showToast({
+								title: res.msg,
+								icon: "none",
+								position: 'top'
+							})
+						}
+						
+					}
+				})
+			},
+			dialogConfirm() {
+				this.$refs.upVersion.close()
+				this.downWgt()
+			},
+			dialogClose() {
+				this.$refs.upVersion.close()
+			},
+			downWgt() {
 				let that = this;
-				// 鑾峰彇褰撳墠app鐗堟湰淇℃伅
-				return
-				that.$req.get("/appUpdate/queryUpdate", {}, {}).then(function(res) {
-					console.log('res.data:' + JSON.stringify(res.data))
-					console.log("鐜板湪鐨勭増鏈�" + that.version + "鏁版嵁搴撶増鏈�" + res.data.data.version + "杩涘叆鏌ユ壘app鐗堟湰");
-					if (res.data.data.version > that.version) {
-						// 杩欓噷涓嬭浇apkurl浠�/appUpdate/queryUpdate鎺ュ彛璇锋眰杩斿洖鏁版嵁涓幏鍙�
-						that.downloadUrl = BaseUrl + '/' + res.data.data.androidUrl
-						// 鏄惁寮哄埗鏇存柊锛�0 鍚︼紱1 鏄級
-						that.isForceUpdate = res.data.data.isForceUpdate
-						uni.showModal({
-			  		// 鏇存柊鎻愰啋
-							title: '鍙戠幇鏂扮増鏈紝鏄惁鏇存柊',
-							content: '姝ょ増鏈彿锛�' + that.version + '\xa0\xa0\xa0' + '寰呮洿鏂扮増鏈彿锛�' + res.data.data
-								.version,
-							success: res => {
-			 				if (res.confirm) {
-									that.downWgt(); //涓嬭浇鏂囦欢
-									// that.showdownLine = true;
-									// plus.runtime.openURL(androidUrl)
-								} else if (res.cancel) {
-									console.log('that.isForceUpdate锛�' + that.isForceUpdate);
-									// 涓嶆洿鏂板己鍒堕��鍑篴pp
-									if (that.isForceUpdate == 1) {
-										console.log('that.isForceUpdate1锛�' + that.isForceUpdate);
-										uni.showModal({
-											// 鏇存柊鎻愰啋
-											title: '鍙戠幇鏂扮増鏈紝鏄惁鏇存柊',
-											content: '姝ょ増鏈负寮哄埗鏇存柊鐗堟湰濡備笉鍗囩骇灏嗛��鍑篈PP',
-											success: res => {
-												if (res.confirm) {
-													console.log('涓嶆洿鏂板己鍒堕��鍑篴pp');
-													plus.runtime.quit();
-												} else if (res.cancel) {
-													that.AndroidCheckUpdate();
-												}
+				const downloadUrl = that.baseUrl + "/appVersion/downloadApp/" + that.filename
+				uni.showLoading({
+					title: '鏇存柊涓�︹��'
+				})
+				const downloadTask = uni.downloadFile({ //鎵ц涓嬭浇
+					url: downloadUrl, //涓嬭浇鍦板潃
+					timeout: 1000 * 30, //30绉掕秴鏃舵椂闂�
+					success: downloadResult => { //涓嬭浇鎴愬姛
+						console.log(downloadResult);
+						that.showdownLine = false
+						uni.hideLoading();
+						if (downloadResult.statusCode == 200) {
+							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();
 											}
-										});
+										);
 									}
 								}
-							}
-						});
-						//dtask.start();   
+							});
+						} else {
+							uni.hideLoading();
+							that.showdownLine = false
+							uni.showToast({
+								title:'璇峰厛涓婁紶瀹夎鍖�',
+								icon: 'error'
+							})
+						}
+					},
+					fail: err => {
+						uni.hideLoading();
+						that.showdownLine = false
+						that.$u.toast(downloadResult.errMsg)
+					},
+					complete: com => {
+						
+						console.log(com)
 					}
-				}).catch(error => {
-					uni.showToast({
-						title: '璋冪敤璇锋眰澶辫触',
-						mask: false,
-						duration: 5000,
-						icon: "none"
-					});
 				});
-				complete: () => {}
+			
+				// 涓嬭浇杩涘害
+				downloadTask.onProgressUpdate(res => {
+					that.downloadNum = res.progress
+					console.log('涓嬭浇杩涘害' + that.downloadNum);
+				});
 			},
 			onLogin() {
 				let that = this

--
Gitblit v1.9.1