From 2c41dc4162446120feae6a09ecf1d07118850f88 Mon Sep 17 00:00:00 2001
From: yangyin <1850366751@qq.com>
Date: 星期四, 29 八月 2024 12:00:12 +0800
Subject: [PATCH] fix: 修改登录的token过期问题

---
 login/login/index.wxml |   10 +
 login/login/index.js   |   80 -------------
 utils/api.js           |  203 +++++++++++++--------------------
 map/index.js           |    8 
 utils/constant.js      |    4 
 5 files changed, 93 insertions(+), 212 deletions(-)

diff --git a/login/login/index.js b/login/login/index.js
index c32d257..2539aa2 100644
--- a/login/login/index.js
+++ b/login/login/index.js
@@ -12,15 +12,11 @@
     inputViewHeight: 100,
     inputWidth: 100,
     inputHeight: 100,
-
     userInfo: {},
-
     jsCode: null,
     canIUse: wx.canIUse('button.open-type.getUserInfo'),
-
     LogoUrl: Constant.Assets.Login.LogoUrl,
     BackgroupImageUrl: Constant.Assets.Login.BackgroupImageUrl,
-
     isShowPwd: false, //鏄惁鏄剧ず瀵嗙爜
     m_SoftWareVersion: Constant.SoftWareVersion
   },
@@ -39,8 +35,9 @@
   },
   // 璁颁綇瀵嗙爜妗�
   rememberPwd(e) {
+    this.data.checked = !this.data.checked
     this.setData({
-      checked: e.detail.value.includes('1')
+      checked: this.data.checked
     })
   },
   // 鑾峰彇杈撳叆鐢佃瘽鍙风爜
