index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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: err.message || err.msg || '请求失败', 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. uni.showToast({ title: err.message || err.msg || '请求失败', icon: 'none' });
  112. }
  113. },
  114. navBack() {
  115. uni.navigateBack();
  116. },
  117. navToDetail(item) {
  118. this.handleMarkRead(item);
  119. uni.navigateTo({
  120. url: `/pages/mine/message/detail/index?id=${item.id}&title=${item.title}&content=${item.content}&time=${item.createTime}`
  121. });
  122. }
  123. }
  124. }
  125. </script>
  126. <style>
  127. page {
  128. background-color: #F5F6FA;
  129. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  130. }
  131. .nav-bar {
  132. position: fixed;
  133. top: 0;
  134. left: 0;
  135. width: 100%;
  136. height: 88rpx;
  137. padding-top: var(--status-bar-height);
  138. background-color: #fff;
  139. display: flex;
  140. align-items: center;
  141. justify-content: space-between;
  142. padding: 0 30rpx;
  143. box-sizing: border-box;
  144. z-index: 100;
  145. }
  146. .nav-placeholder {
  147. height: calc(88rpx + var(--status-bar-height));
  148. }
  149. .back-icon {
  150. width: 40rpx;
  151. height: 40rpx;
  152. }
  153. .nav-title {
  154. font-size: 34rpx;
  155. font-weight: bold;
  156. color: #333;
  157. }
  158. .nav-right {
  159. width: 40rpx;
  160. }
  161. .sys-msg-list {
  162. padding: 20rpx 30rpx;
  163. }
  164. .date-label {
  165. text-align: center;
  166. font-size: 24rpx;
  167. color: #ccc;
  168. margin: 30rpx 0 20rpx;
  169. /* Increased top margin */
  170. }
  171. .sys-card {
  172. background-color: #fff;
  173. border-radius: 16rpx;
  174. padding: 30rpx;
  175. margin-bottom: 20rpx;
  176. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.02);
  177. }
  178. .sys-header {
  179. display: flex;
  180. align-items: center;
  181. margin-bottom: 16rpx;
  182. }
  183. .sys-title {
  184. font-size: 28rpx;
  185. font-weight: bold;
  186. color: #333;
  187. }
  188. .red-dot {
  189. width: 10rpx;
  190. height: 10rpx;
  191. background-color: #FF3B30;
  192. border-radius: 50%;
  193. margin-left: 10rpx;
  194. }
  195. .sys-content {
  196. margin-bottom: 24rpx;
  197. }
  198. .sys-text {
  199. font-size: 26rpx;
  200. color: #666;
  201. line-height: 1.6;
  202. }
  203. .sys-footer {
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: center;
  207. border-top: 1rpx solid #f5f5f5;
  208. padding-top: 20rpx;
  209. }
  210. .sys-time {
  211. font-size: 24rpx;
  212. color: #999;
  213. }
  214. .check-more {
  215. display: flex;
  216. align-items: center;
  217. font-size: 24rpx;
  218. color: #999;
  219. }
  220. .arrow-icon-small {
  221. width: 20rpx;
  222. height: 20rpx;
  223. margin-left: 4rpx;
  224. opacity: 0.5;
  225. }
  226. </style>