message-list.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view>
  3. <!-- 搜索组件 -->
  4. <MessageSearchForm @search="handleQuery" @reset="handleReset" />
  5. <!-- 消息列表 -->
  6. <view class="p-24rpx">
  7. <view
  8. v-for="item in list"
  9. :key="item.id"
  10. class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
  11. @click="handleDetail(item)"
  12. >
  13. <view class="p-24rpx">
  14. <view class="mb-16rpx flex items-center justify-between">
  15. <view class="text-32rpx text-[#333] font-semibold">
  16. {{ item.templateNickname || '-' }}
  17. </view>
  18. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="item.readStatus" />
  19. </view>
  20. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  21. <text class="mr-8rpx shrink-0 text-[#999]">用户类型:</text>
  22. <dict-tag :type="DICT_TYPE.USER_TYPE" :value="item.userType" />
  23. </view>
  24. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  25. <text class="mr-8rpx shrink-0 text-[#999]">用户编号:</text>
  26. <text class="min-w-0 flex-1 truncate">{{ item.userId }}</text>
  27. </view>
  28. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  29. <text class="mr-8rpx shrink-0 text-[#999]">模板编码:</text>
  30. <text class="min-w-0 flex-1 truncate">{{ item.templateCode }}</text>
  31. </view>
  32. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  33. <text class="mr-8rpx shrink-0 text-[#999]">模版类型:</text>
  34. <dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="item.templateType" />
  35. </view>
  36. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  37. <text class="mr-8rpx shrink-0 text-[#999]">模版内容:</text>
  38. <text class="min-w-0 flex-1 truncate">{{ item.templateContent }}</text>
  39. </view>
  40. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  41. <text class="mr-8rpx text-[#999]">创建时间:</text>
  42. <text>{{ formatDateTime(item.createTime) || '-' }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 加载更多 -->
  47. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  48. <wd-status-tip image="content" tip="暂无站内信消息数据" />
  49. </view>
  50. <wd-loadmore
  51. v-if="list.length > 0"
  52. :state="loadMoreState"
  53. @reload="loadMore"
  54. />
  55. </view>
  56. </view>
  57. </template>
  58. <script lang="ts" setup>
  59. import type { NotifyMessage } from '@/api/system/notify/message'
  60. import type { LoadMoreState } from '@/http/types'
  61. import { ref } from 'vue'
  62. import { getNotifyMessagePage } from '@/api/system/notify/message'
  63. import { DICT_TYPE } from '@/utils/constants'
  64. import { formatDateTime } from '@/utils/date'
  65. import MessageSearchForm from './message-search-form.vue'
  66. const total = ref(0)
  67. const list = ref<NotifyMessage[]>([])
  68. const loadMoreState = ref<LoadMoreState>('loading')
  69. const queryParams = ref({
  70. pageNo: 1,
  71. pageSize: 10,
  72. })
  73. /** 查询列表 */
  74. async function getList() {
  75. loadMoreState.value = 'loading'
  76. try {
  77. const data = await getNotifyMessagePage(queryParams.value)
  78. list.value = [...list.value, ...data.list]
  79. total.value = data.total
  80. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  81. } catch {
  82. queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
  83. loadMoreState.value = 'error'
  84. }
  85. }
  86. /** 搜索按钮操作 */
  87. function handleQuery(data?: Record<string, any>) {
  88. queryParams.value = {
  89. ...data,
  90. pageNo: 1,
  91. pageSize: queryParams.value.pageSize,
  92. }
  93. list.value = []
  94. getList()
  95. }
  96. /** 重置按钮操作 */
  97. function handleReset() {
  98. handleQuery()
  99. }
  100. /** 加载更多 */
  101. function loadMore() {
  102. if (loadMoreState.value === 'finished') {
  103. return
  104. }
  105. queryParams.value.pageNo++
  106. getList()
  107. }
  108. /** 查看详情 */
  109. function handleDetail(item: NotifyMessage) {
  110. uni.navigateTo({
  111. url: `/pages-system/notify/message/detail/index?id=${item.id}`,
  112. })
  113. }
  114. /** 触底加载更多 */
  115. onReachBottom(() => {
  116. loadMore()
  117. })
  118. /** 初始化 */
  119. onMounted(() => {
  120. getList()
  121. })
  122. </script>