瀏覽代碼

全部banner组件页面增加年级筛选

bayi 2 年之前
父節點
當前提交
e142c0b9f6
共有 5 個文件被更改,包括 77 次插入17 次删除
  1. 34 2
      pages/activity/index.js
  2. 2 2
      pages/activity/index.wxml
  3. 3 0
      pages/index/index.js
  4. 36 10
      pages/works/index.js
  5. 2 3
      pages/works/index.wxml

+ 34 - 2
pages/activity/index.js

@@ -1,15 +1,33 @@
+import {
+  getBannerList
+} from '~/api/global'
+import {
+  createStoreBindings
+} from 'mobx-miniprogram-bindings'
+import {
+  store
+} from '~/store/index'
 Page({
   data: {
-    activityList: true
+    activityList: true,
+    bannerList: []
   },
   onShow() {
     if (typeof this.getTabBar === 'function') {
       this.getTabBar().setData({
         selected: 1
       })
+      this.storeBindings = createStoreBindings(this, {
+        store,
+        fields: {
+          userInfo: 'userInfo'
+        },
+      })
+      this.storeBindings.updateStoreBindings()
       this.setData({
         activityList: true
       })
+      this.getBannerList()
     }
   },
   onHide() {
@@ -17,7 +35,21 @@ Page({
       activityList: false
     })
   },
+  async getBannerList() {
+    console.log(this.data.userInfo);
+    let bannerList = await getBannerList({
+      grade: this.data.userInfo.grade,
+      classify: 3
+    })
+    this.setData({
+      bannerList,
+    })
+  },
   resetData() {
     this.selectComponent('#activityList').getActivities()
-  }
+    this.getBannerList()
+  },
+  onUnload() {
+    this.storeBindings.destroyStoreBindings()
+  },
 })

+ 2 - 2
pages/activity/index.wxml

@@ -1,5 +1,5 @@
 <navigationBar bind:reload='resetData'></navigationBar>
 <view class="activityBox">
-  <banner classify='3' />
-  <activityList id="activityList" class="activityList" wx:if="{{activityList}}"/>
+  <banner bannerList="{{bannerList}}" />
+  <activityList id="activityList" class="activityList" wx:if="{{activityList}}" />
 </view>

+ 3 - 0
pages/index/index.js

@@ -170,4 +170,7 @@ Page({
       this.getBannerList()
     }
   },
+  onUnload() {
+    this.storeBindings.destroyStoreBindings()
+  },
 })

+ 36 - 10
pages/works/index.js

@@ -11,6 +11,12 @@ import {
   getFollowWorks
 } from '~/api/works'
 import reachBottom from '~/mixins/reachBottom'
+import {
+  createStoreBindings
+} from 'mobx-miniprogram-bindings'
+import {
+  store
+} from '~/store/index'
 Page({
   behaviors: [reachBottom, share],
   data: {
@@ -26,12 +32,13 @@ Page({
         selected: 2
       })
     }
-    let uid = wx.getStorageSync('uid')
-    if (uid) {
-      this.resetData()
+    this.getLocUserInfo()
+    if (Object.keys(this.data.userInfo).length > 0) {
+      this.requestAgain()
     } else {
       getApp().callBack = (res) => {
-        this.resetData()
+        this.getLocUserInfo()
+        this.requestAgain()
       }
     }
   },
@@ -44,6 +51,15 @@ Page({
       this.getData(getFavoritesList, {})
     }
   },
+  async getBannerList() {
+    let bannerList = await getBannerList({
+      grade: this.data.userInfo.grade,
+      classify: this.data.currentType
+    })
+    this.setData({
+      bannerList,
+    })
+  },
   changeType({
     target
   }) {
@@ -55,7 +71,7 @@ Page({
       this.setData({
         currentType: target.dataset.type
       })
-      this.resetData()
+      this.requestAgain()
     }
   },
   /**
@@ -72,10 +88,20 @@ Page({
       })
     }
   },
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-    this.loadMore()
+  requestAgain() {
+    this.resetData()
+    this.getBannerList()
+  },
+  async getLocUserInfo() {
+    this.storeBindings = createStoreBindings(this, {
+      store,
+      fields: {
+        userInfo: 'userInfo'
+      },
+    })
+    this.storeBindings.updateStoreBindings()
+  },
+  onUnload() {
+    this.storeBindings.destroyStoreBindings()
   },
 })

+ 2 - 3
pages/works/index.wxml

@@ -1,10 +1,9 @@
-<navigationBar bind:reload='resetData'></navigationBar>
+<navigationBar bind:reload='requestAgain'></navigationBar>
 <view class="worksBox">
   <!-- 轮播图 -->
-  <banner classify='{{currentType}}' />
+  <banner bannerList="{{bannerList}}" />
   <!-- 切换类型 -->
   <view class="selectType {{isFixed?'isFixed isFixed2':''}}" style="top:{{navBarHeight}}px;" bindtap="changeType">
-
     <view class="type {{currentType=='4'?'currentType':''}}" data-type='4'>关注作品</view>
     <view class="type {{currentType=='5'?'currentType':''}}" data-type='5'>我的作品</view>
     <view class="type {{currentType=='6'?'currentType':''}}" data-type='6'>收藏作品</view>