fireflysg-wxapp/pages/home/home.js

185 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/home.js
import request from '../../utils/request'
Page({
/**
* 页面的初始数据
*/
data: {
list: [],
categoryId: 0,
keyword: '',
pageNum: 1,
pageSize: 10,
listData: [],
pageNum1: 1,
display: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// this.getData()
},
listTap(e) {
const id = e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/vedio/detail?id=' + id
})
},
getVedio() {
const data = {
"keyword": "", // 搜索关键字,视频标题,可选参数
"categoryId": 1, //分类 Id可选参数
"pageNum": this.data.pageNum1,
"pageSize": 10// ⻚⼤⼩,可选参数
}
request._post('/firefly/video/list', data,
res => {
if (res.retCode == 0) {
if (res.body.length > 0) {
var listdata = this.data.listData
listdata.push.apply(listdata, res.body)
this.setData({
listData: listdata,
pageNum1: ++res.pageInfo.pageNum
})
} else {
if (this.data.pageNum1 == res.pageInfo.pages) {
setTimeout(() => {
wx.showToast({
title: '没有更多数据',
icon: 'none',
duration: 2000
})
}, 200);
}
}
}
})
},
onbindtap(e) {
let url = e.currentTarget.dataset.url
wx.navigateTo({
url: url
})
},
tab(e) {
this.setData({
pageNum: 1,
pageNum1:1,
list: [],
listData:[],
display: e.currentTarget.dataset.id
})
console.log(this.data.listData)
if (e.currentTarget.dataset.id != 1) {
this.getData()
}else {
this.getVedio()
}
},
getData() {
let data = {
display: this.data.display,
categoryId: this.data.categoryId,
keyword: this.data.keyword,
pageNum: this.data.pageNum,
pageSize: this.data.pageSize
}
request._post('/firefly/article/list', data,
res => {
if (res.retCode == 0) {
if (res.body.length > 0) {
var listdata = this.data.list
listdata.push.apply(listdata, res.body)
this.setData({
list: listdata,
pageNum: ++res.pageInfo.pageNum
})
} else {
if (this.data.pageNum == res.pageInfo.pages) {
setTimeout(() => {
wx.showToast({
title: '没有更多数据',
icon: 'none',
duration: 2000
})
}, 200);
}
}
}
}
)
},
detail(e) {
let id = e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/article/detail?id=' + id,
})
},
release(e) {
let num = e.currentTarget.dataset.num
wx.navigateTo({
url: '/pages/article/publish?id=' + num,
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.setData({
list: [],
pageNum: 1
})
// this.getVedio()
this.getData()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (this.data.display == 1) {
this.getVedio()
} else {
this.getData()
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})