mirror of
https://gitee.com/qingqing-coconut-tea/RcKtFezyRAZX
synced 2026-07-21 10:32:32 +08:00
init
This commit is contained in:
84
wechat/pages/history/history.js
Normal file
84
wechat/pages/history/history.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// pages/history/history.js
|
||||
// 浏览历史逻辑处理
|
||||
|
||||
const app = getApp()
|
||||
const api = require('../../services/api')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
historyList: [],
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
hasMore: true,
|
||||
loading: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadHistoryList()
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.setData({ page: 1, historyList: [], hasMore: true })
|
||||
this.loadHistoryList()
|
||||
wx.stopPullDownRefresh()
|
||||
},
|
||||
|
||||
onReachBottom() {
|
||||
if (this.data.hasMore && !this.data.loading) {
|
||||
this.setData({ page: this.data.page + 1 })
|
||||
this.loadHistoryList()
|
||||
}
|
||||
},
|
||||
|
||||
loadHistoryList() {
|
||||
if (this.data.loading || !this.data.hasMore) return
|
||||
|
||||
this.setData({ loading: true })
|
||||
|
||||
api.getBrowseHistory({
|
||||
page: this.data.page,
|
||||
pageSize: this.data.pageSize
|
||||
}).then(res => {
|
||||
this.setData({ loading: false })
|
||||
if (res.code === 200) {
|
||||
const list = res.data.list || []
|
||||
this.setData({
|
||||
historyList: this.data.page === 1 ? list : this.data.historyList.concat(list),
|
||||
hasMore: list.length >= this.data.pageSize
|
||||
})
|
||||
}
|
||||
}).catch(() => {
|
||||
this.setData({ loading: false })
|
||||
})
|
||||
},
|
||||
|
||||
goToDetail(e) {
|
||||
const articleId = e.currentTarget.dataset.id
|
||||
wx.navigateTo({
|
||||
url: `/pages/article-detail/article-detail?id=${articleId}`
|
||||
})
|
||||
},
|
||||
|
||||
onClearHistory() {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '确定要清空浏览历史吗?',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
api.clearBrowseHistory().then(result => {
|
||||
if (result.code === 200) {
|
||||
wx.showToast({ title: '已清空', icon: 'success' })
|
||||
this.setData({ historyList: [], hasMore: false })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @联系作者:16768118056
|
||||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||||
*/
|
||||
Reference in New Issue
Block a user