소스 검색

首次绑定页面生命周期代码处理

QAQ 陈 3 달 전
부모
커밋
38ea42dadf
1개의 변경된 파일52개의 추가작업 그리고 1개의 파일을 삭제
  1. 52 1
      pages/FirstBangDing/FirstBangDing.js

+ 52 - 1
pages/FirstBangDing/FirstBangDing.js

@@ -50,7 +50,58 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-
+    const _this = this;
+    // 重新获取用户信息
+    wx.login({
+      success: res => {
+        if(res.code){
+          wx.request({
+            method: 'POST',
+            url: app.globalData.interfaceUrls.loginUrl,
+            data: {
+              wxCode: res.code,
+              dsKey: app.globalData.launchPara
+            },
+            success(res) {
+              if (res.data.code == "200" && res.data.data) {
+                const resData = res.data.data;
+                // 更新全局用户信息
+                app.globalData.userWxInfo = {
+                  openid: resData.openid,
+                  session_key: resData.session_key,
+                  token: resData.token,
+                  bindAccountInfo: resData.swUserManagementVos,
+                  currentDsKey: ""
+                }
+                
+                // 检查是否有绑定的户号
+                if(resData.swUserManagementVos && resData.swUserManagementVos.length > 0){
+                  app.globalData.currentAccountInfo = resData.swUserManagementVos[0];
+                  app.globalData.userWxInfo.currentDsKey = resData.swUserManagementVos[0].dsKey;
+                  // 保存到本地存储
+                  wx.setStorageSync('currentHuHao', resData.swUserManagementVos[0]);
+                  // 设置刷新标记
+                  app.globalData.refresh = 1;
+                  
+                  // 跳转到首页
+                  wx.switchTab({
+                    url: '/pages/homepage/homepage',
+                    success: function() {
+                      // 确保首页重新加载数据
+                      const pages = getCurrentPages();
+                      const homepage = pages[pages.length - 1];
+                      if (homepage && homepage.onLoad) {
+                        homepage.onLoad();
+                      }
+                    }
+                  });
+                }
+              }
+            }
+          });
+        }
+      }
+    });
   },
 
   /**