system-messages.vue 7.1 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. console.log('红娘系统通知加载失败', e)
  78. } finally {
  79. this.loading = false
  80. }
  81. },
  82. loadMore() {
  83. this.loadList()
  84. },
  85. async markAllRead() {
  86. if (!this.userId) return
  87. try {
  88. await api.message.markAllSystemRead(this.userId)
  89. // 本地列表全部置为已读
  90. this.list.forEach(item => {
  91. item.isRead = 1
  92. })
  93. uni.showToast({ title: '已全部标记为已读', icon: 'success' })
  94. } catch (e) {
  95. console.log('一键已读失败', e)
  96. uni.showToast({ title: '操作失败,请稍后重试', icon: 'none' })
  97. }
  98. },
  99. async openDetail(item) {
  100. try {
  101. const data = await api.message.getSystemDetail(item.id)
  102. if (item.isRead === 0) {
  103. try {
  104. await api.message.markSystemRead(item.id)
  105. item.isRead = 1
  106. } catch (e) {}
  107. }
  108. uni.showModal({
  109. title: data.title || '系统通知',
  110. content: (data.content || '').replace(/\n/g, '\n'),
  111. showCancel: false
  112. })
  113. } catch (e) {
  114. uni.showToast({ title: '获取详情失败', icon: 'none' })
  115. }
  116. },
  117. formatTime(t) {
  118. if (!t) return ''
  119. const d = new Date(t)
  120. const month = String(d.getMonth() + 1).padStart(2, '0')
  121. const day = String(d.getDate()).padStart(2, '0')
  122. const hour = String(d.getHours()).padStart(2, '0')
  123. const minute = String(d.getMinutes()).padStart(2, '0')
  124. return `${month}-${day} ${hour}:${minute}`
  125. },
  126. goBack() {
  127. uni.navigateBack()
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .matchmaker-system-page {
  134. min-height: 100vh;
  135. /* 与红娘消息页保持一致:顶部淡粉 -> 中部淡紫 -> 底部趋近白色 */
  136. background: linear-gradient(180deg, #fff1f7 0%, #f6ebff 45%, #fbf7ff 75%, #ffffff 100%);
  137. display: flex;
  138. flex-direction: column;
  139. }
  140. .header {
  141. display: flex;
  142. align-items: center;
  143. justify-content: space-between;
  144. padding: 25rpx 30rpx;
  145. padding-top: calc(25rpx + env(safe-area-inset-top));
  146. background: transparent;
  147. border-bottom-width: 0;
  148. .back-btn {
  149. width: 70rpx;
  150. height: 70rpx;
  151. display: flex;
  152. align-items: center;
  153. justify-content: center;
  154. background: rgba(240, 240, 240, 0.5);
  155. border-radius: 50%;
  156. 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>');
  157. background-size: 40rpx 40rpx;
  158. background-repeat: no-repeat;
  159. background-position: center;
  160. }
  161. .header-title {
  162. font-size: 36rpx;
  163. font-weight: bold;
  164. color: #333;
  165. }
  166. .placeholder {
  167. min-width: 120rpx;
  168. display: flex;
  169. justify-content: flex-end;
  170. align-items: center;
  171. .read-all-btn {
  172. min-width: 96rpx;
  173. height: 48rpx;
  174. line-height: 48rpx;
  175. padding: 0 12rpx;
  176. font-size: 22rpx;
  177. color: #666;
  178. background: #ffffff;
  179. border-radius: 999rpx;
  180. border: 1rpx solid #e5e5e5;
  181. box-shadow: 0 4rpx 10rpx rgba(0,0,0,0.04);
  182. text-align: center;
  183. }
  184. }
  185. }
  186. .content {
  187. flex: 1;
  188. padding: 20rpx 20rpx 120rpx;
  189. }
  190. .system-item {
  191. display: flex;
  192. padding: 26rpx 24rpx;
  193. margin-bottom: 20rpx;
  194. border-radius: 24rpx;
  195. background: #FFFFFF;
  196. box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.04);
  197. }
  198. .item-left {
  199. margin-right: 20rpx;
  200. .icon-wrapper {
  201. width: 64rpx;
  202. height: 64rpx;
  203. border-radius: 50%;
  204. background: linear-gradient(135deg, #b39ddb 0%, #ce93d8 100%);
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. position: relative;
  209. .icon {
  210. font-size: 32rpx;
  211. }
  212. .dot {
  213. position: absolute;
  214. top: -6rpx;
  215. right: -6rpx;
  216. width: 18rpx;
  217. height: 18rpx;
  218. border-radius: 50%;
  219. background: #FF4444;
  220. border: 2rpx solid #FFFFFF;
  221. }
  222. }
  223. }
  224. .item-body {
  225. flex: 1;
  226. min-width: 0;
  227. .item-title-row {
  228. display: flex;
  229. justify-content: space-between;
  230. align-items: center;
  231. margin-bottom: 8rpx;
  232. .item-title {
  233. font-size: 30rpx;
  234. font-weight: 500;
  235. color: #333;
  236. }
  237. .item-time {
  238. font-size: 24rpx;
  239. color: #b0a6c5;
  240. margin-left: 20rpx;
  241. flex-shrink: 0;
  242. }
  243. }
  244. .item-content {
  245. font-size: 26rpx;
  246. color: #777;
  247. line-height: 1.5;
  248. }
  249. }
  250. .loading-container,
  251. .empty-container {
  252. display: flex;
  253. justify-content: center;
  254. align-items: center;
  255. padding: 80rpx 0;
  256. color: #999;
  257. font-size: 28rpx;
  258. }
  259. .load-more {
  260. text-align: center;
  261. padding: 20rpx 0 40rpx;
  262. color: #999;
  263. font-size: 24rpx;
  264. }
  265. </style>