index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="访问日志详情"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 详情内容 -->
  10. <view class="p-24rpx">
  11. <wd-cell-group custom-class="cell-group" border>
  12. <wd-cell title="日志编号" :value="String(formData?.id ?? '-')" />
  13. <wd-cell title="链路追踪" :value="formData?.traceId || '-'" />
  14. <wd-cell title="应用名" :value="formData?.applicationName || '-'" />
  15. <wd-cell title="用户编号" :value="String(formData?.userId ?? '-')" />
  16. <wd-cell title="用户类型" :value="getDictLabel(DICT_TYPE.USER_TYPE, formData?.userType) || '-'" />
  17. <wd-cell title="用户 IP" :value="formData?.userIp || '-'" />
  18. <wd-cell title="用户 UA" :value="formData?.userAgent || '-'" />
  19. <wd-cell title="请求信息" :value="getRequestInfo()" />
  20. <wd-cell title="请求参数" is-link @click="handleCopyText(formData?.requestParams, '请求参数')">
  21. <view class="max-w-400rpx truncate text-right">
  22. {{ formData?.requestParams || '-' }}
  23. </view>
  24. </wd-cell>
  25. <wd-cell title="请求结果" is-link @click="handleCopyText(formData?.responseBody, '请求结果')">
  26. <view class="max-w-400rpx truncate text-right">
  27. {{ formData?.responseBody || '-' }}
  28. </view>
  29. </wd-cell>
  30. <wd-cell title="请求时间" :value="getRequestTimeRange()" />
  31. <wd-cell title="请求耗时" :value="formData?.duration ? `${formData.duration} ms` : '-'" />
  32. <wd-cell title="操作结果">
  33. <template v-if="formData?.resultCode === 0">
  34. <wd-tag type="success" plain>
  35. 正常
  36. </wd-tag>
  37. </template>
  38. <template v-else-if="formData?.resultCode">
  39. <text>失败 | {{ formData.resultCode }} | {{ formData.resultMsg }}</text>
  40. </template>
  41. <template v-else>
  42. <text>-</text>
  43. </template>
  44. </wd-cell>
  45. <wd-cell title="操作模块" :value="formData?.operateModule || '-'" />
  46. <wd-cell title="操作名" :value="formData?.operateName || '-'" />
  47. <wd-cell title="操作类型" :value="getDictLabel(DICT_TYPE.INFRA_OPERATE_TYPE, formData?.operateType) || '-'" />
  48. </wd-cell-group>
  49. </view>
  50. </view>
  51. </template>
  52. <script lang="ts" setup>
  53. import type { ApiAccessLog } from '@/api/infra/apiAccessLog'
  54. import { onMounted, ref } from 'vue'
  55. import { getApiAccessLog } from '@/api/infra/apiAccessLog'
  56. import { getDictLabel } from '@/hooks/useDict'
  57. import { DICT_TYPE } from '@/utils/constants'
  58. import { formatDateTime } from '@/utils/date'
  59. const props = defineProps<{
  60. id: number
  61. }>()
  62. definePage({
  63. style: {
  64. navigationBarTitleText: '',
  65. navigationStyle: 'custom',
  66. },
  67. })
  68. const formData = ref<ApiAccessLog>() // 详情数据
  69. /** 返回上一页 */
  70. function handleBack() {
  71. uni.navigateBack()
  72. }
  73. /** 复制文本并提示 */
  74. function handleCopyText(text?: string, title?: string) {
  75. if (!text || text === '-') {
  76. return
  77. }
  78. uni.setClipboardData({
  79. data: text,
  80. success: () => {
  81. uni.showToast({
  82. title: `${title || '内容'}已复制`,
  83. icon: 'success',
  84. })
  85. },
  86. })
  87. }
  88. /** 加载详情 */
  89. async function getDetail() {
  90. if (!props.id) {
  91. return
  92. }
  93. formData.value = await getApiAccessLog(props.id)
  94. }
  95. /** 获取请求信息 */
  96. function getRequestInfo() {
  97. if (formData.value?.requestMethod && formData.value?.requestUrl) {
  98. return `${formData.value.requestMethod} ${formData.value.requestUrl}`
  99. }
  100. return '-'
  101. }
  102. /** 获取请求时间范围 */
  103. function getRequestTimeRange() {
  104. if (formData.value?.beginTime && formData.value?.endTime) {
  105. return `${formatDateTime(formData.value.beginTime)} ~ ${formatDateTime(formData.value.endTime)}`
  106. }
  107. return '-'
  108. }
  109. /** 初始化 */
  110. onMounted(() => {
  111. getDetail()
  112. })
  113. </script>
  114. <style lang="scss" scoped>
  115. :deep(.cell-group) {
  116. border-radius: 12rpx;
  117. overflow: hidden;
  118. box-shadow: 0 3rpx 8rpx rgba(24, 144, 255, 0.06);
  119. }
  120. </style>