index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <content-wrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="用户编号" prop="userId">
  12. <el-input
  13. v-model="queryParams.userId"
  14. placeholder="请输入用户编号"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="用户类型" prop="userType">
  21. <el-select
  22. v-model="queryParams.userType"
  23. placeholder="请选择用户类型"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getDictOptions(DICT_TYPE.USER_TYPE)"
  29. :key="parseInt(dict.value)"
  30. :label="dict.label"
  31. :value="parseInt(dict.value)"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="应用名" prop="applicationName">
  36. <el-input
  37. v-model="queryParams.applicationName"
  38. placeholder="请输入应用名"
  39. clearable
  40. @keyup.enter="handleQuery"
  41. class="!w-240px"
  42. />
  43. </el-form-item>
  44. <el-form-item label="请求时间" prop="beginTime">
  45. <el-date-picker
  46. v-model="queryParams.beginTime"
  47. value-format="yyyy-MM-dd HH:mm:ss"
  48. type="daterange"
  49. start-placeholder="开始日期"
  50. end-placeholder="结束日期"
  51. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  52. class="!w-240px"
  53. />
  54. </el-form-item>
  55. <el-form-item label="执行时长" prop="duration">
  56. <el-input
  57. v-model="queryParams.duration"
  58. placeholder="请输入执行时长"
  59. clearable
  60. @keyup.enter="handleQuery"
  61. class="!w-240px"
  62. />
  63. </el-form-item>
  64. <el-form-item label="结果码" prop="resultCode">
  65. <el-input
  66. v-model="queryParams.resultCode"
  67. placeholder="请输入结果码"
  68. clearable
  69. @keyup.enter="handleQuery"
  70. class="!w-240px"
  71. />
  72. </el-form-item>
  73. <el-form-item>
  74. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  75. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  76. <el-button
  77. type="success"
  78. plain
  79. @click="handleExport"
  80. :loading="exportLoading"
  81. v-hasPermi="['infra:api-error-log:export']"
  82. >
  83. <Icon icon="ep:download" class="mr-5px" /> 导出
  84. </el-button>
  85. </el-form-item>
  86. </el-form>
  87. </content-wrap>
  88. <!-- 列表 -->
  89. <content-wrap>
  90. <el-table v-loading="loading" :data="list">
  91. <el-table-column label="日志编号" align="center" prop="id" />
  92. <el-table-column label="用户编号" align="center" prop="userId" />
  93. <el-table-column label="用户类型" align="center" prop="userType">
  94. <template #default="scope">
  95. <dict-tag :type="DICT_TYPE.USER_TYPE" :value="scope.row.userType" />
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="应用名" align="center" prop="applicationName" />
  99. <el-table-column label="请求方法" align="center" prop="requestMethod" width="80" />
  100. <el-table-column label="请求地址" align="center" prop="requestUrl" width="250" />
  101. <el-table-column label="请求时间" align="center" prop="beginTime" width="180">
  102. <template #default="scope">
  103. <span>{{ formatDate(scope.row.beginTime) }}</span>
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="执行时长" align="center" prop="duration" width="180">
  107. <template #default="scope">
  108. <span>{{ scope.row.duration }} ms</span>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="操作结果" align="center" prop="status">
  112. <template #default="scope">
  113. <span>{{
  114. scope.row.resultCode === 0 ? '成功' : '失败(' + scope.row.resultMsg + ')'
  115. }}</span>
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="操作" align="center">
  119. <template #default="scope">
  120. <el-button
  121. link
  122. type="primary"
  123. @click="openDetail(scope.row)"
  124. v-hasPermi="['infra:api-access-log:query']"
  125. >
  126. 详细
  127. </el-button>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <!-- 分页组件 -->
  132. <Pagination
  133. :total="total"
  134. v-model:page="queryParams.pageNo"
  135. v-model:limit="queryParams.pageSize"
  136. @pagination="getList"
  137. />
  138. </content-wrap>
  139. <!-- 表单弹窗:详情 -->
  140. <ApiAccessLogDetail ref="detailRef" />
  141. </template>
  142. <script setup lang="ts" name="ApiAccessLog">
  143. import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  144. import download from '@/utils/download'
  145. import { formatDate } from '@/utils/formatTime'
  146. import * as ApiAccessLogApi from '@/api/infra/apiAccessLog'
  147. import ApiAccessLogDetail from './ApiAccessLogDetail.vue'
  148. const message = useMessage() // 消息弹窗
  149. const loading = ref(true) // 列表的加载中
  150. const total = ref(0) // 列表的总页数
  151. const list = ref([]) // 列表的数据
  152. const queryParams = reactive({
  153. pageNo: 1,
  154. pageSize: 10,
  155. userId: null,
  156. userType: null,
  157. applicationName: null,
  158. requestUrl: null,
  159. duration: null,
  160. resultCode: null,
  161. beginTime: []
  162. })
  163. const queryFormRef = ref() // 搜索的表单
  164. const exportLoading = ref(false) // 导出的加载中
  165. /** 查询列表 */
  166. const getList = async () => {
  167. loading.value = true
  168. try {
  169. const data = await ApiAccessLogApi.getApiAccessLogPage(queryParams)
  170. list.value = data.list
  171. total.value = data.total
  172. } finally {
  173. loading.value = false
  174. }
  175. }
  176. /** 搜索按钮操作 */
  177. const handleQuery = () => {
  178. queryParams.pageNo = 1
  179. getList()
  180. }
  181. /** 重置按钮操作 */
  182. const resetQuery = () => {
  183. queryFormRef.value.resetFields()
  184. handleQuery()
  185. }
  186. /** 详情操作 */
  187. const detailRef = ref()
  188. const openDetail = (data: ApiAccessLogApi.ApiAccessLogVO) => {
  189. detailRef.value.open(data)
  190. }
  191. /** 导出按钮操作 */
  192. const handleExport = async () => {
  193. try {
  194. // 导出的二次确认
  195. await message.exportConfirm()
  196. // 发起导出
  197. exportLoading.value = true
  198. const data = await ApiAccessLogApi.exportApiAccessLog(queryParams)
  199. download.excel(data, 'API 访问日志.xls')
  200. } catch {
  201. } finally {
  202. exportLoading.value = false
  203. }
  204. }
  205. /** 初始化 **/
  206. onMounted(() => {
  207. getList()
  208. })
  209. </script>