messageList.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="sub-page">
  3. <TopBar title="消息通知" show-back />
  4. <view class="px-4 pt-3">
  5. <!-- 筛选 -->
  6. <view class="filter-bar mb-3">
  7. <view
  8. v-for="type in filterTypes"
  9. :key="type.value"
  10. class="filter-chip"
  11. :class="{ 'filter-chip-active': currentFilter === type.value }"
  12. @click="currentFilter = type.value"
  13. >
  14. {{ type.label }}
  15. </view>
  16. </view>
  17. <view v-if="loading" class="py-10 text-center">
  18. <text class="empty-text">加载中...</text>
  19. </view>
  20. <view v-else-if="filteredMessages.length === 0">
  21. <EmptyState message="暂无消息" />
  22. </view>
  23. <view v-else class="glass-card">
  24. <uni-swipe-action
  25. v-for="msg in filteredMessages"
  26. :key="msg.id"
  27. :actions="[{text: '删除', color: '#ff3b30', key: 'delete'}]"
  28. @click="onSwipeAction(msg.id, $event)"
  29. >
  30. <view
  31. class="list-row"
  32. hover-class="row-hover"
  33. :hover-start-time="0"
  34. :hover-stay-time="120"
  35. @click="goToDetail(msg.id)"
  36. >
  37. <view class="icon-chip mr-3" :class="{ 'icon-chip-red': msg.type === 'urgent' }">
  38. <text class="uni-icons chip-glyph" :class="getTypeIcon(msg.type)"></text>
  39. <view v-if="!msg.read" class="unread-dot"></view>
  40. </view>
  41. <view class="flex-1 min-w-0 mr-2">
  42. <text class="row-title truncate">{{ msg.title }}</text>
  43. <text class="row-sub truncate">{{ msg.content.length > 20 ? msg.content.substring(0, 20) + '...' : msg.content }}</text>
  44. </view>
  45. <text class="row-date flex-shrink-0 mr-1">{{ formatTime(msg.createTime) }}</text>
  46. <text class="uni-icons uniui-arrowright row-arrow"></text>
  47. </view>
  48. </uni-swipe-action>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script setup lang="ts">
  54. import { ref, computed, onMounted } from 'vue'
  55. import TopBar from '../../components/common/TopBar.vue'
  56. import EmptyState from '../../components/common/EmptyState.vue'
  57. import UniSwipeAction from '../../components/uni-swipe-action/uni-swipe-action.vue'
  58. import { formatDate } from '../../utils'
  59. const loading = ref(false)
  60. const messages = ref<any[]>([])
  61. const currentFilter = ref('all')
  62. const filterTypes = [
  63. { value: 'all', label: '全部' },
  64. { value: 'task', label: '任务' },
  65. { value: 'system', label: '系统' },
  66. { value: 'urgent', label: '紧急' },
  67. ]
  68. const filteredMessages = computed(() => {
  69. if (currentFilter.value === 'all') return messages.value
  70. return messages.value.filter(m => m.type === currentFilter.value)
  71. })
  72. function getTypeIcon(type: string) {
  73. const map: Record<string, string> = {
  74. task: 'uniui-flag-filled',
  75. system: 'uniui-gear-filled',
  76. urgent: 'uniui-notification-filled',
  77. }
  78. return map[type] || 'uniui-chatbubble'
  79. }
  80. function formatTime(date: string) {
  81. return formatDate(date, 'MM-DD HH:mm')
  82. }
  83. function onSwipeAction(msgId: string, action: { key?: string }) {
  84. if (action.key === 'delete') {
  85. uni.showModal({
  86. title: '确认删除',
  87. content: '确定要删除这条消息吗?',
  88. success: (res) => {
  89. if (res.confirm) {
  90. messages.value = messages.value.filter(m => m.id !== msgId)
  91. uni.showToast({ title: '已删除', icon: 'success' })
  92. }
  93. }
  94. })
  95. }
  96. }
  97. function goToDetail(msgId: string) {
  98. uni.navigateTo({ url: `/subPackages/pages-sales/messageDetail?id=${msgId}` })
  99. }
  100. onMounted(() => {
  101. messages.value = [
  102. { id: '1', title: '新任务分配', content: '您有一条新的清掏任务待处理', type: 'task', read: false, createTime: '2026-06-22 14:30' },
  103. { id: '2', title: '任务即将到期', content: '积丹白鹭小区任务将于明日到期', type: 'urgent', read: false, createTime: '2026-06-22 10:00' },
  104. { id: '3', title: '系统维护通知', content: '系统将于今晚23:00-01:00进行维护', type: 'system', read: true, createTime: '2026-06-21 09:00' },
  105. { id: '4', title: '任务审核通过', content: '您发布的任务已通过审核', type: 'task', read: true, createTime: '2026-06-20 16:00' },
  106. ]
  107. })
  108. </script>
  109. <style scoped>
  110. .sub-page {
  111. max-width: 430px;
  112. margin: 0 auto;
  113. min-height: 100vh;
  114. background-color: #f6fbf9;
  115. padding-bottom: 24px;
  116. }
  117. /* 筛选条:默认白底灰边,激活态绿色 */
  118. .filter-bar {
  119. display: flex;
  120. gap: 8px;
  121. overflow-x: auto;
  122. }
  123. .filter-chip {
  124. padding: 6px 16px;
  125. border-radius: 999px;
  126. font-size: 13px;
  127. color: #6b7280;
  128. background-color: #ffffff;
  129. border: 1px solid #e5e7eb;
  130. flex-shrink: 0;
  131. }
  132. .filter-chip-active {
  133. color: #ffffff;
  134. font-weight: 600;
  135. background: linear-gradient(135deg, #368f6f 0%, #4ba98a 100%);
  136. border-color: transparent;
  137. }
  138. .glass-card {
  139. background-color: rgba(255, 255, 255, 0.85);
  140. backdrop-filter: blur(14px);
  141. -webkit-backdrop-filter: blur(14px);
  142. border: 1px solid rgba(164, 216, 152, 0.35);
  143. border-radius: 24px;
  144. box-shadow: 0 18px 50px -12px rgba(54, 143, 111, 0.28);
  145. overflow: hidden;
  146. margin-bottom: 12px;
  147. }
  148. .list-row {
  149. display: flex;
  150. align-items: center;
  151. padding: 13px 16px;
  152. border-top: 1px solid rgba(164, 216, 152, 0.18);
  153. }
  154. .row-title {
  155. display: block;
  156. font-size: 14px;
  157. font-weight: 500;
  158. color: #1f2937;
  159. }
  160. .row-sub {
  161. display: block;
  162. margin-top: 3px;
  163. font-size: 12px;
  164. color: #9ca3af;
  165. }
  166. .row-date {
  167. font-size: 12px;
  168. color: #9ca3af;
  169. }
  170. .row-hover {
  171. background-color: rgba(164, 216, 152, 0.1);
  172. }
  173. .row-arrow {
  174. font-size: 16px;
  175. color: #c4d0cb;
  176. flex-shrink: 0;
  177. }
  178. .icon-chip {
  179. position: relative;
  180. width: 42px;
  181. height: 42px;
  182. border-radius: 12px;
  183. flex-shrink: 0;
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. background-color: rgba(164, 216, 152, 0.2);
  188. }
  189. .icon-chip-red {
  190. background-color: rgba(239, 68, 68, 0.1);
  191. }
  192. .icon-chip-red .chip-glyph {
  193. color: #ef4444;
  194. }
  195. .chip-glyph {
  196. font-size: 20px;
  197. color: #368f6f;
  198. }
  199. .unread-dot {
  200. position: absolute;
  201. top: -3px;
  202. right: -3px;
  203. width: 10px;
  204. height: 10px;
  205. border-radius: 50%;
  206. background-color: #ef4444;
  207. border: 2px solid #ffffff;
  208. }
  209. .empty-text {
  210. font-size: 13px;
  211. color: #9ca3af;
  212. }
  213. </style>