messageList.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="sub-page">
  3. <TopBar title="消息通知" show-back>
  4. <template #right>
  5. <text class="right-link" @click="markAllRead">全部已读</text>
  6. </template>
  7. </TopBar>
  8. <view class="px-4 pt-3">
  9. <!-- 筛选 -->
  10. <view class="filter-bar mb-3">
  11. <view
  12. v-for="tab in filterTabs"
  13. :key="tab.value"
  14. class="filter-chip"
  15. :class="{ 'filter-chip-active': currentFilter === tab.value }"
  16. @click="currentFilter = tab.value"
  17. >
  18. {{ tab.label }}
  19. </view>
  20. </view>
  21. <view v-if="filteredMessages.length === 0">
  22. <EmptyState message="暂无消息" />
  23. </view>
  24. <view v-else class="glass-card">
  25. <view
  26. v-for="msg in filteredMessages"
  27. :key="msg.id"
  28. class="list-row"
  29. hover-class="row-hover"
  30. :hover-start-time="0"
  31. :hover-stay-time="120"
  32. @click="goToDetail(msg)"
  33. >
  34. <view class="icon-chip mr-3">
  35. <text class="uni-icons uniui-chatbubble-filled chip-glyph"></text>
  36. <view v-if="!msg.read" class="unread-dot"></view>
  37. </view>
  38. <view class="flex-1 min-w-0 mr-2">
  39. <text class="row-title truncate" :class="{ 'row-title-read': msg.read }">{{ msg.title }}</text>
  40. <text class="row-sub row-clamp">{{ msg.content }}</text>
  41. </view>
  42. <text class="row-date flex-shrink-0">{{ formatRelativeTime(msg.createTime) }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script setup lang="ts">
  49. import { ref, computed } from 'vue'
  50. import TopBar from '@/components/common/TopBar.vue'
  51. import EmptyState from '@/components/common/EmptyState.vue'
  52. import { useNotificationStore } from '@/stores/notification'
  53. import { formatRelativeTime, navigateTo } from '@/utils'
  54. const notificationStore = useNotificationStore()
  55. const currentFilter = ref('all')
  56. const filterTabs = [
  57. { label: '全部', value: 'all' },
  58. { label: '任务消息', value: 'task' },
  59. { label: '系统消息', value: 'system' },
  60. ]
  61. const filteredMessages = computed(() => {
  62. let list = notificationStore.notifications
  63. if (currentFilter.value !== 'all') {
  64. list = list.filter(n => n.type === currentFilter.value)
  65. }
  66. return list.map(n => ({
  67. ...n,
  68. content: n.content.length > 60 ? n.content.slice(0, 60) + '...' : n.content
  69. }))
  70. })
  71. function markAllRead() {
  72. notificationStore.markAllAsRead()
  73. }
  74. function goToDetail(msg: typeof filteredMessages.value[0]) {
  75. notificationStore.markAsRead(msg.id)
  76. uni.setStorageSync('current_message', msg)
  77. navigateTo('/subPackages/pages-common/messageDetail')
  78. }
  79. </script>
  80. <style scoped>
  81. .sub-page {
  82. max-width: 430px;
  83. margin: 0 auto;
  84. min-height: 100vh;
  85. background-color: #f6fbf9;
  86. padding-bottom: 24px;
  87. }
  88. .right-link {
  89. font-size: 13px;
  90. color: #368f6f;
  91. }
  92. /* 筛选条:默认白底灰边,激活态绿色 */
  93. .filter-bar {
  94. display: flex;
  95. gap: 8px;
  96. overflow-x: auto;
  97. }
  98. .filter-chip {
  99. padding: 6px 16px;
  100. border-radius: 999px;
  101. font-size: 13px;
  102. color: #6b7280;
  103. background-color: #ffffff;
  104. border: 1px solid #e5e7eb;
  105. flex-shrink: 0;
  106. }
  107. .filter-chip-active {
  108. color: #ffffff;
  109. font-weight: 600;
  110. background: linear-gradient(135deg, #368f6f 0%, #4ba98a 100%);
  111. border-color: transparent;
  112. }
  113. .glass-card {
  114. background-color: rgba(255, 255, 255, 0.85);
  115. backdrop-filter: blur(14px);
  116. -webkit-backdrop-filter: blur(14px);
  117. border: 1px solid rgba(164, 216, 152, 0.35);
  118. border-radius: 24px;
  119. box-shadow: 0 18px 50px -12px rgba(54, 143, 111, 0.28);
  120. overflow: hidden;
  121. margin-bottom: 12px;
  122. }
  123. .list-row {
  124. display: flex;
  125. align-items: center;
  126. padding: 13px 16px;
  127. border-top: 1px solid rgba(164, 216, 152, 0.18);
  128. }
  129. .list-row:first-child {
  130. border-top: none;
  131. }
  132. .row-hover {
  133. background-color: rgba(164, 216, 152, 0.1);
  134. }
  135. .icon-chip {
  136. position: relative;
  137. width: 42px;
  138. height: 42px;
  139. border-radius: 12px;
  140. flex-shrink: 0;
  141. display: flex;
  142. align-items: center;
  143. justify-content: center;
  144. background-color: rgba(164, 216, 152, 0.2);
  145. }
  146. .chip-glyph {
  147. font-size: 20px;
  148. color: #368f6f;
  149. }
  150. .unread-dot {
  151. position: absolute;
  152. top: -3px;
  153. right: -3px;
  154. width: 10px;
  155. height: 10px;
  156. border-radius: 50%;
  157. background-color: #ef4444;
  158. border: 2px solid #ffffff;
  159. }
  160. .row-title {
  161. display: block;
  162. font-size: 14px;
  163. font-weight: 600;
  164. color: #1f2937;
  165. }
  166. .row-title-read {
  167. font-weight: 500;
  168. color: #6b7280;
  169. }
  170. .row-sub {
  171. display: block;
  172. margin-top: 3px;
  173. font-size: 12px;
  174. color: #9ca3af;
  175. }
  176. .row-clamp {
  177. display: -webkit-box;
  178. -webkit-line-clamp: 2;
  179. -webkit-box-orient: vertical;
  180. overflow: hidden;
  181. }
  182. .row-date {
  183. font-size: 12px;
  184. color: #9ca3af;
  185. }
  186. </style>