695593266@qq.com 8 miesięcy temu
rodzic
commit
ba3a621d43
3 zmienionych plików z 172 dodań i 79 usunięć
  1. 68 21
      App.vue
  2. 1 1
      manifest.json
  3. 103 57
      pages/systemSettings/index.vue

+ 68 - 21
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,21 +36,19 @@
 			}
 
 			getLatestVersion().then(res => {
+				console.log('res:', res)
 				const {
 					appVersion
 				} = uni.getAppBaseInfo()
 				if (appVersion != res.versionCode) {
 					uni.showModal({
-						title: '发现新版本',
+						title: `发现新版本(${res.versionCode})`,
 						content: '更新说明:' + res.releaseNotes,
 						confirmText: '立即更新',
 						success: (val) => {
 							if (val.confirm) {
-								uni.showLoading({
-									title: "正在下载安装包...",
-									mask: true,
-								});
-								uni.downloadFile({
+					
+								const downloadTask = uni.downloadFile({
 									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
 									success: (data) => {
 										if (data.statusCode === 200) {
@@ -58,15 +56,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
@@ -74,12 +72,12 @@
 															force: true
 														},
 														function() {
-															uni
-																.hideLoading();
+															// uni
+															// 	.hideLoading();
 														},
 														function() {
-															uni
-																.hideLoading();
+															// uni
+															// 	.hideLoading();
 															uni.showToast({
 																title: '更新失败',
 																icon: 'error'
@@ -91,11 +89,60 @@
 										}
 									}
 								});
+								
+								// 先显示初始的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();
+										loadingVisible = false;
+									}
+								})
 							}
 						}
 					});
 				}
 
+			}).catch(err => {
+				console.log('err:', err)
 			})
 
 

+ 1 - 1
manifest.json

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

+ 103 - 57
pages/systemSettings/index.vue

@@ -182,68 +182,114 @@
 				// 	}
 				// })
 
-				// #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) {
+								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'
 															});
+														});
 
-													}
-												});
-											}
+												}
+											});
+										}
+									}
+								});
+
+								// 先显示初始的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();
+										loadingVisible = false;
+									}
+								})
 							}
-						});
-					}
+						}
+					});
+				}
 
+				}).catch(err => {
+					console.log('err:', err)
 				})
 				// #endif
 			},