index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script setup lang="ts">
  2. import { ref } from 'vue'
  3. import dayjs from 'dayjs'
  4. import { DICT_TYPE } from '@/utils/dict'
  5. import { useTable } from '@/hooks/web/useTable'
  6. import { useI18n } from '@/hooks/web/useI18n'
  7. import type { ApiAccessLogVO } from '@/api/infra/apiAccessLog/types'
  8. import { allSchemas } from './apiAccessLog.data'
  9. import * as ApiAccessLogApi from '@/api/infra/apiAccessLog'
  10. const { t } = useI18n() // 国际化
  11. // ========== 列表相关 ==========
  12. const { register, tableObject, methods } = useTable<ApiAccessLogVO>({
  13. getListApi: ApiAccessLogApi.getApiAccessLogPageApi
  14. })
  15. const { getList, setSearchParams } = methods
  16. // ========== 详情相关 ==========
  17. const detailRef = ref() // 详情 Ref
  18. const dialogVisible = ref(false) // 是否显示弹出层
  19. const dialogTitle = ref('') // 弹出层标题
  20. // 详情操作
  21. const handleDetail = (row: ApiAccessLogVO) => {
  22. // 设置数据
  23. detailRef.value = row
  24. dialogTitle.value = t('action.detail')
  25. dialogVisible.value = true
  26. }
  27. // ========== 初始化 ==========
  28. getList()
  29. </script>
  30. <template>
  31. <!-- 搜索工作区 -->
  32. <ContentWrap>
  33. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  34. </ContentWrap>
  35. <ContentWrap>
  36. <!-- 列表 -->
  37. <Table
  38. :columns="allSchemas.tableColumns"
  39. :selection="false"
  40. :data="tableObject.tableList"
  41. :loading="tableObject.loading"
  42. :pagination="{
  43. total: tableObject.total
  44. }"
  45. v-model:pageSize="tableObject.pageSize"
  46. v-model:currentPage="tableObject.currentPage"
  47. @register="register"
  48. >
  49. <template #userType="{ row }">
  50. <DictTag :type="DICT_TYPE.USER_TYPE" :value="row.userType" />
  51. </template>
  52. <template #beginTime="{ row }">
  53. <span>{{ dayjs(row.beginTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  54. </template>
  55. <template #duration="{ row }">
  56. <span>{{ row.duration + 'ms' }}</span>
  57. </template>
  58. <template #resultCode="{ row }">
  59. <span>{{ row.resultCode === 0 ? '成功' : '失败(' + row.resultMsg + ')' }}</span>
  60. </template>
  61. <template #action="{ row }">
  62. <el-button
  63. link
  64. type="primary"
  65. v-hasPermi="['infra:api-access-log:query']"
  66. @click="handleDetail(row)"
  67. >
  68. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  69. </el-button>
  70. </template>
  71. </Table>
  72. </ContentWrap>
  73. <Dialog v-model="dialogVisible" :title="dialogTitle">
  74. <!-- 对话框(详情) -->
  75. <Descriptions :schema="allSchemas.detailSchema" :data="detailRef">
  76. <template #userType="{ row }">
  77. <DictTag :type="DICT_TYPE.USER_TYPE" :value="row.userType" />
  78. </template>
  79. <template #beginTime="{ row }">
  80. <span>{{ dayjs(row.beginTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  81. </template>
  82. <template #duration="{ row }">
  83. <span>{{ row.duration + 'ms' }}</span>
  84. </template>
  85. <template #resultCode="{ row }">
  86. <span>{{ row.resultCode === 0 ? '成功' : '失败(' + row.resultMsg + ')' }}</span>
  87. </template>
  88. </Descriptions>
  89. <!-- 操作按钮 -->
  90. <template #footer>
  91. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  92. </template>
  93. </Dialog>
  94. </template>