log-list.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view>
  3. <!-- 搜索组件 -->
  4. <LogSearchForm @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.mobile }}
  17. </view>
  18. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_SEND_STATUS" :value="item.sendStatus" />
  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.SYSTEM_SMS_CHANNEL_CODE" :value="item.channelCode" />
  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. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="item.templateType" />
  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.templateContent }}</text>
  31. </view>
  32. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  33. <text class="mr-8rpx text-[#999]">发送时间:</text>
  34. <text>{{ formatDateTime(item.sendTime) || '-' }}</text>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 加载更多 -->
  39. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  40. <wd-status-tip image="content" tip="暂无短信日志数据" />
  41. </view>
  42. <wd-loadmore
  43. v-if="list.length > 0"
  44. :state="loadMoreState"
  45. @reload="loadMore"
  46. />
  47. </view>
  48. </view>
  49. </template>
  50. <script lang="ts" setup>
  51. import type { SmsLog } from '@/api/system/sms'
  52. import type { LoadMoreState } from '@/http/types'
  53. import { ref, watch } from 'vue'
  54. import { getSmsLogPage } from '@/api/system/sms'
  55. import { DICT_TYPE } from '@/utils/constants'
  56. import { formatDateTime } from '@/utils/date'
  57. import LogSearchForm from './log-search-form.vue'
  58. const props = defineProps<{
  59. active?: boolean
  60. }>()
  61. const total = ref(0)
  62. const list = ref<SmsLog[]>([])
  63. const loadMoreState = ref<LoadMoreState>('loading')
  64. const queryParams = ref({
  65. pageNo: 1,
  66. pageSize: 10,
  67. })
  68. const initialized = ref(false)
  69. /** 查询列表 */
  70. async function getList() {
  71. loadMoreState.value = 'loading'
  72. try {
  73. const data = await getSmsLogPage(queryParams.value)
  74. list.value = [...list.value, ...data.list]
  75. total.value = data.total
  76. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  77. } catch {
  78. queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
  79. loadMoreState.value = 'error'
  80. }
  81. }
  82. /** 搜索按钮操作 */
  83. function handleQuery(data?: Record<string, any>) {
  84. queryParams.value = {
  85. ...data,
  86. pageNo: 1,
  87. pageSize: queryParams.value.pageSize,
  88. }
  89. list.value = []
  90. getList()
  91. }
  92. /** 重置按钮操作 */
  93. function handleReset() {
  94. handleQuery()
  95. }
  96. /** 加载更多 */
  97. function loadMore() {
  98. if (loadMoreState.value === 'finished') {
  99. return
  100. }
  101. queryParams.value.pageNo++
  102. getList()
  103. }
  104. /** 查看详情 */
  105. function handleDetail(item: SmsLog) {
  106. uni.navigateTo({
  107. url: `/pages-system/sms/log/detail/index?id=${item.id}`,
  108. })
  109. }
  110. /** 监听 active 变化,首次激活时加载数据 */
  111. watch(
  112. () => props.active,
  113. (val) => {
  114. if (val && !initialized.value) {
  115. initialized.value = true
  116. getList()
  117. }
  118. },
  119. { immediate: true },
  120. )
  121. </script>