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