Rorschach 4 years ago
parent
commit
facc8e3dc5

+ 28 - 4
component/video-swiper/index.js

@@ -8,7 +8,7 @@ Component({
         pureDataPattern: /^_/
     },
     properties: {
-        ifHeadTap:{
+        ifHeadTap: {
             type: Boolean,
             value: true
         },
@@ -181,12 +181,18 @@ Component({
         },
         // 点击头部
         headTap: function headTap(e) {
+            if (!wx.getStorageSync('user').wechatName) {
+                wx.navigateTo({
+                    url: `../../pages/login/login`
+                });
+                return;
+            }
             let uid = e.target.dataset.uid ? e.target.dataset.uid : e.currentTarget.dataset.uid;
             // this.trigger(e, 'headTap')
-            console.log('点击头像',e)
+            console.log('点击头像', e)
             wx.navigateTo({
                 url: `../../pages/user/myworks/myworks?uid=${uid}`
-              });
+            });
         },
         // 去朗读
         goToReading: function goToReading(e) {
@@ -194,6 +200,12 @@ Component({
         },
         // 收藏课程
         collectTap: function collectClass(e) {
+            if (!wx.getStorageSync('user').wechatName) {
+                wx.navigateTo({
+                    url: `../../pages/login/login`
+                });
+                return;
+            }
             console.log('收藏按钮', e);
             const data = {
                 targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
@@ -211,8 +223,14 @@ Component({
         },
         // 点赞
         likeTap: function likeTap(e) {
+            if (!wx.getStorageSync('user').wechatName) {
+                wx.navigateTo({
+                    url: `../../pages/login/login`
+                });
+                return;
+            }
             const isLike = e.target.dataset.islike ? e.target.dataset.islike : e.currentTarget.dataset.islike;
-            console.log('isLike',isLike)
+            console.log('isLike', isLike)
             if (isLike) {
                 return;
             }
@@ -231,6 +249,12 @@ Component({
         },
 
         trigger: function trigger(e, type) {
+            if (!wx.getStorageSync('user').wechatName) {
+                wx.navigateTo({
+                    url: `../../pages/login/login`
+                });
+                return;
+            }
             var ext = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
 
             // var detail = e.detail;

+ 40 - 29
pages/index/index.js

@@ -107,30 +107,16 @@ Page({
       })
       return;
     }
-    // 刷新资源
-    if (myIndex == 2) {
-      this.setData({
-        videoList: [],
-        templates: 'courses'
-      }, () => {
-        this.getCoursesList();
-      })
-      return;
-    }
 
     /* 关注和我的需要登陆后查看 */
 
-    getOpenidSessionKey((res) => {}, (error) => {
-      console.log('获取信息失败', error)
-      wx.setStorageSync('userSourseType', 'normal')
-      // this.setData({
-      //   hide: !this.data.hide
-      // })
+    if (!this.data.isLogin) {
       wx.navigateTo({
         url: `../../pages/login/login`
       });
       return;
-    });
+    }
+
     console.log('继续')
     // 刷新关注列表
     if (myIndex == 1) {
@@ -142,6 +128,16 @@ Page({
       })
       return;
     }
+    // 刷新资源
+    if (myIndex == 2) {
+      this.setData({
+        videoList: [],
+        templates: 'courses'
+      }, () => {
+        this.getCoursesList();
+      })
+      return;
+    }
     // 刷新我的
     if (myIndex == 3) {
       this.setData({
@@ -156,9 +152,9 @@ Page({
 
 
   },
-  showPage: function(){
+  showPage: function () {
     let options = this.data.options;
-    if (options.index) {
+    if (options && options.index) {
       this.updateData(options.index)
     } else {
       this.updateData(0)
@@ -204,7 +200,7 @@ Page({
     let grade = wx.getStorageSync('grade');
 
     let user = wx.getStorageSync('user');
-    if(!this.uid || !grade){
+    if (!this.uid || !grade) {
       this.setData({
         isGradeShow: true,
         options
@@ -213,10 +209,10 @@ Page({
       return;
     }
     this.showPage()
-    if(this.uid && !user){
+    if (this.uid && !user) {
       console.log('游客状态')
     }
-    if(this.uid && user){
+    if (this.uid && user) {
       console.log('登陆状态')
     }
     wx.getSystemInfo({
@@ -243,7 +239,16 @@ Page({
     wx.setNavigationBarTitle({
       title: '小学语文朗读配音'
     })
-
+    const userInfo = wx.getStorageSync('user')
+    if (userInfo.wechatName) {
+      this.setData({
+        isLogin: true
+      })
+    } else {
+      this.setData({
+        isLogin: false
+      })
+    }
   },
 
   onHide: function () {
@@ -488,11 +493,11 @@ Page({
         temp.img = item.iconImg;
         temp.plays = item.playAmount;
         temp.likes = item.likeAmount;
-        temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
+        temp.classId = item.exampleId ? item.exampleId : 1605097720036046;
         temp.time = formatDate(item.gmtCreated, 3);
         temp.avatar = this.data.userInfo.avatar;
         temp.uid = this.uid;
-        temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
+        temp.url = item.videoPath;
         temp.id = item.id;
         // temp.avatar = item.user.avatar;
         temp.nickName = this.data.userInfo.wechatName;
@@ -588,7 +593,7 @@ Page({
       isGradeShow: false,
     })
     getOpenidNoLogin((res) => {
-      console.log('getOpenidNoLogin',res)
+      console.log('getOpenidNoLogin', res)
       // 登录或注册完成 展示页面
       this.showPage()
     }, (error) => {
@@ -597,7 +602,7 @@ Page({
       this.setData({
         hide: !this.data.hide
       })
-    },grade);
+    }, grade);
   },
 
   getFollowData: function () {
@@ -641,7 +646,12 @@ Page({
     })
   },
   getCoursesList: function () {
-    httpRequestApi.getCourses('PRIMARY_FIRST_GRADE', 1, 10).success(res => {
+    const grade = wx.getStorageSync('grade');
+    const data = {
+      grade,
+      type: 'EXAMPLE'
+    }
+    httpRequestApi.getClassRead(data).success(res => {
       console.log('资源', res)
       this.setData({
         coursesData: res.data.data.list
@@ -652,8 +662,9 @@ Page({
   },
   goToReading: function (e) {
     console.log('去朗读', e)
+    const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
     wx.navigateTo({
-      url: `../../pages/main/reading/reading?id=${e.detail.activeId}`
+      url: `../../pages/main/reading/reading?id=${id}`
     });
   },
 

+ 36 - 19
pages/login/login.js

@@ -1,26 +1,43 @@
 // pages/login/login.js
+import {
+  getOpenidSessionKey
+} from '../../utils/httpUtil';
 Page({
 
-  /**
-   * 页面的初始数据
-   */
-  data: {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
-
-  onLoad: function (options) {
-
-  },
-  impower: function (e) {
-    console.log(e)
-    var myEventDetail = {} // detail对象,提供给事件监听函数
-    var myEventOption = {} // 触发事件的选项
+      /**
+       * 页面的初始数据
+       */
+      data: {
+
+      },
+
+      /**
+       * 生命周期函数--监听页面加载
+       */
+
+      onLoad: function (options) {
+
+      },
+      impower: function (e) {
+        console.log(e)
+        var myEventDetail = {} // detail对象,提供给事件监听函数
+        var myEventOption = {} // 触发事件的选项
+        getOpenidSessionKey((res) => {
+          wx.showToast({
+            title: '登录成功',
+            icon: 'fail',
+            duration: 500
+          })
+          wx.navigateBack()
+        }, (error) => {
+          wx.showToast({
+            title: '登录失败',
+            icon: 'fail',
+            duration: 500
+          })
+      });
   },
-  touchMove: function(){
+  touchMove: function () {
     return false
   },
   /**

+ 4 - 4
templates/courses/courses.wxml

@@ -1,14 +1,14 @@
 <!-- <wxs src="../../pages/commonWxs/format.wxs" module="format" /> -->
 <template name="courses">
     <view class="courses_container">
-        <view class="course_item" bindtap="goToReading" wx:for="{{coursesData}}" data-id="{{item.lesson.id}}" wx:key="index">
-            <image class="course_icon" src="{{item.lesson.iconImg}}" lazy-load="true" />
+        <view class="course_item" bindtap="goToReading" wx:for="{{coursesData}}" data-id="{{item.userRead.exampleId}}" wx:key="index">
+            <image class="course_icon" src="{{item.userRead.iconImg}}" lazy-load="true" />
             <view class="course_info">
-                <text class="course_title">{{item.lesson.title}}</text>
+                <text class="course_title">{{item.userRead.title}}</text>
                 <view class="course_btn">
                     <view class="collect course_btn">
                         <image class="collect_icon btn_icon" src="../../static/image/collect.png" />
-                        <text class="collect_text btn_text">收藏</text>
+                        <text class="collect_text btn_text">收藏{{item.isFavorites}}</text>
                     </view>
                     <view class="share course_btn">
                         <image class="share_icon btn_icon" src="../../static/image/share.png" />

+ 2 - 2
utils/APIClient.js

@@ -79,10 +79,10 @@ module.exports = {
     }).url(url).data(data).send();
   },
   // 获取单课朗读信息
-  getClassRead(uid, data) {
+  getClassRead(data) {
     let url = getBaseUrl(`wx/userRead`);
     return request.getInstance().header({
-      uid
+      uid:wx.getStorageSync('uid')
     }).data(data).url(url).send();
   },
   // 作品播放了+1

+ 1 - 0
utils/httpUtilNoLogin.js

@@ -65,6 +65,7 @@ function getOpenidNoLogin(successcallback, failcallback,grade) {
                 if (res.data.code === 200) {
                     wx.setStorageSync('uid', res.data.data.uid)
                     wx.setStorageSync('grade', res.data.data.grade)
+                    wx.setStorageSync('user',res.data.data)
                     successcallback(res)
                 }
             }).fail(() => {});