system-messages.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="matchmaker-system-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack"></view>
  6. <text class="header-title">系统通知</text>
  7. <view class="placeholder">
  8. <button class="read-all-btn" @click.stop="markAllRead" size="mini">一键已读</button>
  9. </view>
  10. </view>
  11. <!-- 列表区域 -->
  12. <scroll-view scroll-y class="content" @scrolltolower="loadMore">
  13. <view v-if="loading && list.length === 0" class="loading-container">
  14. <text>加载中...</text>
  15. </view>
  16. <view v-else-if="list.length === 0" class="empty-container">
  17. <text>暂无系统通知</text>
  18. </view>
  19. <view v-else>
  20. <view
  21. v-for="item in list"
  22. :key="item.id"
  23. class="system-item"
  24. @click="openDetail(item)"
  25. >
  26. <view class="item-left">
  27. <view class="icon-wrapper">
  28. <text class="icon">📢</text>
  29. <view v-if="item.isRead === 0" class="dot"></view>
  30. </view>
  31. </view>
  32. <view class="item-body">
  33. <view class="item-title-row">
  34. <text class="item-title">{{ item.title || '系统通知' }}</text>
  35. <text class="item-time">{{ formatTime(item.createdAt || item.created_at) }}</text>
  36. </view>
  37. <text class="item-content">{{ item.content }}</text>
  38. </view>
  39. </view>
  40. <view class="load-more" v-if="hasMore">
  41. {{ loading ? '加载中...' : '上拉加载更多' }}
  42. </view>
  43. <view class="load-more" v-else>没有更多了</view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </template>
  48. <script>
  49. import api from '@/utils/api.js'
  50. export default {
  51. data() {
  52. return {
  53. userId: null,
  54. list: [],
  55. pageNum: 1,
  56. pageSize: 20,
  57. hasMore: true,
  58. loading: false
  59. }
  60. },
  61. onLoad() {
  62. this.userId = uni.getStorageSync('userId')
  63. this.loadList()
  64. },
  65. methods: {
  66. async loadList() {
  67. if (this.loading || !this.hasMore) return
  68. this.loading = true
  69. try {
  70. const res = await api.message.getSystemList(this.userId, this.pageNum, this.pageSize)
  71. const data = (res && (res.list || res.data?.list)) || []
  72. this.list = this.list.concat(data)
  73. const total = (typeof res.total === 'number') ? res.total : (res.data?.total || this.list.length)
  74. this.hasMore = this.list.length < total
  75. this.pageNum++
  76. } catch (e) {
  77. } finally {
  78. this.loading = false
  79. }
  80. },
  81. loadMore() {
  82. this.loadList()
  83. },
  84. async markAllRead() {
  85. if (!this.userId) return
  86. try {
  87. await api.message.markAllSystemRead(this.userId)
  88. // 本地列表全部置为已读
  89. this.list.forEach(item => {
  90. item.isRead = 1
  91. })
  92. uni.showToast({ title: '已全部标记为已读', icon: 'success' })
  93. } catch (e) {
  94. uni.showToast({ title: '操作失败,请稍后重试', icon: 'none' })
  95. }
  96. },
  97. async openDetail(item) {
  98. try {
  99. const data = await api.message.getSystemDetail(item.id)
  100. if (item.isRead === 0) {
  101. try {
  102. await api.message.markSystemRead(item.id)
  103. item.isRead = 1
  104. } catch (e) {}
  105. }
  106. uni.showModal({
  107. title: data.title || '系统通知',
  108. content: (data.content || '').replace(/\n/g, '\n'),
  109. showCancel: false
  110. })
  111. } catch (e) {
  112. uni.showToast({ title: '获取详情失败', icon: 'none' })
  113. }
  114. },
  115. formatTime(t) {
  116. if (!t) return ''
  117. const d = new Date(t)
  118. const month = String(d.getMonth() + 1).padStart(2, '0')
  119. const day = String(d.getDate()).padStart(2, '0')
  120. const hour = String(d.getHours()).padStart(2, '0')
  121. const minute = String(d.getMinutes()).padStart(2, '0')
  122. return `${month}-${day} ${hour}:${minute}`
  123. },
  124. goBack() {
  125. uni.navigateBack()
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .matchmaker-system-page {
  132. min-height: 100vh;
  133. /* 与红娘消息页保持一致:顶部淡粉 -> 中部淡紫 -> 底部趋近白色 */
  134. background: linear-gradient(180deg, #fff1f7 0%, #f6ebff 45%, #fbf7ff 75%, #ffffff 100%);
  135. display: flex;
  136. flex-direction: column;
  137. }
  138. .header {
  139. display: flex;
  140. align-items: center;
  141. justify-content: space-between;
  142. padding: 25rpx 30rpx;
  143. padding-top: calc(25rpx + env(safe-area-inset-top));
  144. background: transparent;
  145. border-bottom-width: 0;
  146. .back-btn {
  147. width: 70rpx;
  148. height: 70rpx;
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. background: rgba(240, 240, 240, 0.5);
  153. border-radius: 50%;
  154. background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></svg>');
  155. background-size: 40rpx 40rpx;
  156. background-repeat: no-repeat;
  157. background-position: center;
  158. }
  159. .header-title {
  160. font-size: 36rpx;
  161. font-weight: bold;
  162. color: #333;
  163. }
  164. .placeholder {
  165. min-width: 120rpx;
  166. display: flex;
  167. justify-content: flex-end;
  168. align-items: center;
  169. .read-all-btn {
  170. min-width: 96rpx;
  171. height: 48rpx;
  172. line-height: 48rpx;
  173. padding: 0 12rpx;
  174. font-size: 22rpx;
  175. color: #666;
  176. background: #ffffff;
  177. border-radius: 999rpx;
  178. border: 1rpx solid #e5e5e5;
  179. box-shadow: 0 4rpx 10rpx rgba(0,0,0,0.04);
  180. text-align: center;
  181. }
  182. }
  183. }
  184. .content {
  185. flex: 1;
  186. padding: 20rpx 20rpx 120rpx;
  187. }
  188. .system-item {
  189. display: flex;
  190. padding: 26rpx 24rpx;
  191. margin-bottom: 20rpx;
  192. border-radius: 24rpx;
  193. background: #FFFFFF;
  194. box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.04);
  195. }
  196. .item-left {
  197. margin-right: 20rpx;
  198. .icon-wrapper {
  199. width: 64rpx;
  200. height: 64rpx;
  201. border-radius: 50%;
  202. background: linear-gradient(135deg, #b39ddb 0%, #ce93d8 100%);
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. position: relative;
  207. .icon {
  208. font-size: 32rpx;
  209. }
  210. .dot {
  211. position: absolute;
  212. top: -6rpx;
  213. right: -6rpx;
  214. width: 18rpx;
  215. height: 18rpx;
  216. border-radius: 50%;
  217. background: #FF4444;
  218. border: 2rpx solid #FFFFFF;
  219. }
  220. }
  221. }
  222. .item-body {
  223. flex: 1;
  224. min-width: 0;
  225. .item-title-row {
  226. display: flex;
  227. justify-content: space-between;
  228. align-items: center;
  229. margin-bottom: 8rpx;
  230. .item-title {
  231. font-size: 30rpx;
  232. font-weight: 500;
  233. color: #333;
  234. }
  235. .item-time {
  236. font-size: 24rpx;
  237. color: #b0a6c5;
  238. margin-left: 20rpx;
  239. flex-shrink: 0;
  240. }
  241. }
  242. .item-content {
  243. font-size: 26rpx;
  244. color: #777;
  245. line-height: 1.5;
  246. }
  247. }
  248. .loading-container,
  249. .empty-container {
  250. display: flex;
  251. justify-content: center;
  252. align-items: center;
  253. padding: 80rpx 0;
  254. color: #999;
  255. font-size: 28rpx;
  256. }
  257. .load-more {
  258. text-align: center;
  259. padding: 20rpx 0 40rpx;
  260. color: #999;
  261. font-size: 24rpx;
  262. }
  263. </style>