From 8d60f69402813488545502941785bf2d951e45bb Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期一, 28 十月 2024 17:12:33 +0800
Subject: [PATCH] login

---
 pages/home/home.js      |    1 
 app.js                  |   10 -----
 assets/request/index.js |   32 +++++++++++++++-
 assets/js/login.js      |   20 +++++----
 4 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/app.js b/app.js
index 38af179..daf7726 100644
--- a/app.js
+++ b/app.js
@@ -7,15 +7,5 @@
   onLaunch: function () {},
   onShow: function () {
     updateManager();
-    MG.identity.refreshToken({
-      appRefCode: config.appRefCode,
-      token: wx.getStorageSync(config.tokenKey)
-    }).then(res => {
-      console.log(res, '宸插埛鏂�')
-      if (res.token) {
-        wx.setStorageSync(config.tokenKey, res.token);
-      }
-
-    })
   },
 });
\ No newline at end of file
diff --git a/assets/js/login.js b/assets/js/login.js
index 338b850..37380d0 100644
--- a/assets/js/login.js
+++ b/assets/js/login.js
@@ -2,9 +2,11 @@
   setSessionGuid
 } from "./userAction"
 const app = getApp();
+import MG from './middleGround/WebMiddleGroundApi';
+import config from './config';
 
 export const loginInfo = (app, callback) => {
-  if (app.config.appId == 27) {
+  if (config.appId == 27) {
     wx.navigateTo({
       url: "/pages/testLogin/index",
     });
@@ -13,9 +15,9 @@
       success: (res) => {
         wx.getUserInfo({
           success: (infoRes) => {
-            app.MG.identity.checkWeChatAppAccount({
+            MG.identity.checkWeChatAppAccount({
               code: res.code,
-              appCode: app.config.appRefCode,
+              appCode: config.appRefCode,
               encryptedData: infoRes.encryptedData,
               iv: infoRes.iv
             }).then(loginRes => {
@@ -42,22 +44,22 @@
               } else {
                 wx.login({
                   success: (res) => {
-                    app.MG.identity.loginByWeChatAppCode({
+                    MG.identity.loginByWeChatAppCode({
                       code: res.code,
-                      appRefCode: app.config.appRefCode,
+                      appRefCode: config.appRefCode,
                       platform: "WeChatAppCustom",
                       encryptedData: infoRes.encryptedData,
                       iv: infoRes.iv
                     }).then(res => {
                       if (res && res.status == "Ok") {
                         // 鍌ㄥ瓨token
-                        wx.setStorageSync(app.config.tokenKey, res.token);
+                        wx.setStorageSync(config.tokenKey, res.token);
                         // 鑾峰彇鐢ㄦ埛淇℃伅
                         getUserInfo(app, callback, res.token)
                         // 璁板綍鐧诲綍缁熻
                         setSessionGuid()
                         //鐧诲綍璁板綍绉垎
-                        app.MG.app.creatUserBehavior({
+                        MG.app.creatUserBehavior({
                           refCode: "sign"
                         })
                       } else {
@@ -90,7 +92,7 @@
 }
 // 鑾峰彇鐧诲綍鐢ㄦ埛韬唤
 const getUserInfo = (app, callback, token) => {
-  app.MG.identity.getCurrentAppUser().then(res => {
+  MG.identity.getCurrentAppUser().then(res => {
     // 鐢ㄦ埛淇℃伅浼樺厛绾э細鏁欏笀璁よ瘉 > 寰俊 > 瀛︾敓锛堟敞鍐屾椂榛樿锛�
     if (res) {
       let defaultUser = {};
@@ -122,7 +124,7 @@
         defaultUser.phoneNumber = phoneNumber.credential
       }
 
-      wx.setStorageSync(app.config.userInfoKey, JSON.stringify(defaultUser));
+      wx.setStorageSync(config.userInfoKey, JSON.stringify(defaultUser));
     }
     callback(token);
   });
diff --git a/assets/request/index.js b/assets/request/index.js
index 5c0c389..d20f265 100644
--- a/assets/request/index.js
+++ b/assets/request/index.js
@@ -1,6 +1,11 @@
 import config from "../js/config"
+import {
+  loginInfo
+} from '../js/login';
+const app = getApp()
 let clearStorage = false;
 let timer = null;
+let backUrl = null
 const request = (params) => {
   let fullUrl = `${config.requestCtx}${params.url}`
   let token = wx.getStorageSync(config.tokenKey) ? wx.getStorageSync(config.tokenKey) : ''
@@ -22,7 +27,7 @@
           const url = currentPage.route
           let options = currentPage.options
           let urlargs = `/${url}?`
-          wx.clearStorageSync();
+          // wx.clearStorageSync();
           if (!clearStorage) {
             clearStorage = true;
             if (!timer) {
@@ -31,16 +36,39 @@
               }, 4000);
             }
             // urlargs = JSON.stringify(urlargs)
+            console.log()
             let strOpt = JSON.stringify(options)
             let currentUrl = {
               options: options,
               backUrl: urlargs
             }
-            currentUrl = JSON.stringify(currentUrl)
+            // currentUrl = JSON.stringify(currentUrl)
             // 涓嶅幓棣栭〉鐧诲綍锛岀洿鎺ヨ皟鐢ㄥ叕鍏辩櫥褰曟柟娉�
             // wx.reLaunch({
             //   url: urlargs ? '/pages/home/home?backUrl=' + encodeURIComponent(currentUrl) : '/pages/home/home'
             // })
+            console.log(currentUrl, 123)
+            loginInfo(app, (data) => {
+              if (data) {
+                if (currentUrl.options) {
+                  for (let key in options) {
+                    const value = currentUrl.options[key]
+                    currentUrl.backUrl += `${key}=${value}&`
+                  }
+                  backUrl = currentUrl.backUrl
+                  console.log(backUrl, "url")
+                  if (backUrl) {
+                    wx.reLaunch({
+                      url: backUrl
+                    })
+                  } else {
+                    wx.reLaunch({
+                      url: '/pages/home/home'
+                    })
+                  }
+                }
+              } else {}
+            })
           }
         } else {
           wx.showToast({
diff --git a/pages/home/home.js b/pages/home/home.js
index 500fa59..75fef81 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -1,7 +1,6 @@
 import {
   fetchHome
 } from '../../services/home/home';
-import moment from 'moment'
 import {
   loginInfo
 } from '../../assets/js/login';

--
Gitblit v1.9.1