Kaynağa Gözat

新增 版本检测

wzh 3 yıl önce
ebeveyn
işleme
d9eb0d67f2

+ 1 - 10
miniprogram/apis/apiConfig.js

@@ -1,17 +1,8 @@
 let v = wx.getAccountInfoSync()
-let appVersion = wx.getStorageSync('appVersion')
 let {
   envVersion
 } = v.miniProgram
-if (appVersion != envVersion) {
-  wx.clearStorage({
-    success: (res) => {
-      wx.setStorageSync('appVersion', envVersion)
-    },
-  })
-
-}
-let apiUrl = `${envVersion == 'release'?'https://interface.huihenduo.com.cn/hhd-pat/':'https://interface.huihenduo.com.cn/hhd-pat-dev/'}`
+let apiUrl = `${envVersion == 'release'?'https://interface.huihenduo.cc/hhd-ship/':'https://interface.huihenduo.cc/hhd-ship-dev/'}`
 
 function api(url, data, method) {
   return new Promise((resolve, reject) => {

+ 25 - 0
miniprogram/app.js

@@ -1,3 +1,7 @@
+import {
+  wxSetSessionKey,
+  getOpenId
+} from "./utils/wxUtils"
 App({
   onLaunch: function () {
     const updateManager = wx.getUpdateManager()
@@ -29,4 +33,25 @@ App({
     })
     this.globalData = {}
   },
+  onShow() {
+    this.checkEnvVersion()
+  },
+  checkEnvVersion() {
+    let v = wx.getAccountInfoSync()
+    let appVersion = wx.getStorageSync('appVersion')
+    let {
+      envVersion
+    } = v.miniProgram
+    if (appVersion != envVersion) {
+      wx.clearStorage({
+        success: (res) => {
+          wx.setStorageSync('appVersion', envVersion)
+          wx.redirectTo({
+            url: '/pages/index/index',
+          })
+        },
+      })
+    }
+    wxSetSessionKey()
+  }
 })

+ 2 - 16
miniprogram/pages/index/index.js

@@ -1,9 +1,5 @@
 // pages/index/index.js
 import cloudApi from "../../apis/cloudApi"
-import {
-  wxSetSessionKey,
-  getOpenId
-} from "../../utils/wxUtils"
 import {
   postApi
 } from "../../apis/api"
@@ -17,19 +13,9 @@ Page({
   },
 
   async login() {
-    let {
-      openId,
-      session_key
-    } = await wxSetSessionKey()
-    if (!openId) {
-      wx.showToast({
-        title: '获取openId失败',
-        icon: "error"
-      })
-      return
-    }
+    if (!wx.getStorageSync('openId')) return
     let res1 = await postApi("/user/wx/openId/login", {
-      openId
+      openId: wx.getStorageSync('openId')
     })
 
     if (res1.data.status == 0) {