From 4b80c98ef5fda8d6358778f2efe8bb35cb20ccf9 Mon Sep 17 00:00:00 2001
From: queenwuli <942534046@qq.com>
Date: Fri, 15 Jan 2021 16:18:21 +0800
Subject: [PATCH] gx

---
 hive-app/App.vue |   62 +++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/hive-app/App.vue b/hive-app/App.vue
index 91ad9a2..5415b3d 100644
--- a/hive-app/App.vue
+++ b/hive-app/App.vue
@@ -8,6 +8,7 @@
 			setTimeout(()=>{  
 				plus.navigator.closeSplashscreen();  
 			 }, 2000);
+			 this.update();
 			//#endif 
 		},
 		onShow: function() {
@@ -15,6 +16,67 @@
 		},
 		onHide: function() {
 			console.log('App Hide')
+		},
+		methods: {
+			isIos(){
+				return uni.getSystemInfoSync().platform == 'ios';
+			},
+			update() {
+				this.$httpUtils.request('/api/common/findAppVersion').then((res) => {
+					if (res.status!=200 || !res.rows){
+						return;
+					}
+					let result = this.isIos() ? res.rows[1] : res.rows[0];
+					plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
+						if(!this.$utils.compare(wgtinfo.version, result.version)){
+						    uni.showModal({
+						        title: "发现新版本",
+						        content: "确认下载更新",
+								showCancel:false,
+						        success: (res) => {
+						            if (res.confirm == true) {
+										if(this.isIos()){
+											this.openAppStore();
+										} else {
+											this.doUpData(result.address);
+										}
+						            }
+						        }
+						    })
+						}
+					})
+				})
+			},
+			doUpData(url) {
+			    let showLoading = plus.nativeUI.showWaiting("正在下载");
+			    const downloadTask = uni.downloadFile({
+			        url: url, 
+			        success: downloadResult => {
+			            if (downloadResult.statusCode == 200) {
+							showLoading.setTitle("下载完成");
+							plus.nativeUI.closeWaiting();
+			                plus.runtime.install(
+			                    downloadResult.tempFilePath, {
+			                        force: true
+			                    },
+			                    function(res) {
+			                        plus.runtime.restart();
+			                    }
+			                );
+			            }
+			        }
+			    });
+				downloadTask.onProgressUpdate((res) => {
+					showLoading.setTitle("  正在下载 " + res.progress + "%  ");
+				});
+			},
+			openAppStore(){
+				let appleId= 1548845238;
+				plus.runtime.launchApplication({
+					action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
+				});
+				plus.runtime.restart();;
+			}
 		}
 	}
 </script>

--
Gitblit v1.9.1