| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <template>
- <view class="container">
- <!-- 导航栏 -->
- <view class="nav-bar">
- <view class="nav-left" @click="navBack">
- <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);">
- </image>
- </view>
- <text class="nav-title">系统消息</text>
- <view class="nav-right"></view>
- </view>
- <view class="nav-placeholder"></view>
- <view class="sys-msg-list" v-for="(group, date) in groupedNotices" :key="date">
- <view class="date-label">{{ date }}</view>
-
- <view class="sys-card" v-for="item in group" :key="item.id" @click="handleMarkRead(item)">
- <view class="sys-header">
- <text class="sys-title">{{ item.title }}</text>
- <view class="red-dot" v-if="!item.readFlag"></view>
- </view>
- <view class="sys-content">
- <text class="sys-text">{{ item.content }}</text>
- </view>
- <view class="sys-footer" @click.stop="navToDetail(item)">
- <text class="sys-time">{{ formatTime(item.createTime, 'HH:mm') }}</text>
- <view class="check-more">
- <text>查看详情</text>
- <image class="arrow-icon-small" src="/static/icons/chevron_right.svg"></image>
- </view>
- </view>
- </view>
- </view>
- <!-- No data -->
- <view class="empty-state" v-if="Object.keys(groupedNotices).length === 0 && !loading">
- <text class="empty-text">暂无消息记录</text>
- </view>
- <uni-load-more :status="loadMoreStatus" v-if="notices.length > 0"></uni-load-more>
- </view>
- </template>
- <script>
- import { listMyNotice, readNotice } from '@/api/system/notice'
- import { formatTime } from '@/utils/index'
- export default {
- data() {
- return {
- notices: [],
- queryParams: {
- pageNum: 1,
- pageSize: 10,
- type: 1 // 系统消息
- },
- total: 0,
- loading: false,
- loadMoreStatus: 'more'
- }
- },
- computed: {
- groupedNotices() {
- const groups = {};
- this.notices.forEach(item => {
- const date = formatTime(item.createTime, 'yyyy-MM-dd');
- if (!groups[date]) {
- groups[date] = [];
- }
- groups[date].push(item);
- });
- return groups;
- }
- },
- onShow() {
- this.refreshList();
- },
- onPullDownRefresh() {
- this.refreshList();
- },
- onReachBottom() {
- if (this.notices.length >= this.total) return;
- this.queryParams.pageNum++;
- this.loadNotices();
- },
- methods: {
- formatTime,
- async refreshList() {
- this.queryParams.pageNum = 1;
- this.notices = [];
- await this.loadNotices();
- uni.stopPullDownRefresh();
- },
- async loadNotices() {
- if (this.loading) return;
- this.loading = true;
- this.loadMoreStatus = 'loading';
- try {
- const res = await listMyNotice(this.queryParams);
- this.notices = [...this.notices, ...(res.rows || [])];
- this.total = Number(res.total);
- this.loadMoreStatus = this.notices.length >= this.total ? 'noMore' : 'more';
- } catch (err) {
- console.error('获取消息失败:', err);
- uni.showToast({ title: '加载失败', icon: 'none' });
- } finally {
- this.loading = false;
- }
- },
- async handleMarkRead(item) {
- if (item.readFlag) return;
- try {
- await readNotice(item.id);
- item.readFlag = true;
- } catch (err) {
- console.error('标记已读失败:', err);
- }
- },
- navBack() {
- uni.navigateBack();
- },
- navToDetail(item) {
- this.handleMarkRead(item);
- uni.navigateTo({
- url: `/pages/mine/message/detail/index?id=${item.id}&title=${item.title}&content=${item.content}&time=${item.createTime}`
- });
- }
- }
- }
- </script>
- <style>
- page {
- background-color: #F5F6FA;
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
- }
- .nav-bar {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 88rpx;
- padding-top: var(--status-bar-height);
- background-color: #fff;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 30rpx;
- box-sizing: border-box;
- z-index: 100;
- }
- .nav-placeholder {
- height: calc(88rpx + var(--status-bar-height));
- }
- .back-icon {
- width: 40rpx;
- height: 40rpx;
- }
- .nav-title {
- font-size: 34rpx;
- font-weight: bold;
- color: #333;
- }
- .nav-right {
- width: 40rpx;
- }
- .sys-msg-list {
- padding: 20rpx 30rpx;
- }
- .date-label {
- text-align: center;
- font-size: 24rpx;
- color: #ccc;
- margin: 30rpx 0 20rpx;
- /* Increased top margin */
- }
- .sys-card {
- background-color: #fff;
- border-radius: 16rpx;
- padding: 30rpx;
- margin-bottom: 20rpx;
- box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.02);
- }
- .sys-header {
- display: flex;
- align-items: center;
- margin-bottom: 16rpx;
- }
- .sys-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- }
- .red-dot {
- width: 10rpx;
- height: 10rpx;
- background-color: #FF3B30;
- border-radius: 50%;
- margin-left: 10rpx;
- }
- .sys-content {
- margin-bottom: 24rpx;
- }
- .sys-text {
- font-size: 26rpx;
- color: #666;
- line-height: 1.6;
- }
- .sys-footer {
- display: flex;
- justify-content: space-between;
- align-items: center;
- border-top: 1rpx solid #f5f5f5;
- padding-top: 20rpx;
- }
- .sys-time {
- font-size: 24rpx;
- color: #999;
- }
- .check-more {
- display: flex;
- align-items: center;
- font-size: 24rpx;
- color: #999;
- }
- .arrow-icon-small {
- width: 20rpx;
- height: 20rpx;
- margin-left: 4rpx;
- opacity: 0.5;
- }
- </style>
|