From a82b8c09ca795a4b6273b03a79ba488f6cce5eb0 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 11 八月 2022 15:54:21 +0800
Subject: [PATCH] 微信一键登录

---
 pages/module_user/userlogin/userlogin.js |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/pages/module_user/userlogin/userlogin.js b/pages/module_user/userlogin/userlogin.js
index 3c122d1..f3b05bc 100644
--- a/pages/module_user/userlogin/userlogin.js
+++ b/pages/module_user/userlogin/userlogin.js
@@ -34,7 +34,71 @@
   },
 
   loginWx() {
+    var that = this
+    wx.getUserProfile({
+      lang: 'zh_CN',
+      desc: '鐢ㄤ簬鏄剧ず锛屾彁绀虹敤鎴峰綋鍓嶅凡鐧诲綍',
+      success(res) {
+        //鑾峰彇缂撳瓨鐨勭敤鎴疯处鎴峰瘑鐮�
+    wx.getStorage({
+      key: 'accessToken',
+      success(res) {
+        app.globalData.accessToken = res.data
+        that.setData({
+          userName: res.data.userName,
+          password: res.data.password
+        })
 
+        userservice.login(that.data.userName, that.data.password, {
+          success (data) {
+            if (data.success) {
+              app.globalData.accessToken = {
+                userName: that.data.userName,
+                password: that.data.password,
+                userId: data.userId,
+                suserId: data.suserId,
+              }
+              wx.setStorage({
+                key: 'accessToken',
+                data: app.globalData.accessToken,
+              })
+              that.getUserInfo()
+            } else {
+              wx.showToast({
+                title: '璐︽埛鎴栧瘑鐮侀敊璇�',
+                duration: 1000,
+                icon: 'none',
+              })
+            }
+          },
+          complete () {
+            that.setData({
+              loading: false
+            })
+          }
+        })
+      },
+    })
+      }
+    })
+  },
+
+  getUserInfo() {
+    var that = this
+    userservice.getUserInfo(app.globalData.accessToken.userId, {
+      success(data) {
+        app.globalData.userInfo = data
+        wx.setStorage({
+          key: 'userInfo',
+          data: data,
+          success: (result) => {
+            wx.switchTab({
+              url: '/pages/home/home',
+            })
+          }
+        })
+      }
+    })
   },
 
   gotoLogin() {

--
Gitblit v1.9.3