70 lines
1.5 KiB
JavaScript
70 lines
1.5 KiB
JavaScript
|
|
import articleApi from "../../../api/articleApi"
|
||
|
|
import clientConfig from "../../../config/index"
|
||
|
|
|
||
|
|
|
||
|
|
Page({
|
||
|
|
|
||
|
|
data: {
|
||
|
|
searchKey: '',
|
||
|
|
hotArticles:[],
|
||
|
|
rankType: 'all',
|
||
|
|
hasMore: true, // 是否有更多数据
|
||
|
|
loading: false, // 是否正在加载
|
||
|
|
pageSize: 10,
|
||
|
|
pageNum: 1,
|
||
|
|
sortField: '',
|
||
|
|
},
|
||
|
|
|
||
|
|
onSearch(){
|
||
|
|
this.data.hotArticles = []
|
||
|
|
this.data.pageNum = 1
|
||
|
|
this.data.hasMore = true
|
||
|
|
this.fetchData()
|
||
|
|
},
|
||
|
|
|
||
|
|
onLoad(options) {
|
||
|
|
this.fetchData()
|
||
|
|
},
|
||
|
|
|
||
|
|
onReachBottom: function () {
|
||
|
|
if (this.data.hasMore) {
|
||
|
|
this.fetchData(); // 触底时加载更多数据
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
fetchData(){
|
||
|
|
if (this.data.loading) {
|
||
|
|
return; // 如果正在加载,则不再加载
|
||
|
|
}
|
||
|
|
|
||
|
|
articleApi.page({
|
||
|
|
pageNum: this.data.pageNum,
|
||
|
|
pageSize: this.data.pageSize,
|
||
|
|
searchKey: this.data.searchKey,
|
||
|
|
sortField: this.data.sortField,
|
||
|
|
sortOrder: 'descend'
|
||
|
|
}).then(res=>{
|
||
|
|
res.data.rows.forEach(i => {
|
||
|
|
if(i.fileList.length > 0){
|
||
|
|
i.cover = i.fileList[0].fileUrl
|
||
|
|
}
|
||
|
|
})
|
||
|
|
this.setData({
|
||
|
|
hotArticles: [...this.data.hotArticles, ...res.data.rows],
|
||
|
|
loading: false,
|
||
|
|
pageNum: this.data.pageNum + 1
|
||
|
|
})
|
||
|
|
|
||
|
|
if (res.data.rows.length < 10) {
|
||
|
|
console.log(res.data.rows)
|
||
|
|
this.setData({ hasMore: false });
|
||
|
|
}
|
||
|
|
})
|
||
|
|
},
|
||
|
|
|
||
|
|
rank(e){
|
||
|
|
let rankType = e.currentTarget.dataset.type
|
||
|
|
this.setData({rankType})
|
||
|
|
this.fetchData()
|
||
|
|
}
|
||
|
|
})
|