Преглед изворни кода

开发我的关注及我的收藏页面

bayi пре 2 година
родитељ
комит
cdaab04cf3

+ 1 - 1
app.json

@@ -1,6 +1,7 @@
 {
   "pages": [
     "pages/index/index",
+    "pages/collection/index",
     "pages/personal/index",
     "pages/childClassify/index",
     "pages/pkResult/index",
@@ -11,7 +12,6 @@
     "pages/my/index",
     "pages/editUser/index",
     "pages/notice/index",
-    "pages/collection/index",
     "pages/follow/index",
     "pages/logs/logs"
   ],

+ 59 - 59
mixins/reachBottom.js

@@ -1,65 +1,65 @@
 module.exports = Behavior({
-    data: {
-        loading: false, // 加载状态标志位
+  data: {
+    loading: false, // 加载状态标志位
+    list: [],
+    grade: '',
+    pageNo: 1,
+    totalSize: 0,
+    noMoreData: false, // 无更多数据置为 false
+  },
+  properties: {
+    pageSize: {
+      type: Number,
+      value: 10
+    }
+  },
+  methods: {
+    async getData(fn, args) {
+      if (this.data.noMoreData) {
+        return
+      }
+      let params = {
+        pageNo: this.data.pageNo,
+        pageSize: this.properties.pageSize,
+        ...args
+      }
+      // 加载状态,用于页面中控制加载动画的显示
+      this.setData({
+        loading: true
+      })
+      let {
+        list,
+        totalSize
+      } = await fn(params).finally(() => {
+        // 页面渲染完成后关闭加载动画字段
+        wx.nextTick(() => {
+          this.setData({
+            loading: false
+          })
+        });
+      })
+      list = [...this.data.list, ...list]
+      console.log(list,
+        totalSize);
+      this.setData({
+        pageNo: ++this.data.pageNo,
+        list,
+        totalSize,
+        noMoreData: list.length >= totalSize
+      })
+
+    },
+    resetData() {
+      console.log("触发resetData");
+      if (this.data.loading) return; // 如果接口已经在请求中,则不重置数据,防止用户持续下拉刷新
+      this.setData({
+        loading: false,
         list: [],
-        grade: '',
         pageNo: 1,
         totalSize: 0,
-        noMoreData: false, // 无更多数据置为 false
-    },
-    properties: {
-        pageSize: {
-            type: Number,
-            value: 10
-        }
-    },
-    methods: {
-        async getData(fn, args) {
-            if (this.data.noMoreData) {
-                return
-            }
-            let params = {
-                pageNo: this.data.pageNo,
-                pageSize: this.properties.pageSize,
-                ...args
-            }
-            // 加载状态,用于页面中控制加载动画的显示
-            this.setData({
-                loading: true
-            })
-            let {
-                list,
-                totalSize
-            } = await fn(params).finally(() => {
-                // 页面渲染完成后关闭加载动画字段
-                wx.nextTick(() => {
-                    this.setData({
-                        loading: false
-                    })
-                });
-            })
-            list = [...this.data.list, ...list]
-            console.log(list,
-                totalSize);
-            this.setData({
-                pageNo: ++this.data.pageNo,
-                list,
-                totalSize,
-                noMoreData: list.length >= totalSize
-            })
-
-        },
-        resetData() {
-            console.log("触发", this.data.loading);
-            if (this.data.loading) return; // 如果接口已经在请求中,则不重置数据,防止用户持续下拉刷新
-            this.setData({
-                loading: false,
-                list: [],
-                pageNo: 1,
-                totalSize: 0,
-                noMoreData: false,
-            })
-            this.loadMore(); // 调用页面中的接口请求方法
-        },
+        noMoreData: false,
+      })
+      this.loadMore(); // 调用页面中的接口请求方法
     },
+  },
 })

+ 19 - 49
pages/collection/index.js

@@ -1,54 +1,24 @@
 import {
-    getFavoritesList
+  getFavoritesList
 } from "~/api/user"
-import behavior from '~/mixins/video'
+import reachBottom from '~/mixins/reachBottom'
 Page({
-    behaviors: [behavior],
-    /**
-     * 页面的初始数据
-     */
-    data: {
-        list: [],
-        pageNo: 1,
-        totalSize: 0,
+  behaviors: [reachBottom],
+  data: {},
+  onShow() {
+    this.resetData()
+  },
+  async loadMore() {
+    this.getData(getFavoritesList, {})
+    console.log(this.data.list);
+  },
+  onReachBottom() {
+    this.loadMore()
+  },
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
 
-    },
-
-    /**
-     * 生命周期函数--监听页面加载
-     */
-    onLoad(options) {
-        this.getFavoritesList()
-    },
-    async getFavoritesList() {
-        let {
-            list,
-            totalSize
-        } = await getFavoritesList({
-            pageNo: this.data.pageNo,
-            pageSize: 20
-        })
-        list = [...this.data.list, ...list]
-        this.setData({
-            list,
-            totalSize
-        })
-    },
-    /**
-     * 页面上拉触底事件的处理函数
-     */
-    onReachBottom() {
-        if (this.data.totalSize > this.data.list.length) {
-            this.setData({
-                pageNo: this.data.pageNo + 1
-            })
-            this.getFansList()
-        }
-    },
-    /**
-     * 用户点击右上角分享
-     */
-    onShareAppMessage() {
-
-    }
+  }
 })

+ 1 - 3
pages/collection/index.json

@@ -1,8 +1,6 @@
 {
     "usingComponents": {
-        "videoPreview": "/components/videoPreview/index",
-        "emptyBg": "/components/empty/index",
-        "Comment": "/components/comment/index"
+      "worksList": "/components/worksList/index"
     },
     "navigationBarTitleText": "我的收藏"
 }

+ 1 - 2
pages/collection/index.less

@@ -1,3 +1,2 @@
-.collection{
-    
+.collection {
 }

+ 1 - 6
pages/collection/index.wxml

@@ -1,8 +1,3 @@
 <view class="collection">
-    <videoPreview wx:for="{{list}}" wx:key="index" videoInfo="{{item}}" index='{{index}}' currentId="{{currentId}}"
-        data-id="{{item.userRead.id}}" bind:playVideo="playVideo" bind:openComment="openComment">
-    </videoPreview>
-    <emptyBg wx:if="{{list.length==0}}" message='您还没有收藏的作品哦~'></emptyBg>
-    <Comment id="comment" />
-    <canvas id='share' type="2d"> </canvas>
+  <worksList id="worksList" worksList="{{list}}" />
 </view>

+ 48 - 39
pages/follow/index.js

@@ -1,46 +1,55 @@
 import {
-    getFansList
+  getFansList
 } from '~/api/user'
 Page({
 
-    /**
-     * 页面的初始数据
-     */
-    data: {
-        list: [],
-        pageNo: 1,
-        totalSize: 0
-    },
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    list: [],
+    pageNo: 1,
+    totalSize: 0
+  },
 
-    /**
-     * 生命周期函数--监听页面加载
-     */
-    onLoad(options) {
-        this.getFansList()
-    },
-    /**
-     * 页面上拉触底事件的处理函数
-     */
-    onReachBottom() {
-        if (this.data.totalSize > this.data.list.length) {
-            this.setData({
-                pageNo: this.data.pageNo + 1
-            })
-            this.getFansList()
-        }
-    },
-    async getFansList() {
-        let {
-            list,
-            totalSize
-        } = await getFansList({
-            pageNo: this.data.pageNo,
-            pageSize: 20
-        })
-        list = [...this.data.list, ...list]
-        this.setData({
-            list,
-            totalSize
-        })
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+    this.getFansList()
+  },
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+    if (this.data.totalSize > this.data.list.length) {
+      this.setData({
+        pageNo: this.data.pageNo + 1
+      })
+      this.getFansList()
     }
+  },
+  async getFansList() {
+    let {
+      list,
+      totalSize
+    } = await getFansList({
+      pageNo: this.data.pageNo,
+      pageSize: 20
+    })
+    list = [...this.data.list, ...list]
+    this.setData({
+      list,
+      totalSize
+    })
+  },
+  jumpUserInfo({
+    currentTarget
+  }) {
+    console.log(currentTarget.dataset);
+    let uid = currentTarget.dataset.uid
+    wx.navigateTo({
+      url: `/pages/personal/index?uid=${uid}`,
+    })
+  }
 })

