Forráskód Böngészése

设置页自动更新

achao 2 éve
szülő
commit
a54e2bfb67
1 módosított fájl, 40 hozzáadás és 31 törlés
  1. 40 31
      pages/user/setUp.vue

+ 40 - 31
pages/user/setUp.vue

@@ -99,7 +99,7 @@
 					url: '',
 					show: true
 				}, ],
-				version:"1.1.0"
+				version: "1.1.0"
 			}
 		},
 		computed: {
@@ -108,9 +108,17 @@
 		onShow() {
 			this.getList()
 			// #ifdef APP-PLUS
-			this.version = plus.runtime.version
-			console.log("当前版本为:",plus.runtime.version)
-			this.checkVersion()
+			plus.runtime.getProperty(plus.runtime.appid, (info) => {
+				//版本号
+				this.version = info.version;
+				console.log("当前版本为:", this.version)
+				this.checkVersion()
+				//appid
+				// this.appID = info.appid;
+			})
+			// this.version = plus.runtime.version
+			// console.log("当前版本为:", plus.runtime)
+			// this.checkVersion()
 			// #endif
 		},
 		onLoad() {},
@@ -135,8 +143,7 @@
 					},
 					method: 'GET',
 					success: (res) => {
-						var versionNo = plus.runtime.version
-						if (versionNo == res.data.data.version) {
+						if (this.version == res.data.data.version) {
 							this.version = "当前为最新版" + res.data.data.version
 						} else {
 							this.version = "发现新版本,立即更新"
@@ -162,7 +169,7 @@
 								plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
 									let client_version = wgtinfo.version
 									var flag_update = client_version.split(".").splice(0, 2).join(
-										".") != res.data.data.version.split(".").splice(0, 2)
+											".") != res.data.data.version.split(".").splice(0, 2)
 										.join(".")
 									var flag_hot = (Number(client_version.split(".")[2]) < Number(res
 										.data.data.version.split(".")[2])) & !flag_update
@@ -182,21 +189,22 @@
 													console.log(res.data.data.url, )
 													var dtask = plus.downloader
 														.createDownload(res.data.data
-														.url, {
-															method: 'GET',
-															filename: '_doc/update/'
-														}, function(d, status) {
-															if (status == 200) {
-																var path = d
-																.filename; //下载apk
-																plus.runtime.install(
-																	path); // 自动安装apk文件
-															} else {
-																plus.nativeUI.alert(
-																	'版本更新失败:' +
-																	status);
-															}
-														});
+															.url, {
+																method: 'GET',
+																filename: '_doc/update/'
+															},
+															function(d, status) {
+																if (status == 200) {
+																	var path = d
+																		.filename; //下载apk
+																	plus.runtime.install(
+																		path); // 自动安装apk文件
+																} else {
+																	plus.nativeUI.alert(
+																		'版本更新失败:' +
+																		status);
+																}
+															});
 													dtask.start();
 												}
 											}
@@ -204,7 +212,7 @@
 									} else if (flag_hot) {
 										console.log("热更新")
 										uni.showLoading({
-											title:'正在热更新'
+											title: '正在热更新'
 										})
 										uni.downloadFile({
 											url: res.data.data.wgtUrl,
@@ -213,7 +221,7 @@
 												if (downloadResult.statusCode === 200) {
 													plus.nativeUI.toast(
 														`正在热更新!${res.data.data.versionCode}`
-														);
+													);
 													plus.runtime.install(downloadResult
 														.tempFilePath, {
 															force: false
@@ -233,19 +241,19 @@
 																		that.$store
 																			.commit(
 																				'logout'
-																				)
+																			)
 																		that.$api
 																			.logout()
 																		plus.nativeUI
 																			.toast(
 																				"登出成功"
-																				);
+																			);
 																		plus.runtime
 																			.restart();
 																		plus.nativeUI
 																			.toast(
 																				"重启成功"
-																				);
+																			);
 																	}
 																})
 															plus.runtime.restart();
@@ -255,7 +263,7 @@
 															console.log(e)
 															plus.nativeUI.toast(
 																`热更新失败:${e.message}`
-																);
+															);
 														});
 												}
 											}
@@ -337,8 +345,8 @@
 					url: `/pages/user/fankui`
 				})
 			},
-			unsubscribe(){
-				var that=this
+			unsubscribe() {
+				var that = this
 				uni.clearStorage({
 					success: function(res) {
 						console.log('success');
@@ -347,7 +355,7 @@
 						})
 						that.$api.doRequest('post', '/auth/api/logout').then(res => {
 							if (res.data.data) {
-						
+
 							}
 						})
 						that.$store.commit('logout')
@@ -468,6 +476,7 @@
 	.exitlogin:after {
 		border: none;
 	}
+
 	.version_css {
 		// margin-right: 10rpx;
 		color: #9D9D9D;