25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

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