+ 15 - 15
pages/follow/index.wxml

@@ -1,18 +1,18 @@
 <view class="followBox">
-    <view class="follow" wx:for="{{ list }}" wx:key="*this">
-        <view class="userInfo">
-            <view class='avatar'>
-                <image class='avatar-image' src="{{ item.user.avatar }}" />
-                <view class="user-profession">{{item.user.profession}}</view>
-            </view>
-            <view class="nickName">
-                {{item.user.nickName||item.user.eid}}
-            </view>
-        </view>
-        <view class="state">
-            <image class='stateImg' src="{{item.isEachOther?'/static/concernback.png':'/static/concerned.png'}}" />
-            <view class="stateText">{{ item.isEachOther?'互相关注':'已关注' }}</view>
-        </view>
+  <view class="follow" wx:for="{{ list }}" wx:key="*this">
+    <view class="userInfo">
+      <view class='avatar'>
+        <image class='avatar-image' src="{{ item.user.avatar }}" bindtap="jumpUserInfo" data-uid='{{item.user.uid}}' />
+        <view class="user-profession">{{item.user.profession}}</view>
+      </view>
+      <view class="nickName">
+        {{item.user.nickName||item.user.eid}}
+      </view>
     </view>
-    <emptyBg wx:if="{{list.length==0}}" message='您还没有关注哦'></emptyBg>
+    <view class="state">
+      <image class='stateImg' src="{{item.isEachOther?'/static/concernback.png':'/static/concerned.png'}}" />
+      <view class="stateText">{{ item.isEachOther?'互相关注':'已关注' }}</view>
+    </view>
+  </view>
+  <emptyBg wx:if="{{list.length==0}}" message='您还没有关注哦'></emptyBg>
 </view>