瀏覽代碼

'getUserInfo接口修改'

Rorschach 3 年之前
父節點
當前提交
90f9bfa547

+ 1 - 0
component/video-swiper/index.js

@@ -299,6 +299,7 @@ Component({
         },
         // 去朗读
         goToReading: function goToReading(e) {
+            console.log('111222')
             this.trigger(e, 'goToReading')
         },
         // 收藏课程

+ 1 - 1
pages/activity/goodList/goodList.wxss

@@ -6,6 +6,6 @@
 }
 .good_list image {
   width: 100%;
-  height: 2863rpx;
+  height: 3624rpx;
   display: block;
 }

+ 3 - 2
pages/index/index.js

@@ -436,7 +436,8 @@ Page({
     wx.setNavigationBarTitle({
       title: '小学语文朗读配音'
     })
-    if (this.data.fromLoginIndex) {
+    console.log('页面返回页面返回', this.data.fromLoginIndex)
+    if (this.data.fromLoginIndex || this.data.fromLoginIndex == 0) {
       console.log('页面返回页面返回', this.data.fromLoginIndex)
       let index = this.data.fromLoginIndex;
       let userInfo = wx.getStorageSync('user');
@@ -444,7 +445,7 @@ Page({
         fromLoginIndex: null,
         isLogin: userInfo.wechatName ? true : false
       }, () => {
-        this.updateData(0)
+        this.updateData(index)
       })
     }
     if (this.data.fromReading) {

+ 1 - 1
pages/index/index.wxml

@@ -48,7 +48,7 @@
   
   <!-- <view hidden="{{gradeActivity === 'PRIMARY_SENIOR_GRADE' || gradeActivity === 'PRESCHOOL' || 0 != myIndex}}" class="activity-img" bindtap="goToActivity"> -->
   <view hidden="{{0 != myIndex}}" class="activity-img" bindtap="goToActivity">
-    <image src="http://reader-wx.ai160.com/images/reader/activity/banner61.jpg"></image>
+    <image src="http://reader-wx.ai160.com/images/reader/activity/banner.jpg"></image>
   </view>
  
   <!-- <view hidden="{{(!isIos && isVip) || 0 != myIndex }}" class="activity-img" bindtap="bannerTap">

+ 100 - 30
pages/login/login.js

@@ -2,13 +2,22 @@
 import {
   getOpenidSessionKey
 } from '../../utils/httpUtil';
+import url from '../../utils/const';
+import request from '../../utils/WXHttpRequest';
+
+const HOST = url.baseApi;
+
+
+function getAPIUrl(action) {
+  return HOST + action;
+}
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    index: undefined,
+    index: 0,
     canIUseGetUserProfile: false
   },
 
@@ -28,39 +37,100 @@ Page({
       })
     }
   },
+  userLoginRecord: function (uid) {
+    if (wx.getStorageSync('uid')) {
+      console.log('调用方法')
+      let url = getAPIUrl('wx/loginLog');
+      return request.getInstance().header({
+        uid: wx.getStorageSync('uid')
+      }).method('POST').url(url).send().success(() => {}).fail(() => {});
+    }
+  },
   getUserProfile: function (e) {
     wx.getUserProfile({
       desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
-      success: (res) => {
-        console.log('getUserProfile',res);
-        getOpenidSessionKey((res) => {
-          console.log('getUserProfilegetUserProfile',res)
-          wx.showToast({
-            title: '登录成功',
-            icon: 'fail',
-            duration: 1000,
-            success: () => {
-              const pages = getCurrentPages();
-              const prevPage = pages[pages.length - 2];
-              prevPage.setData({
-                fromLoginIndex: this.data.index, // 有id就塞到第一位
-              }, () => {
-                wx.navigateBack({
-                  delta: 1
-                })
+      success: (userProfile) => {
+        console.log('getUserProfile', userProfile);
+        const userInfo = userProfile.userInfo;
+        this.getOpenId((openidData) => {
+          console.log('openid', openidData)
+          let url = getAPIUrl('wx/user');
+          const userData = {
+            openId: openidData.data.data.openid,
+            unionId: openidData.data.data.unionid,
+            wechatName: userInfo.nickName,
+            gender: userInfo.gender,
+            avatar: userInfo.avatarUrl
+          }
+          request.getInstance().url(url).header({}).data(userData).method('POST').send().success(res => {
+            console.log('登陆成功', res)
+            wx.hideToast()
+            wx.showToast({
+              title: '登录成功',
+              icon: 'success',
+              duration: 1500,
+              mask: true
+            })
+            wx.setStorageSync('uid', res.data.data.data.uid)
+            wx.setStorageSync('user', res.data.data.data)
+            this.userLoginRecord();
+            const pages = getCurrentPages();
+            const prevPage = pages[pages.length - 2];
+            console.log(222222, prevPage)
+            prevPage.setData({
+              fromLoginIndex: this.data.index, // 有id就塞到第一位
+            }, () => {
+              wx.navigateBack({
+                delta: 1
               })
-            }
-          })
-        }, (error) => {
-          wx.showToast({
-            title: '登录失败',
-            icon: 'fail',
-            duration: 1000,
-            success: () => {
-              wx.navigateBack()
-            }
-          })
-        });
+            })
+          });
+        })
+        // getOpenidSessionKey((res) => {
+        //   console.log('getUserProfilegetUserProfile', res)
+        //   wx.showToast({
+        //     title: '登录成功',
+        //     icon: 'fail',
+        //     duration: 1000,
+        //     success: () => {
+        //       const pages = getCurrentPages();
+        //       const prevPage = pages[pages.length - 2];
+        //       prevPage.setData({
+        //         fromLoginIndex: this.data.index, // 有id就塞到第一位
+        //       }, () => {
+        //         wx.navigateBack({
+        //           delta: 1
+        //         })
+        //       })
+        //     }
+        //   })
+        // }, (error) => {
+        //   wx.showToast({
+        //     title: '登录失败',
+        //     icon: 'fail',
+        //     duration: 1000,
+        //     success: () => {
+        //       wx.navigateBack()
+        //     }
+        //   })
+        // });
+      }
+    })
+  },
+  getOpenId: function (successcallback, failcallback) {
+    wx.login({
+      success: function (res) {
+        if (res.code) {
+          // 获取openid
+          console.log('openId', res.code)
+          let url = getAPIUrl('wx/user/openId')
+          let data = {
+            code: res.code
+          }
+          return request.getInstance().url(url).data(data).send().success(successcallback).fail(failcallback);
+        } else {
+          console.log('获取用户登录态失败!' + res.errMsg)
+        }
       }
     })
   },

+ 1 - 0
pages/login/login.wxml

@@ -8,5 +8,6 @@
 
         <button class="btn"  wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile">登录</button>
         <button class="btn"  wx:else open-type="getUserInfo" bindgetuserinfo="impower">登录</button>
+        <!-- <button class="btn"  open-type="getUserInfo" bindgetuserinfo="impower" bindtap="getUserProfile">登录</button> -->
     </view>
 </view>

+ 1 - 2
utils/httpUtil.js

@@ -43,7 +43,6 @@ function userLoginRecord(uid) {
             uid: wx.getStorageSync('uid')
         }).method('POST').url(url).send().success(() => {}).fail(() => {});
     }
-
 }
 //登录
 function getLoginSchedule(sessionKey, openId, successcallback, failcallback) {
@@ -88,7 +87,6 @@ function getLoginSchedule(sessionKey, openId, successcallback, failcallback) {
                         wx.setStorageSync('user', res.data.data.data)
                         userLoginRecord()
                         successcallback(res)
-
                     });
                 },
                 fail: function (res) {
@@ -113,6 +111,7 @@ function getOpenidSessionKey(successcallback, failcallback) {
     //     return;
     // }
     wxLogin(function (res) {
+        console.log('wxlogin123123123123',res)
         if (res.data.code == 200) {
             let sessionKey = res.data.data.session_key;
             let openId = res.data.data.openid;