Explorar el Código

fix: 修复文件下载URL拼接问题并更新版本检查逻辑

liujt hace 8 meses
padre
commit
f7a0843cb8
Se han modificado 3 ficheros con 101 adiciones y 27 borrados
  1. 1 1
      App.vue
  2. 2 2
      manifest.json
  3. 98 24
      pages/systemSettings/index.vue

+ 1 - 1
App.vue

@@ -51,7 +51,7 @@
 									mask: true,
 								});
 								uni.downloadFile({
-									url: res.fileUrl,
+									url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
 									success: (data) => {
 										if (data.statusCode === 200) {
 											uni.saveFile({

+ 2 - 2
manifest.json

@@ -2,7 +2,7 @@
     "name" : "智慧工厂",
     "appid" : "__UNI__45B3907",
     "description" : "",
-    "versionName" : "v1.0.3.6",
+    "versionName" : "v1.0.3.7",
     "versionCode" : "100",
     "transformPx" : false,
     "h5" : {
@@ -10,7 +10,7 @@
             "proxy" : {
                 "/api" : {
                     // "target" : "http://192.168.1.110:18086/",
-                    "target" : "http://192.168.1.125:18086/",
+                    "target" : "http://192.168.1.251:18086/",
                     "changeOrigin" : true,
                     "secure" : false,
                     "pathRewrite" : {

+ 98 - 24
pages/systemSettings/index.vue

@@ -15,11 +15,11 @@
           apiAdress
         }}</text>
 			</u-cell>
-			<!-- 	<u-cell :title="'当前版本 ' + currentVersion" :isLink="true" arrow-direction="right">
+			<u-cell :title="'当前版本 ' + currentVersion" :isLink="true" arrow-direction="right">
 				<text slot="value" class="u-slot-value" @click="handlUpdate">{{
-          Nversion == currentVersion ? '' : `发现新版本(${this.Nversion})`
-        }}</text>
-			</u-cell> -->
+					Nversion == currentVersion ? '' : `发现新版本(${Nversion})`}}
+				</text>
+			</u-cell>
 		</u-cell-group>
 		<view class="flex-buttom">
 			<view class="btn" @click="loginOut"> 退出登录 </view>
@@ -46,6 +46,9 @@
 		removeMemo
 	} from '@/utils/passwordMemo.js'
 	import ServerSetting from '@/components/ServerSetting/index'
+	import {
+		getLatestVersion
+	} from '@/api/common.js'
 	export default {
 		components: {
 			updatePop,
@@ -70,9 +73,15 @@
 				apiInfo.hostname &&
 				`${apiInfo.protocal || ''}${apiInfo.hostname || ''}:${apiInfo.port || ''}`
 
+			const {
+				appVersion
+			} = uni.getAppBaseInfo()
+			this.currentVersion = appVersion
+			getLatestVersion().then(res => {
+				this.Nversion = res.versionCode
+			})
 
-
-			this.currentVersion = plus?.runtime.version
+			// this.currentVersion = plus?.runtime.version
 			// this.getbb()
 		},
 		created() {
@@ -152,26 +161,91 @@
 				})
 			},
 			handlUpdate() {
-				get(this.apiUrl + '/versioning/getLatestData').then(res => {
-					console.log(res);
-					if (res.success) {
-						const currentVersion = this.currentVersion
-						const Nversion = res.data.version
-
-						console.log(currentVersion, Nversion);
-						this.VersionInfo = res.data
-						if (currentVersion !== Nversion) {
-							this.$refs.updatePop.open()
-							this.versionNum = Nversion
-							this.downloadUrl = this.apiUrl + res.data.path
-						} else {
-							uni.showToast({
-								title: '暂无新版本',
-								icon: 'none'
-							})
-						}
+				// get(this.apiUrl + '/versioning/getLatestData').then(res => {
+				// 	console.log(res);
+				// 	if (res.success) {
+				// 		const currentVersion = this.currentVersion
+				// 		const Nversion = res.data.version
+
+				// 		console.log(currentVersion, Nversion);
+				// 		this.VersionInfo = res.data
+				// 		if (currentVersion !== Nversion) {
+				// 			this.$refs.updatePop.open()
+				// 			this.versionNum = Nversion
+				// 			this.downloadUrl = this.apiUrl + res.data.path
+				// 		} else {
+				// 			uni.showToast({
+				// 				title: '暂无新版本',
+				// 				icon: 'none'
+				// 			})
+				// 		}
+				// 	}
+				// })
+
+				// #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'
+																});
+															});
+
+													}
+												});
+											}
+										}
+									});
+								}
+							}
+						});
 					}
+
 				})
+				// #endif
 			},
 			getbb() {
 				get(this.apiUrl + '/versioning/getLatestData').then(res => {