Jelajahi Sumber

feat(更新): 优化应用更新流程和版本显示

liujt 8 bulan lalu
induk
melakukan
1e5254eca4
3 mengubah file dengan 98 tambahan dan 49 penghapusan
  1. 50 25
      App.vue
  2. 1 1
      manifest.json
  3. 47 23
      pages/systemSettings/index.vue

+ 50 - 25
App.vue

@@ -42,15 +42,12 @@
 				} = uni.getAppBaseInfo()
 				} = uni.getAppBaseInfo()
 				if (appVersion != res.versionCode) {
 				if (appVersion != res.versionCode) {
 					uni.showModal({
 					uni.showModal({
-						title: '发现新版本',
+						title: `发现新版本(${res.versionCode})`,
 						content: '更新说明:' + res.releaseNotes,
 						content: '更新说明:' + res.releaseNotes,
 						confirmText: '立即更新',
 						confirmText: '立即更新',
 						success: (val) => {
 						success: (val) => {
 							if (val.confirm) {
 							if (val.confirm) {
-								// uni.showLoading({
-								// 	title: "正在下载安装包...",
-								// 	mask: true,
-								// });
+					
 								const downloadTask = uni.downloadFile({
 								const downloadTask = uni.downloadFile({
 									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
 									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
 									success: (data) => {
 									success: (data) => {
@@ -75,12 +72,12 @@
 															force: true
 															force: true
 														},
 														},
 														function() {
 														function() {
-															uni
-																.hideLoading();
+															// uni
+															// 	.hideLoading();
 														},
 														},
 														function() {
 														function() {
-															uni
-																.hideLoading();
+															// uni
+															// 	.hideLoading();
 															uni.showToast({
 															uni.showToast({
 																title: '更新失败',
 																title: '更新失败',
 																icon: 'error'
 																icon: 'error'
@@ -92,23 +89,51 @@
 										}
 										}
 									}
 									}
 								});
 								});
-								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) {
+								
+								// 先显示初始的loading提示
+								uni.showLoading({
+									title: "正在下载安装包: 0%",
+									mask: true,
+								});
+								
+								// 记录上次显示的进度,避免频繁更新
+								let lastProgress = 0;
+								let loadingVisible = true;
+								
+								downloadTask.onProgressUpdate((ress) => {
+									console.log('下载进度:', ress)
+									
+									// 只在进度有明显变化(每10%)或者达到100%时更新提示
+									if ((ress.progress > lastProgress && ress.progress % 10 === 0) || ress.progress === 100) {
+										// 先隐藏再显示以更新内容
+										if (loadingVisible) {
+											uni.hideLoading();
+										}
+										
+										if (ress.progress < 100) {
+											uni.showLoading({
+												title: "正在下载安装包: " + ress.progress + "%",
+												mask: true,
+											});
+											loadingVisible = true;
+										} else {
+											loadingVisible = false;
+										}
+										lastProgress = ress.progress;
+									}
+								})
+								
+								// 确保任务完成时隐藏loading
+								downloadTask.onStop(() => {
+									if (loadingVisible) {
+										uni.hideLoading();
+										loadingVisible = false;
+									}
+								})
+								downloadTask.onError(() => {
+									if (loadingVisible) {
 										uni.hideLoading();
 										uni.hideLoading();
+										loadingVisible = false;
 									}
 									}
 								})
 								})
 							}
 							}

+ 1 - 1
manifest.json

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

+ 47 - 23
pages/systemSettings/index.vue

@@ -195,10 +195,6 @@
 						confirmText: '立即更新',
 						confirmText: '立即更新',
 						success: (val) => {
 						success: (val) => {
 							if (val.confirm) {
 							if (val.confirm) {
-								// uni.showLoading({
-								// 	title: "正在下载安装包...",
-								// 	mask: true,
-								// });
 								const downloadTask = uni.downloadFile({
 								const downloadTask = uni.downloadFile({
 									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
 									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
 									success: (data) => {
 									success: (data) => {
@@ -223,12 +219,12 @@
 															force: true
 															force: true
 														},
 														},
 														function() {
 														function() {
-															uni
-																.hideLoading();
+															// uni
+															// 	.hideLoading();
 														},
 														},
 														function() {
 														function() {
-															uni
-																.hideLoading();
+															// uni
+															// 	.hideLoading();
 															uni.showToast({
 															uni.showToast({
 																title: '更新失败',
 																title: '更新失败',
 																icon: 'error'
 																icon: 'error'
@@ -240,23 +236,51 @@
 										}
 										}
 									}
 									}
 								});
 								});
-								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) {
+								// 先显示初始的loading提示
+								uni.showLoading({
+									title: "正在下载安装包: 0%",
+									mask: true,
+								});
+								
+								// 记录上次显示的进度,避免频繁更新
+								let lastProgress = 0;
+								let loadingVisible = true;
+								
+								downloadTask.onProgressUpdate((ress) => {
+									console.log('下载进度:', ress)
+									
+									// 只在进度有明显变化(每10%)或者达到100%时更新提示
+									if ((ress.progress > lastProgress && ress.progress % 10 === 0) || ress.progress === 100) {
+										// 先隐藏再显示以更新内容
+										if (loadingVisible) {
+											uni.hideLoading();
+										}
+										
+										if (ress.progress < 100) {
+											uni.showLoading({
+												title: "正在下载安装包: " + ress.progress + "%",
+												mask: true,
+											});
+											loadingVisible = true;
+										} else {
+											loadingVisible = false;
+										}
+										lastProgress = ress.progress;
+									}
+								})
+								
+								// 确保任务完成时隐藏loading
+								downloadTask.onStop(() => {
+									if (loadingVisible) {
+										uni.hideLoading();
+										loadingVisible = false;
+									}
+								})
+								downloadTask.onError(() => {
+									if (loadingVisible) {
 										uni.hideLoading();
 										uni.hideLoading();
+										loadingVisible = false;
 									}
 									}
 								})
 								})
 							}
 							}