瀏覽代碼

feat: 添加APP版本更新功能并更新manifest配置

yusheng 8 月之前
父節點
當前提交
9983b3514f
共有 5 個文件被更改,包括 221 次插入3 次删除
  1. 1 1
      .gitignore
  2. 2 0
      .hbuilderx/launch.json
  3. 76 1
      App.vue
  4. 10 1
      api/common.js
  5. 132 0
      manifest.json

+ 1 - 1
.gitignore

@@ -4,7 +4,7 @@ target/
 !**/src/main/**/target/
 !**/src/test/**/target/
 node_modules
-manifest.json
+# manifest.json
 ### STS ###
 .apt_generated
 .classpath

+ 2 - 0
.hbuilderx/launch.json

@@ -19,7 +19,9 @@
             "type" : "uniCloud"
         },
         {
+            "customPlaygroundType" : "device",
             "openVueDevtools" : true,
+            "packageName" : "uni.app.UNI45B3907",
             "playground" : "standard",
             "type" : "uni-app:app-android"
         },

+ 76 - 1
App.vue

@@ -3,6 +3,10 @@
 		isMemo
 	} from '@/utils/passwordMemo.js'
 	import ScanCode from '@/mixins/ScanCode.js'
+	import {
+		getLatestVersion
+	} from '@/api/common.js'
+
 	import Vue from 'vue'
 
 	export default {
@@ -12,9 +16,9 @@
 			// 配置1秒后自动关闭启动页
 
 			console.log('Vue version:', Vue.version);
-
 			// #ifdef APP-PLUS
 			const apiInfo = uni.getStorageSync('apiInfo')
+
 			if (apiInfo.protocal) {
 				Vue.prototype.apiUrl = `${apiInfo.protocal}${apiInfo.hostname}:${apiInfo.port}/api`
 			}
@@ -29,9 +33,80 @@
 					url: '/pages/home/home'
 				})
 			}
+
+			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: res.fileUrl,
+									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
+
+
+			// getLatestVersion
+
 		},
 		onShow: function() {
+
+
 			console.log('App Show')
 		},
 		onHide: function() {

+ 10 - 1
api/common.js

@@ -104,4 +104,13 @@ export async function getDictByCode(code) {
 		return data.data;
 	}
 	return Promise.reject(data.message);
-}
+}
+export async function getLatestVersion(code) {
+	const data = await get(
+		Vue.prototype.apiUrl + `/sys/appupdates/getLatestVersion`,
+	);
+	if (data.code == 0) {
+		return data.data;
+	}
+	return Promise.reject(data.message);
+}

+ 132 - 0
manifest.json

@@ -0,0 +1,132 @@
+{
+    "name" : "智慧工厂",
+    "appid" : "__UNI__45B3907",
+    "description" : "",
+    "versionName" : "v1.0.2.7",
+    "versionCode" : "100",
+    "transformPx" : false,
+    "h5" : {
+        "devServer" : {
+            "proxy" : {
+                "/api" : {
+                    // "target" : "http://192.168.1.110:18086/",
+                    "target" : "http://192.168.1.251:18086/",
+                    "changeOrigin" : true,
+                    "secure" : false,
+                    "pathRewrite" : {
+                        "^/api" : ""
+                    } //如需去掉前缀则加上此配置
+                }
+            },
+            "https" : false
+        },
+        "domain" : "http://127.0.0.1:8601"
+    },
+    /* 5+App特有相关 */
+    "app-plus" : {
+        "usingComponents" : true,
+        "nvueStyleCompiler" : "uni-app",
+        "compilerVersion" : 3,
+        "splashscreen" : {
+            "alwaysShowBeforeRender" : false,
+            "waiting" : true,
+            "autoclose" : true,
+            "delay" : 0
+        },
+        /* 模块配置 */
+        "modules" : {
+            "Camera" : {},
+            "Barcode" : {}
+        },
+        /* 应用发布信息 */
+        "distribute" : {
+            /* android打包配置 */
+            "android" : {
+                "permissions" : [
+                    "<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
+                    "<uses-permission android:name=\"android.permission.VIBRATE\"/>",
+                    "<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
+                    "<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
+                    "<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
+                    "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.CAMERA\"/>",
+                    "<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
+                    "<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
+                    "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
+                    "<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
+                    "<uses-feature android:name=\"android.hardware.camera\"/>",
+                    "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>",
+                    "<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>"
+                ],
+                "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ]
+            },
+            /* ios打包配置 */
+            "ios" : {
+                "dSYMs" : false
+            },
+            /* SDK配置 */
+            "sdkConfigs" : {
+                "ad" : {}
+            },
+            "icons" : {
+                "android" : {
+                    "hdpi" : "unpackage/res/icons/72x72.png",
+                    "xhdpi" : "unpackage/res/icons/96x96.png",
+                    "xxhdpi" : "unpackage/res/icons/144x144.png",
+                    "xxxhdpi" : "unpackage/res/icons/192x192.png"
+                },
+                "ios" : {
+                    "appstore" : "unpackage/res/icons/1024x1024.png",
+                    "ipad" : {
+                        "app" : "unpackage/res/icons/76x76.png",
+                        "app@2x" : "unpackage/res/icons/152x152.png",
+                        "notification" : "unpackage/res/icons/20x20.png",
+                        "notification@2x" : "unpackage/res/icons/40x40.png",
+                        "proapp@2x" : "unpackage/res/icons/167x167.png",
+                        "settings" : "unpackage/res/icons/29x29.png",
+                        "settings@2x" : "unpackage/res/icons/58x58.png",
+                        "spotlight" : "unpackage/res/icons/40x40.png",
+                        "spotlight@2x" : "unpackage/res/icons/80x80.png"
+                    },
+                    "iphone" : {
+                        "app@2x" : "unpackage/res/icons/120x120.png",
+                        "app@3x" : "unpackage/res/icons/180x180.png",
+                        "notification@2x" : "unpackage/res/icons/40x40.png",
+                        "notification@3x" : "unpackage/res/icons/60x60.png",
+                        "settings@2x" : "unpackage/res/icons/58x58.png",
+                        "settings@3x" : "unpackage/res/icons/87x87.png",
+                        "spotlight@2x" : "unpackage/res/icons/80x80.png",
+                        "spotlight@3x" : "unpackage/res/icons/120x120.png"
+                    }
+                }
+            }
+        }
+    },
+    /* 快应用特有相关 */
+    "quickapp" : {},
+    // /* 小程序特有相关 */
+    "mp-weixin" : {
+        "appid" : "",
+        "setting" : {
+            "urlCheck" : false
+        },
+        "usingComponents" : true
+    },
+    "mp-alipay" : {
+        "usingComponents" : true
+    },
+    "mp-baidu" : {
+        "usingComponents" : true
+    },
+    "mp-toutiao" : {
+        "usingComponents" : true
+    },
+    "uniStatistics" : {
+        "enable" : false
+    },
+    "vueVersion" : "2",
+    "fallbackLocale" : "zh-Hans",
+    "sassImplementationName" : "node-sass"
+}