// pages/notification/notification.js // 消息通知逻辑处理 const app = getApp() const api = require('../../services/api') Page({ data: { notificationList: [], page: 1, pageSize: 10, hasMore: true, loading: false, unreadCount: 0 }, onLoad() { this.checkLogin() }, onShow() { this.checkLogin() }, onPullDownRefresh() { this.setData({ page: 1, notificationList: [], hasMore: true }) this.loadNotificationList() wx.stopPullDownRefresh() }, onReachBottom() { if (this.data.hasMore && !this.data.loading) { this.setData({ page: this.data.page + 1 }) this.loadNotificationList() } }, checkLogin() { const userInfo = wx.getStorageSync('userInfo') if (!userInfo) { wx.redirectTo({ url: '/pages/login/login' }) return } this.loadNotificationList() }, loadNotificationList() { if (this.data.loading || !this.data.hasMore) return this.setData({ loading: true }) api.getNotificationList({ 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({ notificationList: this.data.page === 1 ? list : this.data.notificationList.concat(list), hasMore: list.length >= this.data.pageSize, unreadCount: res.data.unreadCount || 0 }) } }).catch(() => { this.setData({ loading: false }) }) }, onMarkAllRead() { api.markAllNotificationRead().then(res => { if (res.code === 200) { wx.showToast({ title: '已全部标为已读', icon: 'success' }) this.setData({ page: 1, notificationList: [], hasMore: true, unreadCount: 0 }) this.loadNotificationList() } }) }, onMarkRead(e) { const id = e.currentTarget.dataset.id api.markNotificationRead({ id }).then(res => { if (res.code === 200) { const list = this.data.notificationList const index = list.findIndex(item => item.id === id) if (index !== -1) { list[index].isRead = true this.setData({ notificationList: list, unreadCount: Math.max(0, this.data.unreadCount - 1) }) } } }) }, onDelete(e) { const id = e.currentTarget.dataset.id wx.showModal({ title: '提示', content: '确定要删除这条通知吗?', success: res => { if (res.confirm) { api.deleteNotification({ id }).then(result => { if (result.code === 200) { wx.showToast({ title: '删除成功', icon: 'success' }) this.setData({ page: 1, notificationList: [], hasMore: true }) this.loadNotificationList() } }) } } }) }, onNotificationTap(e) { const notification = e.currentTarget.dataset.notification this.onMarkRead({ currentTarget: { dataset: { id: notification.id } } }) if (notification.url) { wx.navigateTo({ url: notification.url }) } } }) /** * @联系作者:16768118056 * @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。 * @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。 */