Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

196 rader
3.7 KiB

  1. <template>
  2. <view class="page">
  3. <view v-if="list.length" class="msg-list">
  4. <view class="msg-item" v-for="item in list" :key="item.id" @tap="goDetail(item.id)">
  5. <view class="msg-icon" :class="item.type === 1 ? 'success' : 'fail'">
  6. <u-icon :name="item.type === 1 ? 'checkmark-circle-fill' : 'close-circle-fill'" size="22"
  7. :color="item.type === 1 ? '#52c41a' : '#f5222d'" />
  8. </view>
  9. <view class="msg-body">
  10. <view class="msg-title-row">
  11. <text class="msg-title">{{ item.title }}</text>
  12. <view v-if="!item.is_read" class="unread-dot"></view>
  13. </view>
  14. <text class="msg-desc">{{ item.content }}</text>
  15. <text class="msg-time">{{ item.create_time }}</text>
  16. </view>
  17. <text class="arrow">›</text>
  18. </view>
  19. </view>
  20. <view v-if="!loading && !list.length" class="empty">
  21. <u-icon name="bell" size="60" color="#ccc" />
  22. <text class="empty-text">暂无消息</text>
  23. </view>
  24. <view v-if="loading" class="loading-tip">
  25. <u-loading-icon size="24" />
  26. </view>
  27. <view v-if="!loading && finished && list.length" class="no-more">没有更多了</view>
  28. </view>
  29. </template>
  30. <script setup>
  31. import { ref } from 'vue'
  32. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  33. import { get } from '@/utils/request.js'
  34. const list = ref([])
  35. const page = ref(1)
  36. const loading = ref(false)
  37. const finished = ref(false)
  38. onLoad(() => {
  39. loadMessages()
  40. })
  41. onPullDownRefresh(() => {
  42. page.value = 1
  43. finished.value = false
  44. list.value = []
  45. loadMessages().then(() => uni.stopPullDownRefresh())
  46. })
  47. onReachBottom(() => {
  48. if (!finished.value && !loading.value) loadMessages()
  49. })
  50. const loadMessages = async () => {
  51. if (loading.value) return
  52. loading.value = true
  53. try {
  54. const res = await get('/api/mp/messages', { page: page.value, pageSize: 20 })
  55. const data = res.data || {}
  56. const items = data.data || []
  57. if (page.value === 1) {
  58. list.value = items
  59. } else {
  60. list.value.push(...items)
  61. }
  62. if (page.value >= (data.totalPages || 1)) {
  63. finished.value = true
  64. } else {
  65. page.value++
  66. }
  67. } catch (e) {}
  68. loading.value = false
  69. }
  70. const goDetail = (id) => {
  71. const item = list.value.find(m => m.id === id)
  72. if (item) item.is_read = 1
  73. uni.navigateTo({ url: `/pages/message/detail?id=${id}` })
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. .page {
  78. min-height: 100vh;
  79. background: #f4f4f5;
  80. padding: 24rpx;
  81. }
  82. .msg-item {
  83. display: flex;
  84. align-items: flex-start;
  85. background: #fff;
  86. border-radius: 10rpx;
  87. padding: 28rpx 24rpx;
  88. margin-bottom: 20rpx;
  89. border: 1rpx solid #ebeef5;
  90. }
  91. .msg-icon {
  92. width: 56rpx;
  93. height: 56rpx;
  94. border-radius: 50%;
  95. display: flex;
  96. align-items: center;
  97. justify-content: center;
  98. flex-shrink: 0;
  99. margin-right: 20rpx;
  100. margin-top: 4rpx;
  101. &.success {
  102. background: #f6ffed;
  103. }
  104. &.fail {
  105. background: #fff2f0;
  106. }
  107. }
  108. .msg-body {
  109. flex: 1;
  110. min-width: 0;
  111. }
  112. .msg-title-row {
  113. display: flex;
  114. align-items: center;
  115. gap: 12rpx;
  116. }
  117. .msg-title {
  118. font-size: 30rpx;
  119. font-weight: 600;
  120. color: #333;
  121. }
  122. .unread-dot {
  123. width: 14rpx;
  124. height: 14rpx;
  125. border-radius: 50%;
  126. background: #f5222d;
  127. flex-shrink: 0;
  128. }
  129. .msg-desc {
  130. font-size: 26rpx;
  131. color: #888;
  132. margin-top: 8rpx;
  133. display: -webkit-box;
  134. -webkit-line-clamp: 1;
  135. -webkit-box-orient: vertical;
  136. overflow: hidden;
  137. }
  138. .msg-time {
  139. font-size: 24rpx;
  140. color: #bbb;
  141. margin-top: 8rpx;
  142. }
  143. .arrow {
  144. color: #c0c4cc;
  145. font-size: 28rpx;
  146. flex-shrink: 0;
  147. margin-left: 12rpx;
  148. margin-top: 8rpx;
  149. }
  150. .empty {
  151. display: flex;
  152. flex-direction: column;
  153. align-items: center;
  154. padding-top: 200rpx;
  155. }
  156. .empty-text {
  157. font-size: 28rpx;
  158. color: #ccc;
  159. margin-top: 20rpx;
  160. }
  161. .loading-tip {
  162. display: flex;
  163. justify-content: center;
  164. padding: 40rpx 0;
  165. }
  166. .no-more {
  167. text-align: center;
  168. font-size: 24rpx;
  169. color: #ccc;
  170. padding: 30rpx 0;
  171. }
  172. </style>