mirror of
https://gitee.com/qingqing-coconut-tea/RcKtFezyRAZX
synced 2026-07-21 10:32:32 +08:00
102 lines
2.5 KiB
JavaScript
102 lines
2.5 KiB
JavaScript
// pages/my-favorite/my-favorite.js
|
||
// 我的收藏逻辑处理
|
||
|
||
const app = getApp()
|
||
const api = require('../../services/api')
|
||
|
||
Page({
|
||
data: {
|
||
favoriteList: [],
|
||
page: 1,
|
||
pageSize: 10,
|
||
hasMore: true,
|
||
loading: false
|
||
},
|
||
|
||
onLoad() {
|
||
this.checkLogin()
|
||
},
|
||
|
||
onShow() {
|
||
this.checkLogin()
|
||
},
|
||
|
||
onPullDownRefresh() {
|
||
this.setData({ page: 1, favoriteList: [], hasMore: true })
|
||
this.loadFavoriteList()
|
||
wx.stopPullDownRefresh()
|
||
},
|
||
|
||
onReachBottom() {
|
||
if (this.data.hasMore && !this.data.loading) {
|
||
this.setData({ page: this.data.page + 1 })
|
||
this.loadFavoriteList()
|
||
}
|
||
},
|
||
|
||
checkLogin() {
|
||
const userInfo = wx.getStorageSync('userInfo')
|
||
if (!userInfo) {
|
||
wx.redirectTo({ url: '/pages/login/login' })
|
||
return
|
||
}
|
||
this.loadFavoriteList()
|
||
},
|
||
|
||
loadFavoriteList() {
|
||
if (this.data.loading || !this.data.hasMore) return
|
||
|
||
this.setData({ loading: true })
|
||
|
||
api.getMyFavoriteList({
|
||
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({
|
||
favoriteList: this.data.page === 1 ? list : this.data.favoriteList.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}`
|
||
})
|
||
},
|
||
|
||
onCancelFavorite(e) {
|
||
const articleId = e.currentTarget.dataset.id
|
||
wx.showModal({
|
||
title: '提示',
|
||
content: '确定要取消收藏吗?',
|
||
success: res => {
|
||
if (res.confirm) {
|
||
api.updateFavorite({ articleId, isFavorite: false }).then(result => {
|
||
if (result.code === 200) {
|
||
wx.showToast({ title: '已取消收藏', icon: 'success' })
|
||
this.setData({ page: 1, favoriteList: [], hasMore: true })
|
||
this.loadFavoriteList()
|
||
} else {
|
||
wx.showToast({ title: result.message || '操作失败', icon: 'none' })
|
||
}
|
||
})
|
||
}
|
||
}
|
||
})
|
||
}
|
||
})
|
||
|
||
/**
|
||
* @联系作者:16768118056
|
||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||
*/
|