index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="yd-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>
  11. <wd-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/api-access-log'
  54. import { onMounted, ref } from 'vue'
  55. import { useToast } from 'wot-design-uni'
  56. import { getApiAccessLog } from '@/api/infra/api-access-log'
  57. import { getDictLabel } from '@/hooks/useDict'
  58. import { navigateBackPlus } from '@/utils'
  59. import { DICT_TYPE } from '@/utils/constants'
  60. import { formatDateTime } from '@/utils/date'
  61. const props = defineProps<{
  62. id: number | any
  63. }>()
  64. definePage({
  65. style: {
  66. navigationBarTitleText: '',
  67. navigationStyle: 'custom',
  68. },
  69. })
  70. const formData = ref<ApiAccessLog>() // 详情数据
  71. const toast = useToast()
  72. /** 返回上一页 */
  73. function handleBack() {
  74. navigateBackPlus('/pages-infra/api-access-log/index')
  75. }
  76. /** 复制文本并提示 */
  77. function handleCopyText(text?: string, title?: string) {
  78. if (!text || text === '-') {
  79. return
  80. }
  81. uni.setClipboardData({
  82. data: text,
  83. success: () => {
  84. uni.hideToast()
  85. toast.success(`${title || '内容'}已复制`)
  86. },
  87. })
  88. }
  89. /** 加载详情 */
  90. async function getDetail() {
  91. if (!props.id) {
  92. return
  93. }
  94. toast.loading('加载中...')
  95. try {
  96. formData.value = await getApiAccessLog(props.id)
  97. } finally {
  98. toast.close()
  99. }
  100. }
  101. /** 获取请求信息 */
  102. function getRequestInfo() {
  103. if (formData.value?.requestMethod && formData.value?.requestUrl) {
  104. return `${formData.value.requestMethod} ${formData.value.requestUrl}`
  105. }
  106. return '-'
  107. }
  108. /** 获取请求时间范围 */
  109. function getRequestTimeRange() {
  110. if (formData.value?.beginTime && formData.value?.endTime) {
  111. return `${formatDateTime(formData.value.beginTime)} ~ ${formatDateTime(formData.value.endTime)}`
  112. }
  113. return '-'
  114. }
  115. /** 初始化 */
  116. onMounted(() => {
  117. getDetail()
  118. })
  119. </script>
  120. <style lang="scss" scoped>
  121. </style>