// pages/my-comment/my-comment.js // 我的评论逻辑处理 const app = getApp() const api = require('../../services/api') Page({ data: { commentList: [], page: 1, pageSize: 10, hasMore: true, loading: false }, onLoad() { this.checkLogin() }, onShow() { this.checkLogin() }, onPullDownRefresh() { this.setData({ page: 1, commentList: [], hasMore: true }) this.loadCommentList() wx.stopPullDownRefresh() }, onReachBottom() { if (this.data.hasMore && !this.data.loading) { this.setData({ page: this.data.page + 1 }) this.loadCommentList() } }, checkLogin() { const userInfo = wx.getStorageSync('userInfo') if (!userInfo) { wx.redirectTo({ url: '/pages/login/login' }) return } this.loadCommentList() }, loadCommentList() { if (this.data.loading || !this.data.hasMore) return this.setData({ loading: true }) api.getMyCommentList({ 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({ commentList: this.data.page === 1 ? list : this.data.commentList.concat(list), hasMore: list.length >= this.data.pageSize }) } }).catch(() => { this.setData({ loading: false }) }) }, goToArticle(e) { const articleId = e.currentTarget.dataset.articleId wx.navigateTo({ url: `/pages/article-detail/article-detail?id=${articleId}` }) }, onDelete(e) { const commentId = e.currentTarget.dataset.id wx.showModal({ title: '提示', content: '确定要删除这条评论吗?', success: res => { if (res.confirm) { api.deleteComment({ id: commentId }).then(result => { if (result.code === 200) { wx.showToast({ title: '删除成功', icon: 'success' }) this.setData({ page: 1, commentList: [], hasMore: true }) this.loadCommentList() } else { wx.showToast({ title: result.message || '删除失败', icon: 'none' }) } }) } } }) } }) /** * @联系作者:16768118056 * @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。 * @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。 */