mirror of
https://gitee.com/qingqing-coconut-tea/RcKtFezyRAZX
synced 2026-07-21 10:32:32 +08:00
init
This commit is contained in:
130
wechat/pages/notification/notification.js
Normal file
130
wechat/pages/notification/notification.js
Normal file
@@ -0,0 +1,130 @@
|
||||
// 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,查看完整运行演示。
|
||||
*/
|
||||
12
wechat/pages/notification/notification.json
Normal file
12
wechat/pages/notification/notification.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "消息通知",
|
||||
"enablePullDownRefresh": true,
|
||||
"backgroundTextStyle": "dark"
|
||||
}
|
||||
|
||||
/**
|
||||
* @联系作者:16768118056
|
||||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||||
*/
|
||||
52
wechat/pages/notification/notification.wxml
Normal file
52
wechat/pages/notification/notification.wxml
Normal file
@@ -0,0 +1,52 @@
|
||||
<!-- pages/notification/notification.wxml -->
|
||||
<!-- 消息通知视图 -->
|
||||
|
||||
<view class="notification-container">
|
||||
<!-- 工具栏 -->
|
||||
<view class="toolbar" wx:if="{{notificationList.length > 0}}">
|
||||
<text class="toolbar-btn" bindtap="onMarkAllRead">全部标为已读</text>
|
||||
</view>
|
||||
|
||||
<!-- 通知列表 -->
|
||||
<view class="notification-list">
|
||||
<view
|
||||
class="notification-item {{item.isRead ? 'read' : 'unread'}}"
|
||||
wx:for="{{notificationList}}"
|
||||
wx:key="id"
|
||||
bindtap="onNotificationTap"
|
||||
data-notification="{{item}}"
|
||||
>
|
||||
<view class="notification-icon">
|
||||
<text class="iconfont {{item.type === 'system' ? 'icon-settings' : item.type === 'comment' ? 'icon-comment' : 'icon-bell'}}"></text>
|
||||
</view>
|
||||
<view class="notification-content">
|
||||
<view class="notification-header">
|
||||
<text class="notification-title">{{item.title}}</text>
|
||||
<text class="notification-time">{{item.createTime}}</text>
|
||||
</view>
|
||||
<text class="notification-text">{{item.content}}</text>
|
||||
</view>
|
||||
<view class="notification-actions">
|
||||
<text class="action-btn" bindtap="onMarkRead" data-id="{{item.id}}">已读</text>
|
||||
<text class="action-btn delete" bindtap="onDelete" data-id="{{item.id}}">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="loading-more" wx:if="{{loading}}">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
<view class="no-more" wx:if="{{!hasMore && notificationList.length > 0}}">
|
||||
<text>没有更多了</text>
|
||||
</view>
|
||||
<view class="empty-state" wx:if="{{!loading && notificationList.length === 0}}">
|
||||
<text class="iconfont icon-bell empty-icon"></text>
|
||||
<text class="empty-text">暂无通知</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
/**
|
||||
* @联系作者:16768118056
|
||||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||||
*/
|
||||
146
wechat/pages/notification/notification.wxss
Normal file
146
wechat/pages/notification/notification.wxss
Normal file
@@ -0,0 +1,146 @@
|
||||
/* pages/notification/notification.wxss */
|
||||
/* 消息通知样式 */
|
||||
|
||||
.notification-container {
|
||||
min-height: 100vh;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 20rpx 30rpx;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.toolbar-btn {
|
||||
font-size: 26rpx;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.notification-list {
|
||||
padding: 0 20rpx;
|
||||
}
|
||||
|
||||
.notification-item {
|
||||
display: flex;
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
margin-bottom: 16rpx;
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.notification-item.unread {
|
||||
background-color: #f0f7ff;
|
||||
}
|
||||
|
||||
.notification-item.unread::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 24rpx;
|
||||
right: 24rpx;
|
||||
width: 16rpx;
|
||||
height: 16rpx;
|
||||
background-color: #f56c6c;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.notification-icon {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
background-color: rgba(102, 126, 234, 0.1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.notification-icon .iconfont {
|
||||
font-size: 36rpx;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.notification-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.notification-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.notification-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.notification-time {
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.notification-text {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
line-height: 1.5;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.notification-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
font-size: 24rpx;
|
||||
color: #667eea;
|
||||
padding: 8rpx 0;
|
||||
}
|
||||
|
||||
.action-btn.delete {
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.loading-more,
|
||||
.no-more {
|
||||
text-align: center;
|
||||
padding: 30rpx;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 100rpx 0;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 100rpx;
|
||||
color: #ddd;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/**
|
||||
* @联系作者:16768118056
|
||||
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
|
||||
* @访问:https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415,查看完整运行演示。
|
||||
*/
|
||||
Reference in New Issue
Block a user