From 684ef70c5834b3bdee5997dbdc8bf193eacb7851 Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期四, 01 八月 2024 11:34:01 +0800
Subject: [PATCH] lll

---
 wechat_jiaxuan/app.js |  165 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 119 insertions(+), 46 deletions(-)

diff --git a/wechat_jiaxuan/app.js b/wechat_jiaxuan/app.js
index 10dab9b..d52c340 100644
--- a/wechat_jiaxuan/app.js
+++ b/wechat_jiaxuan/app.js
@@ -1,5 +1,6 @@
 import {
-  wxLoginCustomer
+  wxLoginCustomer,
+  getMemberInfo
 } from './api/index'
 import CustomHook from 'spa-custom-hooks';
 let globalData = {
@@ -24,55 +25,127 @@
       this.globalData.bottomLift = WindowInfo.screenHeight - WindowInfo.safeArea.bottom
     }
     // 鎺堟潈鐧诲綍
-    wx.login({
-      timeout: 5000,
-      success: (res) => {
-        var userId = null
-        if (op.query.scene) {
-          let temp = op.query.scene.split('_')
-          userId = temp[2] 
-        }
-        if (res.code) {
-          //鍙戣捣缃戠粶璇锋眰
-          wxLoginCustomer({
-            code: res.code,
-            userId 
-          }).then(res => {
-            wx.setStorageSync('token', res.data.token)
-            this.globalData.token = res.data.token
-            if (op.query.scene) {
-              let temp = op.query.scene.split('_')
-              wx.navigateTo({
-                url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`,
-              })
-            }
-            console.log('鎷垮埌token浜�', res.data.token);
-            if (res && res.data.member) {
-              wx.setStorageSync('member', res.data.member)
-              wx.setStorageSync('openid', res.data.member.openid)
-              wx.setStorageSync('sessionKey', res.data.sessionKey)
-            } else {
-              console.log('鐧诲綍澶辫触锛�')
+    var userId = null
+    if (op.query.scene) {
+      let temp = op.query.scene.split('_')
+      userId = temp[2]
+    }
+    const token = wx.getStorageSync('token') || ''
+    if (token) {
+      getMemberInfo({
+        isAuth: true
+      }).then(res => {
+        if (res.code !== 200) {
+          setTimeout(() => {
+            wx.showLoading({
+              title: '姝e湪閲嶆柊鐧诲綍...',
+              mask: true
+            })
+          }, 200)
+          setTimeout(() => {
+            wx.hideLoading()
+          }, 1000)
+          wx.login({
+            timeout: 5000,
+            success: (res) => {
+              var userId = null
+              if (op.query.scene) {
+                let temp = op.query.scene.split('_')
+                userId = temp[2]
+              }
+              if (res.code) {
+                //鍙戣捣缃戠粶璇锋眰
+                wxLoginCustomer({
+                  code: res.code,
+                  userId
+                }).then(res => {
+                  wx.setStorageSync('token', res.data.token)
+                  this.globalData.token = res.data.token
+                  if (op.query.scene) {
+                    let temp = op.query.scene.split('_')
+                    wx.navigateTo({
+                      url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`,
+                    })
+                  }
+                  console.log('鎷垮埌token浜�', res.data.token);
+                  if (res && res.data.member) {
+                    wx.setStorageSync('member', res.data.member)
+                    wx.setStorageSync('openid', res.data.member.openid)
+                    wx.setStorageSync('sessionKey', res.data.sessionKey)
+                  } else {
+                    console.log('鐧诲綍澶辫触锛�')
+                  }
+                })
+              } else {
+                console.log('鐧诲綍澶辫触锛�' + res)
+              }
+            },
+            fail(err) {
+              console.log(err)
             }
           })
         } else {
-          console.log('鐧诲綍澶辫触锛�' + res)
+          if (op.query.scene) {
+            let temp = op.query.scene.split('_')
+            wx.navigateTo({
+              url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`,
+            })
+          }
         }
-      },
-      fail(err) {
-        console.log(err)
-      }
-    }) 
-
+      })
+    } else {
+      // 鎺堟潈鐧诲綍
+      wx.login({
+        timeout: 5000,
+        success: (res) => {
+          if (op.query.scene) {
+            let temp = op.query.scene.split('_')
+            userId = temp[2]
+          }
+          if (res.code) {
+            //鍙戣捣缃戠粶璇锋眰
+            wxLoginCustomer({
+              code: res.code,
+              userId
+            }).then(res => {
+              wx.setStorageSync('token', res.data.token)
+              this.globalData.token = res.data.token
+              if (op.query.scene) {
+                let temp = op.query.scene.split('_')
+                wx.navigateTo({
+                  url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`,
+                })
+              }
+              console.log('鎷垮埌token浜�', res.data.token);
+              if (res && res.data.member) {
+                wx.setStorageSync('member', res.data.member)
+                wx.setStorageSync('openid', res.data.member.openid)
+                wx.setStorageSync('sessionKey', res.data.sessionKey)
+              } else {
+                console.log('鐧诲綍澶辫触锛�')
+              }
+            })
+          } else {
+            console.log('鐧诲綍澶辫触锛�' + res)
+          }
+        },
+        fail(err) {
+          console.log(err)
+        }
+      })
+    }
+  },
+  onShow(options) {
+    console.log('options', options);
   }
 })
 CustomHook.install({
-  'Login':{
-     name:'Login',
-     watchKey: 'token',
-     onUpdate(val){
-       //鏈塼oken鍒欒Е鍙戞閽╁瓙
-       return !!val;
-     }
-   }
- }, globalData || 'globalData')
\ No newline at end of file
+  'Login': {
+    name: 'Login',
+    watchKey: 'token',
+    onUpdate(val) {
+      //鏈塼oken鍒欒Е鍙戞閽╁瓙
+      return !!val;
+    }
+  }
+}, globalData || 'globalData')
\ No newline at end of file

--
Gitblit v1.9.3