Jelajahi Sumber

feat: 更新应用版本至v1.0.3.9并优化更新流程

liujt 8 bulan lalu
induk
melakukan
44e057f1a0
3 mengubah file dengan 117 tambahan dan 73 penghapusan
  1. 38 16
      App.vue
  2. 1 1
      manifest.json
  3. 78 56
      pages/systemSettings/index.vue

+ 38 - 16
App.vue

@@ -15,10 +15,10 @@
 			//console.log('App Launch')
 			// 配置1秒后自动关闭启动页
 
-			console.log('Vue version:', Vue.version);
+			console.log('Vue version:~~~', Vue.version);
 			// #ifdef APP-PLUS
 			const apiInfo = uni.getStorageSync('apiInfo')
-
+			console.log('apiInfo:', apiInfo)
 			if (apiInfo.protocal) {
 				Vue.prototype.apiUrl = `${apiInfo.protocal}${apiInfo.hostname}:${apiInfo.port}/api`
 				Vue.prototype.webviewUrl = `${apiInfo.protocal}${apiInfo.hostname}:${apiInfo.port}`
@@ -36,6 +36,7 @@
 			}
 
 			getLatestVersion().then(res => {
+				console.log('res:', res)
 				const {
 					appVersion
 				} = uni.getAppBaseInfo()
@@ -46,11 +47,11 @@
 						confirmText: '立即更新',
 						success: (val) => {
 							if (val.confirm) {
-								uni.showLoading({
-									title: "正在下载安装包...",
-									mask: true,
-								});
-								uni.downloadFile({
+								// uni.showLoading({
+								// 	title: "正在下载安装包...",
+								// 	mask: true,
+								// });
+								const downloadTask = uni.downloadFile({
 									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
 									success: (data) => {
 										if (data.statusCode === 200) {
@@ -58,15 +59,15 @@
 												tempFilePath: data
 													.tempFilePath,
 												success: (saveRes) => {
-													uni.showToast({
-														title: '下载成功',
-														icon: 'success'
-													});
-													uni.hideLoading();
-													uni.showLoading({
-														title: "正在更新...",
-														mask: true,
-													});
+													// uni.showToast({
+													// 	title: '下载成功',
+													// 	icon: 'success'
+													// });
+													// uni.hideLoading();
+													// uni.showLoading({
+													// 	title: "正在更新...",
+													// 	mask: true,
+													// });
 													// 调用安装逻辑
 													plus.runtime.install(
 														saveRes
@@ -91,11 +92,32 @@
 										}
 									}
 								});
+								downloadTask.onProgressUpdate((res) => {
+									console.log('下载进度:', res)
+									// uni.showModal({
+									// 	content: '下载进度:' + res.progress + '%',
+									// 	showCancel: false,
+									// 	success: (val) => {
+									// 		if (val.confirm) {
+									// 		}
+									// 	}
+									// })
+									uni.showLoading({
+										title: "正在下载安装包: " + res.progress + "%",
+										mask: true,
+									});
+
+									if (res.progress == 100) {
+										uni.hideLoading();
+									}
+								})
 							}
 						}
 					});
 				}
 
+			}).catch(err => {
+				console.log('err:', err)
 			})
 
 

+ 1 - 1
manifest.json

@@ -2,7 +2,7 @@
     "name" : "智慧工厂",
     "appid" : "__UNI__45B3907",
     "description" : "",
-    "versionName" : "v1.0.3.7",
+    "versionName" : "v1.0.3.9",
     "versionCode" : "100",
     "transformPx" : false,
     "h5" : {

+ 78 - 56
pages/systemSettings/index.vue

@@ -182,68 +182,90 @@
 				// 	}
 				// })
 
-				// #ifdef APP-PLUS
-				getLatestVersion().then(res => {
-					const {
-						appVersion
-					} = uni.getAppBaseInfo()
-					if (appVersion != res.versionCode) {
-						uni.showModal({
-							title: '发现新版本',
-							content: '更新说明:' + res.releaseNotes,
-							confirmText: '立即更新',
-							success: (val) => {
-								if (val.confirm) {
-									uni.showLoading({
-										title: "正在下载安装包...",
-										mask: true,
-									});
-									uni.downloadFile({
-										url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
-										success: (data) => {
-											if (data.statusCode === 200) {
-												uni.saveFile({
-													tempFilePath: data
-														.tempFilePath,
-													success: (saveRes) => {
-														uni.showToast({
-															title: '下载成功',
-															icon: 'success'
-														});
-														uni.hideLoading();
-														uni.showLoading({
-															title: "正在更新...",
-															mask: true,
-														});
-														// 调用安装逻辑
-														plus.runtime.install(
-															saveRes
-															.savedFilePath, {
-																force: true
-															},
-															function() {
-																uni
-																	.hideLoading();
-															},
-															function() {
-																uni
-																	.hideLoading();
-																uni.showToast({
-																	title: '更新失败',
-																	icon: 'error'
-																});
+			// #ifdef APP-PLUS
+			getLatestVersion().then(res => {
+				console.log('res:', res)
+				const {
+					appVersion
+				} = uni.getAppBaseInfo()
+				if (appVersion != res.versionCode) {
+					uni.showModal({
+						title: '发现新版本',
+						content: '更新说明:' + res.releaseNotes,
+						confirmText: '立即更新',
+						success: (val) => {
+							if (val.confirm) {
+								// uni.showLoading({
+								// 	title: "正在下载安装包...",
+								// 	mask: true,
+								// });
+								const downloadTask = uni.downloadFile({
+									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
+									success: (data) => {
+										if (data.statusCode === 200) {
+											uni.saveFile({
+												tempFilePath: data
+													.tempFilePath,
+												success: (saveRes) => {
+													// uni.showToast({
+													// 	title: '下载成功',
+													// 	icon: 'success'
+													// });
+													// uni.hideLoading();
+													// uni.showLoading({
+													// 	title: "正在更新...",
+													// 	mask: true,
+													// });
+													// 调用安装逻辑
+													plus.runtime.install(
+														saveRes
+														.savedFilePath, {
+															force: true
+														},
+														function() {
+															uni
+																.hideLoading();
+														},
+														function() {
+															uni
+																.hideLoading();
+															uni.showToast({
+																title: '更新失败',
+																icon: 'error'
 															});
+														});
 
-													}
-												});
-											}
+												}
+											});
 										}
+									}
+								});
+								downloadTask.onProgressUpdate((res) => {
+									console.log('下载进度:', res)
+									// uni.showModal({
+									// 	content: '下载进度:' + res.progress + '%',
+									// 	showCancel: false,
+									// 	success: (val) => {
+									// 		if (val.confirm) {
+									// 		}
+									// 	}
+									// })
+									uni.showLoading({
+										title: "正在下载安装包: " + res.progress + "%",
+										mask: true,
 									});
-								}
+
+									if (res.progress == 100) {
+										uni.hideLoading();
+									}
+								})
 							}
-						});
-					}
+						}
+					});
+				}
 
+				}).catch(err => {
+					console.log('err:', err)
 				})
 				// #endif
 			},