市北人才赋能平台 --小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.8 KiB

6 years ago
// pages/user/common/myFavorite/index.js
import dayjs from '../../../utils/dayjs/index.js'
import relativeTime from '../../../utils/dayjs/relativeTime.js'
dayjs.extend(relativeTime);
import { UserModel } from '../../../models/user.js'
let userModel = new UserModel()
6 years ago
Page({
/**
* 页面的初始数据
*/
data: {
6 years ago
list: [],
currentPage:1
6 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.fetchMyFavoriteList()
6 years ago
},
fetchMyFavoriteList(){
console.log('啦啦啦')
let page = this.data.currentPage
userModel.getMyFavoriteList(page,res=>{
console.log(res)
const datas = res.result.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
topicId: item.contentId,
title: item.title,
topicImg: item.image,
userIcon: item.groupAvator,
userName: item.author,
time: item.createTime,
commentNum: item.commentNum,
type:item.type
})
})
if (page == 1) {
this.setData({
list: tempDatas
})
} else {
if (tempDatas.length > 0) {
const list = [...this.data.list, ...tempDatas]
this.setData({
list: list
})
} else {
const page = this.data.currPage - 1
this.setData({
currPage: page
})
wx.showToast({
title: '已加载全部',
icon: 'none'
})
}
}
console.log(this.data.list)
wx.stopPullDownRefresh()
})
},
6 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.setData({
currPage: 1,
})
this.fetchMyFavoriteList()
6 years ago
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
let page = this.data.currentPage+1
this.setData({
currPage: page,
})
this.fetchMyFavoriteList()
6 years ago
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
clickListItem(e) {
const item = e.detail.item;
console.log(item);
let id = item.topicId
if(item.type === '1'){
wx.navigateTo({
url: `/pages/article/index?id=${id}`,
})
}else {
wx.navigateTo({
url: `/pages/topics/interactive/topicArticle/index?topicId=${id}`,
})
}
6 years ago
}
})