index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="API 错误日志"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 搜索组件 -->
  10. <SearchForm
  11. :search-params="queryParams"
  12. @search="handleQuery"
  13. @reset="handleReset"
  14. />
  15. <!-- 日志列表 -->
  16. <view class="p-24rpx">
  17. <view
  18. v-for="item in list"
  19. :key="item.id"
  20. class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
  21. @click="handleDetail(item)"
  22. >
  23. <view class="p-24rpx">
  24. <view class="mb-16rpx flex items-center justify-between">
  25. <view class="line-clamp-1 mr-16rpx flex-1 text-28rpx text-[#333] font-semibold">
  26. {{ item.exceptionName }}
  27. </view>
  28. <!-- DONE @芽艺:字典 -->
  29. <dict-tag :type="DICT_TYPE.INFRA_API_ERROR_LOG_PROCESS_STATUS" :value="item.processStatus" />
  30. </view>
  31. <view class="mb-12rpx flex text-26rpx text-[#666]">
  32. <text class="mr-8rpx flex-shrink-0 text-[#999]">请求:</text>
  33. <text class="line-clamp-2 break-all">{{ item.requestMethod }} {{ item.requestUrl }}</text>
  34. </view>
  35. <view class="mb-12rpx flex items-center text-26rpx text-[#666]">
  36. <text class="mr-8rpx text-[#999]">应用名:</text>
  37. <text>{{ item.applicationName }}</text>
  38. </view>
  39. <view class="mb-12rpx flex items-center text-26rpx text-[#666]">
  40. <text class="mr-8rpx text-[#999]">用户编号:</text>
  41. <text>{{ item.userId }}</text>
  42. </view>
  43. <view class="flex items-center text-24rpx text-[#999]">
  44. <text>{{ formatDateTime(item.exceptionTime) }}</text>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 加载更多 -->
  49. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  50. <wd-status-tip image="content" tip="暂无日志数据" />
  51. </view>
  52. <wd-loadmore
  53. v-if="list.length > 0"
  54. :state="loadMoreState"
  55. @reload="loadMore"
  56. />
  57. </view>
  58. </view>
  59. </template>
  60. <script lang="ts" setup>
  61. import type { SearchFormData } from './components/search-form.vue'
  62. import type { ApiErrorLog } from '@/api/infra/apiErrorLog'
  63. import type { LoadMoreState } from '@/http/types'
  64. import { onReachBottom } from '@dcloudio/uni-app'
  65. import { onMounted, reactive, ref } from 'vue'
  66. import { getApiErrorLogPage } from '@/api/infra/apiErrorLog'
  67. import { DICT_TYPE } from '@/utils/constants'
  68. import { formatDateTime } from '@/utils/date'
  69. import { navigateBackPlus } from '@/utils'
  70. import SearchForm from './components/search-form.vue'
  71. definePage({
  72. style: {
  73. navigationBarTitleText: '',
  74. navigationStyle: 'custom',
  75. },
  76. })
  77. const total = ref(0) // 列表的总页数
  78. const list = ref<ApiErrorLog[]>([]) // 列表的数据
  79. const loadMoreState = ref<LoadMoreState>('loading') // 加载更多状态
  80. const queryParams = reactive({
  81. pageNo: 1,
  82. pageSize: 10,
  83. userId: undefined as number | undefined,
  84. applicationName: undefined as string | undefined,
  85. processStatus: -1 as number, // -1 表示全部
  86. })
  87. /** 返回上一页 */
  88. function handleBack() {
  89. navigateBackPlus()
  90. }
  91. /** 查询日志列表 */
  92. async function getList() {
  93. loadMoreState.value = 'loading'
  94. try {
  95. const data = await getApiErrorLogPage({
  96. ...queryParams,
  97. processStatus: queryParams.processStatus === -1 ? undefined : queryParams.processStatus,
  98. })
  99. list.value = [...list.value, ...data.list]
  100. total.value = data.total
  101. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  102. } catch {
  103. queryParams.pageNo = queryParams.pageNo > 1 ? queryParams.pageNo - 1 : 1
  104. loadMoreState.value = 'error'
  105. }
  106. }
  107. /** 搜索按钮操作 */
  108. function handleQuery(data?: SearchFormData) {
  109. queryParams.userId = data?.userId
  110. queryParams.applicationName = data?.applicationName
  111. queryParams.processStatus = data?.processStatus ?? -1
  112. queryParams.pageNo = 1
  113. list.value = [] // 清空列表
  114. getList()
  115. }
  116. /** 重置按钮操作 */
  117. function handleReset() {
  118. handleQuery()
  119. }
  120. /** 加载更多 */
  121. function loadMore() {
  122. if (loadMoreState.value === 'finished') {
  123. return
  124. }
  125. queryParams.pageNo++
  126. getList()
  127. }
  128. /** 查看详情 */
  129. function handleDetail(item: ApiErrorLog) {
  130. uni.navigateTo({
  131. url: `/pages-infra/apiErrorLog/detail/index?id=${item.id}`,
  132. })
  133. }
  134. /** 触底加载更多 */
  135. onReachBottom(() => {
  136. loadMore()
  137. })
  138. /** 初始化 */
  139. onMounted(() => {
  140. getList()
  141. })
  142. </script>
  143. <style lang="scss" scoped>
  144. </style>