3 Commits dd21923cd5 ... 90f9bfa547

Auteur SHA1 Bericht Datum
  Rorschach 90f9bfa547 'getUserInfo接口修改' 3 jaren geleden
  Rorschach d583993f0b Merge branch 'loginFix' into simple2.0 3 jaren geleden
  Rorschach cf76dee9ee '1' 3 jaren geleden

+ 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;
 }

+ 11 - 7
pages/index/index.js

@@ -340,6 +340,9 @@ Page({
           }, () => {
             this.showPage();
           })
+        } else {
+          console.log('游客未登录有年纪')
+          this.showPage();
         }
       }
       // 登录或注册完成 展示页面
@@ -433,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');
@@ -441,7 +445,7 @@ Page({
         fromLoginIndex: null,
         isLogin: userInfo.wechatName ? true : false
       }, () => {
-        this.updateData(0)
+        this.updateData(index)
       })
     }
     if (this.data.fromReading) {
@@ -1119,13 +1123,13 @@ Page({
     httpRequestApi.postActEvent('BANNER').success(res => {
       console.log('活动banner', res)
     })
-    wx.navigateTo({
-      url: `../activity/index/index`
-      // url: `../activity/rule/rule`
-    });
     // wx.navigateTo({
-    //   url: `../activity/goodList/goodList`
+    //   url: `../activity/index/index`
+    //   // url: `../activity/rule/rule`
     // });
+    wx.navigateTo({
+      url: `../activity/goodList/goodList`
+    });
   },
   /**
    * banner点击

+ 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">

+ 118 - 6
pages/login/login.js

@@ -2,13 +2,23 @@
 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
   },
 
   /**
@@ -16,11 +26,113 @@ Page({
    */
 
   onLoad: function (options) {
-    if(options.index){
+    if (options.index) {
       this.setData({
         index: options.index
       })
     }
+    if (wx.getUserProfile) {
+      this.setData({
+        canIUseGetUserProfile: true
+      })
+    }
+  },
+  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: (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
+              })
+            })
+          });
+        })
+        // 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)
+        }
+      }
+    })
   },
   impower: function (e) {
     console.log(e)
@@ -36,11 +148,11 @@ Page({
           const pages = getCurrentPages();
           const prevPage = pages[pages.length - 2];
           prevPage.setData({
-              fromLoginIndex: this.data.index, // 有id就塞到第一位
+            fromLoginIndex: this.data.index, // 有id就塞到第一位
           }, () => {
-              wx.navigateBack({
-                  delta: 1
-              })
+            wx.navigateBack({
+              delta: 1
+            })
           })
         }
       })

+ 4 - 1
pages/login/login.wxml

@@ -5,6 +5,9 @@
         <!-- <image class="head-bg" src="../../static/image/reader_logo.jpg" style="background: red;"></image> -->
         <view class="text">使用您的微信登录</view>
         <!-- <view class="shuoming">获得你的公开信息(昵称、头像等)</view> -->
-        <button class="btn"  open-type="getUserInfo" bindgetuserinfo="impower">登录</button>
+
+        <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 - 3
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,12 +111,12 @@ 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;
             getLoginSchedule(sessionKey, openId, successcallback, failcallback);
         }
-
     }, function (res) {
         failcallback(res);
     })