index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="container">
  3. <!-- 导航栏 -->
  4. <view class="nav-bar">
  5. <view class="nav-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);">
  7. </image>
  8. </view>
  9. <text class="nav-title">系统消息</text>
  10. <view class="nav-right"></view>
  11. </view>
  12. <view class="nav-placeholder"></view>
  13. <view class="sys-msg-list" v-for="(group, date) in groupedNotices" :key="date">
  14. <view class="date-label">{{ date }}</view>
  15. <view class="sys-card" v-for="item in group" :key="item.id" @click="handleMarkRead(item)">
  16. <view class="sys-header">
  17. <text class="sys-title">{{ item.title }}</text>
  18. <view class="red-dot" v-if="!item.readFlag"></view>
  19. </view>
  20. <view class="sys-content">
  21. <text class="sys-text">{{ item.content }}</text>
  22. </view>
  23. <view class="sys-footer" @click.stop="navToDetail(item)">
  24. <text class="sys-time">{{ formatTime(item.createTime, 'HH:mm') }}</text>
  25. <view class="check-more">
  26. <text>查看详情</text>
  27. <image class="arrow-icon-small" src="/static/icons/chevron_right.svg"></image>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- No data -->
  33. <view class="empty-state" v-if="Object.keys(groupedNotices).length === 0 && !loading">
  34. <text class="empty-text">暂无消息记录</text>
  35. </view>
  36. <uni-load-more :status="loadMoreStatus" v-if="notices.length > 0"></uni-load-more>
  37. </view>
  38. </template>
  39. <script>
  40. import { listMyNotice, readNotice } from '@/api/system/notice'
  41. import { formatTime } from '@/utils/index'
  42. export default {
  43. data() {
  44. return {
  45. notices: [],
  46. queryParams: {
  47. pageNum: 1,
  48. pageSize: 10,
  49. type: 1 // 系统消息
  50. },
  51. total: 0,
  52. loading: false,
  53. loadMoreStatus: 'more'
  54. }
  55. },
  56. computed: {
  57. groupedNotices() {
  58. const groups = {};
  59. this.notices.forEach(item => {
  60. const date = formatTime(item.createTime, 'yyyy-MM-dd');
  61. if (!groups[date]) {
  62. groups[date] = [];
  63. }
  64. groups[date].push(item);
  65. });
  66. return groups;
  67. }
  68. },
  69. onShow() {
  70. this.refreshList();
  71. },
  72. onPullDownRefresh() {
  73. this.refreshList();
  74. },
  75. onReachBottom() {
  76. if (this.notices.length >= this.total) return;
  77. this.queryParams.pageNum++;
  78. this.loadNotices();
  79. },
  80. methods: {
  81. formatTime,
  82. async refreshList() {
  83. this.queryParams.pageNum = 1;
  84. this.notices = [];
  85. await this.loadNotices();
  86. uni.stopPullDownRefresh();
  87. },
  88. async loadNotices() {
  89. if (this.loading) return;
  90. this.loading = true;
  91. this.loadMoreStatus = 'loading';
  92. try {
  93. const res = await listMyNotice(this.queryParams);
  94. this.notices = [...this.notices, ...(res.rows || [])];
  95. this.total = Number(res.total);
  96. this.loadMoreStatus = this.notices.length >= this.total ? 'noMore' : 'more';
  97. } catch (err) {
  98. console.error('获取消息失败:', err);
  99. uni.showToast({ title: '加载失败', icon: 'none' });
  100. } finally {
  101. this.loading = false;
  102. }
  103. },
  104. async handleMarkRead(item) {
  105. if (item.readFlag) return;
  106. try {
  107. await readNotice(item.id);
  108. item.readFlag = true;
  109. } catch (err) {
  110. console.error('标记已读失败:', err);
  111. }
  112. },
  113. navBack() {
  114. uni.navigateBack();
  115. },
  116. navToDetail(item) {
  117. this.handleMarkRead(item);
  118. uni.navigateTo({
  119. url: `/pages/mine/message/detail/index?id=${item.id}&title=${item.title}&content=${item.content}&time=${item.createTime}`
  120. });
  121. }
  122. }
  123. }
  124. </script>
  125. <style>
  126. page {
  127. background-color: #F5F6FA;
  128. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  129. }
  130. .nav-bar {
  131. position: fixed;
  132. top: 0;
  133. left: 0;
  134. width: 100%;
  135. height: 88rpx;
  136. padding-top: var(--status-bar-height);
  137. background-color: #fff;
  138. display: flex;
  139. align-items: center;
  140. justify-content: space-between;
  141. padding: 0 30rpx;
  142. box-sizing: border-box;
  143. z-index: 100;
  144. }
  145. .nav-placeholder {
  146. height: calc(88rpx + var(--status-bar-height));
  147. }
  148. .back-icon {
  149. width: 40rpx;
  150. height: 40rpx;
  151. }
  152. .nav-title {
  153. font-size: 34rpx;
  154. font-weight: bold;
  155. color: #333;
  156. }
  157. .nav-right {
  158. width: 40rpx;
  159. }
  160. .sys-msg-list {
  161. padding: 20rpx 30rpx;
  162. }
  163. .date-label {
  164. text-align: center;
  165. font-size: 24rpx;
  166. color: #ccc;
  167. margin: 30rpx 0 20rpx;
  168. /* Increased top margin */
  169. }
  170. .sys-card {
  171. background-color: #fff;
  172. border-radius: 16rpx;
  173. padding: 30rpx;
  174. margin-bottom: 20rpx;
  175. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.02);
  176. }
  177. .sys-header {
  178. display: flex;
  179. align-items: center;
  180. margin-bottom: 16rpx;
  181. }
  182. .sys-title {
  183. font-size: 28rpx;
  184. font-weight: bold;
  185. color: #333;
  186. }
  187. .red-dot {
  188. width: 10rpx;
  189. height: 10rpx;
  190. background-color: #FF3B30;
  191. border-radius: 50%;
  192. margin-left: 10rpx;
  193. }
  194. .sys-content {
  195. margin-bottom: 24rpx;
  196. }
  197. .sys-text {
  198. font-size: 26rpx;
  199. color: #666;
  200. line-height: 1.6;
  201. }
  202. .sys-footer {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. border-top: 1rpx solid #f5f5f5;
  207. padding-top: 20rpx;
  208. }
  209. .sys-time {
  210. font-size: 24rpx;
  211. color: #999;
  212. }
  213. .check-more {
  214. display: flex;
  215. align-items: center;
  216. font-size: 24rpx;
  217. color: #999;
  218. }
  219. .arrow-icon-small {
  220. width: 20rpx;
  221. height: 20rpx;
  222. margin-left: 4rpx;
  223. opacity: 0.5;
  224. }
  225. </style>