@@ -91,7 +88,6 @@
   //婕旂ず璐︽埛 
   loginByDemo: function (jsCode) {
     let that = this;
-
     var userInfo = this.data.userInfo;
     userInfo.EmployeeID = Constant.Assets.Login.DemoEmployeeID; //婕旂ず璐︽埛
     userInfo.CorpID = Constant.CorpID;
@@ -107,37 +103,16 @@
   loginByReal: function (jsCode) {
     let that = this;
     var userInfo = this.data.userInfo;
-    var sysInfo = app.globalData.sysInfo;
-    // console.log('鎵撳嵃userInfo', userInfo)
     wx.showToast({
       title: '鐧诲綍涓�',
       icon: "loading",
       duration: 3000
     });
-    // let data={
-    //   SoftType:Constant.SoftType,
-    //   SoftTag:Constant.SoftTag,
-    //   LoginName: this.data.phone,
-    //   LoginPwd: this.data.password,
-    //   CorpID: Constant.CorpID,
-    //   WxCode: jsCode,
-    //   UJsCode: jsCode, //鏄惁灏辨槸jsCode鏈夊緟纭
-    //   UAvatarUrl: userInfo == null ? "" : userInfo.avatarUrl,
-    //   UCity: userInfo == null ? "" : userInfo.city,
-    //   UProvince: userInfo == null ? "" : userInfo.province,
-    //   UNickName: userInfo == null ? "" : userInfo.nickName,
-    //   UGender: userInfo == null ? "" : userInfo.gender + "",
-    //   SBrand: sysInfo.brand,
-    //   SModel: sysInfo.model,
-    //   SPlatform: sysInfo.platform,
-    //   SVersion: sysInfo.version
-    // }
     let data = {
       LoginName: that.data.phone,
       LoginPwd: that.data.password,
       Software: Constant.Software
     }
-    // console.log(JSON.stringify(data),110)
     var post_url = Constant.BASE_AUTH_URL + "Auth/User/Login/LoginSoftwareStandardBySystemAccount@V1.0";
     wx.request({
       url: post_url,
@@ -155,12 +130,8 @@
         });
       },
       success: function (res) {
-        //  console.log(res,123)
-
         wx.hideToast();
-
         var result = res.data;
-        // console.log(result);
         if (result.Code != 0) {
           wx.showModal({
             content: "璐﹀彿瀵嗙爜涓嶆纭�",
@@ -169,7 +140,6 @@
           });
           return;
         }
-
         var return_data = result.Data;
         if (return_data.Status != 0) {
           wx.showModal({
@@ -185,7 +155,6 @@
         if (Token) {
           isNeedToken = true
         }
-
         let Checked = {}
         if (that.data.checked) {
           Checked = {
@@ -202,18 +171,11 @@
           ExpreTime: ExpreTime,
           isNeedToken: isNeedToken,
         })
-
         var return_user = return_data.User;
-        //console.log(return_user);
-
         userInfo.ID = return_user.ID
-        // userInfo.WxUserCode = return_user.LastLoginWxUserCode;
         userInfo.EmployeeID = return_user.EmployeeID; //浣跨敤鍛樺伐ID
         userInfo.CorpID = return_user.LoginAccount.ID;
         userInfo.RealName = return_user.Name;
-        // userInfo.Telphone = return_user.Telphone;
-        //console.log(userInfo);
-
         that.loginSuccessCb(userInfo);
       }
     });
@@ -221,14 +183,9 @@
   //鐧诲綍鎴愬姛
   loginSuccessCb: function (userInfo) {
     var that = this;
-    //console.log(userInfo,184)
     that.setData({
       userInfo: userInfo
     });
-    //
-    //if (wx.getStorageSync("LoginUserInfo")) {
-    //  app.globalData.userInfo = userInfo;
-    //}
     wx.setStorageSync("LoginUserInfo", userInfo);
     app.globalData.userInfo = userInfo;
     wx.showToast({
@@ -236,37 +193,14 @@
       icon: 'loading',
       duration: 1000
     })
-  
     wx.switchTab({
       url: '../../workDesktop/index/index',
     })
     app.onStartAlarm()
-
-    // var pages = getCurrentPages();
-    // if (pages.length >= 2) {
-    //   //var currPage = pages[pages.length - 1];   //褰撳墠椤甸潰
-    //   var prevPage = pages[pages.length - 2]; //杩斿洖涓婁竴涓〉闈�
-    //   //console.log(prevPage.route)
-    //   if (prevPage) {
-    //     var fn = prevPage.refreshUserInfo;
-    //     if (typeof fn == "function")
-    //       fn();
-    //     wx.navigateBack();
-    //   } else {
-    //     wx.navigateTo({
-    //       url: "/workDestop/index/index"
-    //     });
-    //   }
-    // } else {
-    //   wx.navigateBack();
-    // }
   },
   //鐐瑰嚮鐪熷疄鐢ㄦ埛鐧诲綍鎸夐挳
   tapBindUserReal: function (e) {
-    // console.log(e)
-
     let that = this;
-
     if (this.data.phone.length < 0 || this.data.password.length < 0) {
       wx.showToast({
         title: '鐢ㄦ埛鍚嶆垨瀵嗙爜涓嶈兘涓虹┖澶�!',
@@ -275,7 +209,6 @@
       });
       return;
     }
-
     if (this.data.phone.length < 2 || this.data.password.length < 5) {
       wx.showToast({
         title: '鐢ㄦ埛鍚嶅瘑鐮侀暱搴︿笉澶�!',
@@ -284,7 +217,6 @@
       });
       return;
     }
-
     wx.getUserProfile({
       desc: '鐢ㄤ簬鐧诲綍楠岃瘉', // 澹版槑鑾峰彇鐢ㄦ埛涓汉淇℃伅鍚庣殑鐢ㄩ�旓紝鍚庣画浼氬睍绀哄湪寮圭獥涓紝璇疯皑鎱庡~鍐�
       success: (res) => {
@@ -306,7 +238,6 @@
           that.setData({
             userInfo: res.userInfo,
           })
-
           that.getWxUserLoginCodeCb().then((loginParas) => {
             // console.log(loginParas.code)
             var jsCode = loginParas.code;
@@ -354,18 +285,11 @@
         }
       }
     })
-
   },
-
-
-
-
-
   // 鍔犺浇
   onLoad: function () {
     var that = this;
     var screenSize = app.globalData.screenSize;
-
     var screenWidth = screenSize.width;
     var screenHight = screenSize.height;
     var screenWidthScale = screenSize.width / 750;
diff --git a/login/login/index.wxml b/login/login/index.wxml
index fba147e..be15ac2 100644
--- a/login/login/index.wxml
+++ b/login/login/index.wxml
@@ -23,17 +23,21 @@
       <icon wx:if="{{!isShowPwd}}" class="cuIcon-attention" bindtap="changePwdView" style="font-size: 30rpx;line-height: 2;"></icon>
       <icon wx:else class="cuIcon-attentionforbid" bindtap="changePwdView" style="font-size: 30rpx;line-height: 2;"></icon>
     </view>
-    <view class="psdBox">
+    <!-- <view class="psdBox">
       <checkbox-group bindchange="rememberPwd">
       <checkbox value="1" checked="{{checked}}" />
       <label for="check">璁颁綇瀵嗙爜</label>
+    </checkbox-group>
+    </view> -->
+    <view class="psdBox" bindtap="rememberPwd">
+      <checkbox-group >
+      <checkbox value="1" checked="{{checked}}" style="width: 15px;height: 17px"/>
+      <label for="check" style="margin-left: 24rpx;">璁颁綇瀵嗙爜</label>
     </checkbox-group>
     </view>
   </view>
   <view class="loginBtnView">
     <button class="loginBtnReal" type="primary" bindtap="tapBindUserReal" style="background-color: #39b5de;">鐧诲綍</button>
-    <!-- <button class="loginBtnDemo" type="primary"  bindtap="tapBindUserDemo"
-      style="background-color: #B9D3EE;">婕旂ず</button> -->
   </view>
   <view class="explain call_style" style="display: flex; justify-content: center; align-items: center; flex-direction: column;">
     <label bindtap="call">褰撳墠鐗堟湰:
diff --git a/map/index.js b/map/index.js
index f7cc686..8498cee 100644
--- a/map/index.js
+++ b/map/index.js
@@ -13,11 +13,11 @@
     isLoad:false,
     //鍦板浘淇℃伅
     mapInfo: {
-      mapCenterLatitude: 31.09814, //鍦板浘涓績缁忕含搴�
-      mapCenterLongitude: 120.437185,
+      mapCenterLatitude: 31.121743, //鍦板浘涓績缁忕含搴�
+      mapCenterLongitude: 120.287392,
       markers: [], //鏍囪marker map
       Station: [], //娉电珯鍒楄〃
-      scale: 10, //鍦板浘鏀惧ぇ姣斾緥
+      scale: 12, //鍦板浘鏀惧ぇ姣斾緥
       pointsList: [], //鎵�鏈塵arker鐨勭粡绾害
       DMA: [], //DMA
       marker: {},
@@ -937,8 +937,6 @@
         break;
       }
     }
-
-    console.log(value,941)
     that.setData({
       'mapInfo.mapCenterLatitude': value.latitude,
       'mapInfo.mapCenterLongitude': value.longitude,
diff --git a/utils/api.js b/utils/api.js
index 4723800..91dd269 100644
--- a/utils/api.js
+++ b/utils/api.js
@@ -4,9 +4,7 @@
 let app = getApp()
 let ACCESS_TOKEN_KEY = 'AccessToken'
 let API = (params) => {
-  
   let tokenInfo = wx.getStorageSync(ACCESS_TOKEN_KEY)
-  
   let currentDateTime = new Date().getTime()
   if (!tokenInfo) {
     wx.reLaunch({
@@ -14,49 +12,35 @@
     })
     return
   }
-
   const token = tokenInfo.Token;
   const refresh_token = tokenInfo.RefreshToken
-
   if (!refresh_token) {
     wx.reLaunch({
       url: '/login/login/index',
     })
     return
   }
-
   //瑙f瀽token
   const jwt_token = decryptJWT(token);
   // 鑾峰彇token澶辨晥鏃堕棿
   const exp_token = getJWTDate(jwt_token.exp).getTime();
   // token澶辨晥鐘舵��
   const isExpireByToken = currentDateTime >= exp_token
-
   //瑙f瀽refreshtoken
   const jwt_refresh_token = decryptJWT(refresh_token);
   // 鑾峰彇refreshToken澶辨晥鏃堕棿
   const exp_refresh_token = getJWTDate(jwt_refresh_token.exp).getTime();
   // refreshToken澶辨晥鐘舵��
   const isExpireByRefreshToken = currentDateTime >= exp_refresh_token
-
-  // console.log(utils.formatTime(new Date()), utils.formatTime(getJWTDate(jwt_token.exp)), utils.formatTime(getJWTDate(jwt_refresh_token.exp)), 22)
-  // console.log(new Date().getTime() > getJWTDate(jwt.exp).getTime(), 22)
-
-
   // 鍒ゆ柇 token鍜宺efreshToken鏄惁閮藉け鏁�,閮藉け鏁堝垯璺宠浆鐧诲綍
   if ((isExpireByToken && isExpireByRefreshToken) && tokenInfo.isNeedToken) {
-    wx.reLaunch({
-      url: '/login/login/index',
-    })
-    return
+    RefreshToken()
   }
-
   // 鍒ゆ柇 token 澶辨晥浣唕efreshToken娌″け鏁�
   if ((!isExpireByToken && isExpireByRefreshToken) && tokenInfo.isNeedToken) {
     tokenInfo.Token = refresh_token
     wx.setStorageSync(ACCESS_TOKEN_KEY, tokenInfo)
   }
-
   let defaultParams = {
     url: '',
     method: "GET",
@@ -68,7 +52,6 @@
     fail: function () {},
     complete: function () {}
   }
-
   let requestParam = Object.assign(defaultParams, params)
   // 鍒ゆ柇鏄惁瑕佹坊鍔爐oken
   if (tokenInfo.isNeedToken == true) {
@@ -86,30 +69,29 @@
         return
       }
       if (result.Code && result.Code != 0) {
-     if(result.Code==-3){
-      wx.showModal({
-        title: result.Message,
-        complete: (res) => {
-          if (res.cancel) {
-            
-          }
-      
-          if (res.confirm) {
-            
-          }
-        }
-      })
+        if (result.Code == -3) {
+          wx.showModal({
+            title: result.Message,
+            complete: (res) => {
+              if (res.cancel) {
 
-     }
-     else{
-      wx.showToast({
-        title: result.Message,
-        icon: 'error',
-        duration: 1500
-      })
-      RefreshToken()
-      return
-     }
+              }
+
+              if (res.confirm) {
+
+              }
+            }
+          })
+
+        } else {
+          wx.showToast({
+            title: result.Message,
+            icon: 'error',
+            duration: 1500
+          })
+          RefreshToken()
+          return
+        }
       }
       requestParam.success(res)
     },
@@ -123,92 +105,65 @@
 
 }
 const RefreshToken = () => {
-  wx.reLaunch({
-    url: '/login/login/index',
-  })
-  return
-
   // 鑾峰彇璐︽埛淇℃伅
-  // let accountInfo = JSON.parse(wx.getStorageSync("AccountInfo"))
-
-  // console.log(accountInfo,60)
+  let accountInfo = wx.getStorageSync("AccountInfo")
   // 鑾峰彇鐧诲綍鐨勭敤鎴蜂俊鎭�
-  // let userInfo = wx.getStorageSync("LoginUserInfo");
-  // let sysInfo = app.globalData.sysInfo;
-  // console.log('鎵撳嵃userInfo', userInfo)
-  // let data = {
-  //   SoftType: Constant.SoftType,
-  //   SoftTag: Constant.SoftTag,
-  //   LoginName: accountInfo.LoginName,
-  //   LoginPwd: accountInfo.LoginPwd,
-  //   CorpID: Constant.CorpID,
-  //   WxCode: accountInfo.WxCode,
-  //   UJsCode: accountInfo.UJsCode, //鏄惁灏辨槸jsCode鏈夊緟纭
-  //   UAvatarUrl: userInfo == null ? "" : userInfo.avatarUrl,
-  //   UCity: userInfo == null ? "" : userInfo.city,
-  //   UProvince: userInfo == null ? "" : userInfo.province,
-  //   UNickName: userInfo == null ? "" : userInfo.nickName,
-  //   UGender: userInfo == null ? "" : userInfo.gender + "",
-  //   SBrand: sysInfo.brand,
-  //   SModel: sysInfo.model,
-  //   SPlatform: sysInfo.platform,
-  //   SVersion: sysInfo.version
-  // }
+  let data = {
+    LoginName: accountInfo.phone,
+    LoginPwd: accountInfo.password,
+    Software: Constant.Software
+  }
   // console.log(JSON.stringify(data),110)
-  // wx.request({
-  //   url: Constant.BASE_SERVER_URL + "User/UserLogin/FromCorpWechatApplet@V1.0",
-  //   method: 'POST',
-  //   data: data,
-  //   header: {
-  //     'content-type': 'application/json'
-  //   },
-  //   fail: function (err) { //璇锋眰澶辫触
-  //     wx.showModal({
-  //       content: '缃戠粶淇″彿涓嶅ソ',
-  //       showCancel: false,
-  //       confirmColor: "#39b5de"
-  //     });
-  //   },
-  //   success: function (res) {
-  //     console.log(res, "鏂扮殑token淇℃伅")
-
-  //     var result = res.data;
-  //     // console.log(result);
-  //     if (result.Code != 0) {
-  //       wx.showToast({
-  //         title: 'token鑾峰彇澶辫触锛岃閲嶆柊鐧诲綍',
-  //         icon: "none",
-  //         duration: 2000
-  //       })
-  //       return;
-  //     }
-
-  //     var return_data = result.Data;
-  //     if (return_data.Status != 0) {
-  //       wx.showToast({
-  //         title: 'token鑾峰彇澶辫触锛岃閲嶆柊鐧诲綍',
-  //         icon: "none",
-  //         duration: 2000
-  //       })
-  //       return;
-  //     }
-  //     let Token = return_data.Token
-  //     let isNeedToken = false //鏄惁闇�瑕乀oken 褰揟oken澶辨晥鐨勬椂鍊� 鍒ゆ柇鏄惁璺宠浆鐧诲綍
-  //     if (Token) {
-  //       isNeedToken = true
-  //     }
-  //     let ExpreTime = new Date().getTime() //鑾峰彇褰撳墠鏃堕棿鎴�
-
-  //     wx.setStorageSync('AccessToken', {
-  //       Token: Token,
-  //       ExpreTime: ExpreTime,
-  //       isNeedToken: isNeedToken
-  //     })
-  //     wx.setStorageSync("AccountInfo", JSON.stringify(data))
-  //     // 鑾峰彇鏂扮殑token鍚庨噸鏂拌皟鐢ㄦ帴鍙�
-  //     apiCb(params)
-  //   }
-  // });
+  wx.request({
+    url: Constant.BASE_AUTH_URL + "Auth/User/Login/LoginSoftwareStandardBySystemAccount@V1.0",
+    method: 'POST',
+    data: data,
+    header: {
+      'content-type': 'application/json'
+    },
+    fail: function (err) { //璇锋眰澶辫触
+      wx.showModal({
+        content: '缃戠粶淇″彿涓嶅ソ',
+        showCancel: false,
+        confirmColor: "#39b5de"
+      });
+    },
+    success: function (res) {
+      // console.log(res, "鏂扮殑token淇℃伅")
+      var result = res.data;
+      // console.log(result);
+      if (result.Code != 0) {
+        wx.showToast({
+          title: 'token鑾峰彇澶辫触锛岃閲嶆柊鐧诲綍',
+          icon: "none",
+          duration: 2000
+        })
+        return;
+      }
+      var return_data = result.Data;
+      if (return_data.Status != 0) {
+        wx.showToast({
+          title: 'token鑾峰彇澶辫触锛岃閲嶆柊鐧诲綍',
+          icon: "none",
+          duration: 2000
+        })
+        return;
+      }
+      let Token = return_data.AccessToken
+      let RefreshToken = return_data.RefreshToken
+      let isNeedToken = false //鏄惁闇�瑕乀oken 褰揟oken澶辨晥鐨勬椂鍊� 鍒ゆ柇鏄惁璺宠浆鐧诲綍
+      if (Token) {
+        isNeedToken = true
+      }
+      let ExpreTime = new Date().getTime() //鑾峰彇褰撳墠鏃堕棿鎴�
+      wx.setStorageSync('AccessToken', {
+        Token: Token,
+        RefreshToken: RefreshToken,
+        ExpreTime: ExpreTime,
+        isNeedToken: isNeedToken,
+      })    
+    }
+  })
 }
 
 //瑙e瘑 JWT token 鐨勪俊鎭�
diff --git a/utils/constant.js b/utils/constant.js
index 14b615c..11fb6bb 100644
--- a/utils/constant.js
+++ b/utils/constant.js
@@ -6,8 +6,8 @@
 var TencenteMapKey = "GFDBZ-D3NKX-LNL4Z-TSWGU-RYCE3-4HB3I";
 var IMAGE_ROOT_URL = "https://www.xpump.net/ProductLibraryFile/";
 
-var SOFTWARE_VERSION = "1.24.0514A";
-var UPDATE_TIME = "1.24.0514A";
+var SOFTWARE_VERSION = "1.24.0829A";
+var UPDATE_TIME = "1.24.0829A";
 // 灏嗘柟娉曘�佸彉閲忔毚闇插嚭鍘�
 module.exports = {
   BASE_SERVER_URL: BASE_SERVER_URL,

--
Gitblit v1.9.3