index.vue 6.5 KB

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