瀏覽代碼

fix:登录页面版本号

xuyunhui 2 月之前
父節點
當前提交
51eda69ac3
共有 4 個文件被更改,包括 76 次插入6 次删除
  1. 65 0
      common/js/app.js
  2. 2 2
      common/js/env.js
  3. 2 2
      manifest.json
  4. 7 2
      pages/login/login.vue

+ 65 - 0
common/js/app.js

@@ -0,0 +1,65 @@
+/**
+ * 应用信息工具类
+ */
+import versionConfig from '@/config/version.js'
+
+export default {
+	/**
+	 * 同步获取应用版本号
+	 * @returns {string} 版本号
+	 */
+	getVersionSync() {
+		try {
+			const systemInfo = uni.getSystemInfoSync()
+
+			console.log(systemInfo,'systemInfosystemInfosystemInfo')
+			// #ifdef APP-PLUS
+			// App 端优先使用 plus API
+			return plus.runtime.version
+			// #endif
+
+			// 小程序和 H5 端使用 uni.getSystemInfoSync 的 appVersion 字段
+			if (systemInfo.appVersion) {
+				return systemInfo.appVersion
+			}
+
+			// 如果获取不到,返回配置文件的版本号
+			return versionConfig.getVersionName()
+		} catch (e) {
+			// 出错时返回配置文件的版本号
+			return versionConfig.getVersionName()
+		}
+	},
+
+	/**
+	 * 异步获取应用版本号
+	 * @returns {Promise<string>} 版本号
+	 */
+	getVersion() {
+		return new Promise((resolve) => {
+			try {
+				uni.getSystemInfo({
+					success: (res) => {
+						// #ifdef APP-PLUS
+						// App 端优先使用 plus API
+						resolve(plus.runtime.version)
+						// #endif
+
+						// #ifndef APP-PLUS
+						if (res.appVersion) {
+							resolve(res.appVersion)
+						} else {
+							resolve(versionConfig.getVersionName())
+						}
+						// #endif
+					},
+					fail: () => {
+						resolve(versionConfig.getVersionName())
+					}
+				})
+			} catch (e) {
+				resolve(versionConfig.getVersionName())
+			}
+		})
+	}
+}

+ 2 - 2
common/js/env.js

@@ -4,13 +4,13 @@
  * 正式环境
  * @type {string}
  */
-// let baseUrl = `https://jje.xinyuekj.com.cn/prod-api`
+let baseUrl = `https://jje.xinyuekj.com.cn/prod-api`
 
 /**
  * 测试环境
  * @type {string}
  */
-let baseUrl = `https://jje.xinyuekj.com.cn/test-api`
+// let baseUrl = `https://jje.xinyuekj.com.cn/test-api`
 
 /**
  * 庞架开发环境

+ 2 - 2
manifest.json

@@ -2,8 +2,8 @@
     "name" : "娇骄儿技师端",
     "appid" : "__UNI__7BC265E",
     "description" : "",
-    "versionName" : "1.0.21",
-    "versionCode" : 1021,
+    "versionName" : "1.0.22",
+    "versionCode" : 1022,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {

+ 7 - 2
pages/login/login.vue

@@ -48,17 +48,19 @@
 		</view>
 
 		<view class="flex-row justify-center version">
-			<text>版本:1.0.0</text>
+			<text>版本:{{ version }}</text>
 		</view>
 	</view>
 </template>
 
 <script>
+import app from '@/common/js/app.js'
 
 	export default {
 		data() {
 			return {
 				savePassword:true,
+				version: '1.0.21',
 				form: {
 					username: '',
 					password: ''
@@ -85,6 +87,10 @@
 
 			}
 		},
+		onLoad() {
+			// 获取应用版本号
+			this.version = app.getVersionSync()
+		},
 		onShow(){
 			this.form.username = uni.getStorageSync('username')
 			this.form.password = uni.getStorageSync('password')
@@ -95,7 +101,6 @@
 			}
 		},
 		methods: {
-
 			forgetPassword(){
 				uni.navigateTo({
 					url:'/pages/forgetPassword/forgetPassword'