From 2c08a98f7e85ec7c9376f27a7933e75e44d672f7 Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期二, 27 八月 2024 15:52:59 +0800
Subject: [PATCH] ll

---
 wechat_staff/pages/login/index.js |   85 +++++++++++++++++++++++++++++-------------
 1 files changed, 59 insertions(+), 26 deletions(-)

diff --git a/wechat_staff/pages/login/index.js b/wechat_staff/pages/login/index.js
index 084b641..d7b0acd 100644
--- a/wechat_staff/pages/login/index.js
+++ b/wechat_staff/pages/login/index.js
@@ -3,7 +3,8 @@
   getDictData,
   getWxMiniPhone,
   loginByPhone,
-  bindingOpenid
+  bindingOpenid,
+  wxLoginCustomer
 } from '../../api/index'
 Page({
 
@@ -16,6 +17,7 @@
     status: '0', // 鏍囪瘑
     countDown: 0,
     phone: '',
+    openid:'',
     code: '',
     showModal: false,
     activeHtml: '',
@@ -54,6 +56,9 @@
       }, 1000)
     })
   },
+  onShow(){
+    wx.hideHomeButton()
+  },
   handleJudge(e) {
     const flag = e.currentTarget.dataset.flag
     console.log(e);
@@ -62,7 +67,8 @@
   loginPhone() {
     const {
       code,
-      phone
+      phone,
+      openid
     } = this.data
     if (!this.data.agreementFalg) {
       return wx.showToast({
@@ -85,17 +91,18 @@
 
     loginByPhone({
       code,
+      openid,
       phone
     }).then(res => {
       if (res.data && res.data.token) {
-        wx.login({
-          timeout: 5000,
-          success: (loginRes) =>  {
-            if (loginRes.code) {
-              this.bindingOpenid(loginRes.code, res.data.token)
-            }
-          }
-        })
+        // wx.login({
+        //   timeout: 5000,
+        //   success: (loginRes) =>  {
+        //     if (loginRes.code) {
+        //       this.bindingOpenid(loginRes.code, res.data.token)
+        //     }
+        //   }
+        // })
         if(res.data.phone){
           res.data.users.phone = res.data.phone || res.data.users.phone
         }
@@ -112,6 +119,7 @@
       }else{
         wx.showToast({
           title: '浣犺繕涓嶆槸璇ョ郴缁熺敤鎴凤紝璇疯仈绯荤浉鍏崇鐞嗗憳娉ㄥ唽',
+          icon: 'none'
         })
       }
     })
@@ -132,7 +140,45 @@
       primary: app.primary,
       bottomLift: app.bottomLift
     })
+    this.autoLogin()
     this.initData()
+  },
+  autoLogin(){
+    var that =this
+    wx.login({
+      timeout: 5000,
+      success(res) {
+        if (res.code) {
+          //鍙戣捣缃戠粶璇锋眰
+          wxLoginCustomer({
+            code: res.code
+          }).then(res => {
+            console.log(res)
+            wx.setStorageSync('sessionKey', res.data.sessionKey)
+            that.setData({openid:res.data.openid})
+            if (res && res.data !=null && res.data.token!=null) { 
+              console.log(res)
+              wx.hideLoading()
+              wx.setStorageSync('member', res.data.users || '')
+              wx.setStorageSync('token', res.data.token || '')
+              wx.switchTab({
+                url: '/pages/index/index',
+              }) 
+            } 
+          })
+        } else {
+          wx.reLaunch({
+            url: '/pages/login/index',
+          })
+          wx.hideLoading()
+          console.log('鐧诲綍澶辫触锛�' + res)
+        }
+      },
+      fail(err) {
+        wx.hideLoading()
+        console.log(err)
+      }
+    })
   },
   getPhoneNumber(e) {
     const data = {
@@ -141,17 +187,10 @@
     getWxMiniPhone({
       encryptedData: data.encryptedData,
       iv: data.iv,
+      openid:this.data.openid,
       sessionKey: wx.getStorageSync('sessionKey'),
     }).then(res => {
-      if (res.data && res.data.token) {
-        wx.login({
-          timeout: 5000,
-          success: (loginRes) =>  {
-            if (loginRes.code) {
-              this.bindingOpenid(loginRes.code, res.data.token)
-            }
-          }
-        })
+      if (res.data && res.data.token) { 
         if(res.data.phone){
           res.data.users.phone = res.data.phone || res.data.users.phone
         }
@@ -163,6 +202,7 @@
       }else{
         wx.showToast({
           title: '浣犺繕涓嶆槸璇ョ郴缁熺敤鎴凤紝璇疯仈绯荤浉鍏崇鐞嗗憳娉ㄥ唽',
+          icon: 'none'
         })
       }
 
@@ -223,13 +263,6 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
   onReady() {
-
-  },
-
-  /**
-   * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
-   */
-  onShow() {
 
   },
 

--
Gitblit v1.9.3