index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <ContentWrap>
  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 getIntDictOptions(DICT_TYPE.USER_TYPE)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="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-access-log:export']"
  82. >
  83. <Icon icon="ep:download" class="mr-5px" /> 导出
  84. </el-button>
  85. </el-form-item>
  86. </el-form>
  87. </ContentWrap>
  88. <!-- 列表 -->
  89. <ContentWrap>
  90. <el-table v-loading="loading" :data="list">
  91. <el-table-column label="日志编号" align="center" prop="id" width="100" fix="right" />
  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" width="150" />
  99. <el-table-column label="请求方法" align="center" prop="requestMethod" width="80" />
  100. <el-table-column label="请求地址" align="center" prop="requestUrl" width="500" />
  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"> {{ scope.row.duration }} ms </template>
  108. </el-table-column>
  109. <el-table-column label="操作结果" align="center" prop="status">
  110. <template #default="scope">
  111. {{ scope.row.resultCode === 0 ? '成功' : '失败(' + scope.row.resultMsg + ')' }}
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="操作模块" align="center" prop="operateModule" width="180" />
  115. <el-table-column label="操作名" align="center" prop="operateName" width="180" />
  116. <el-table-column label="操作类型" align="center" prop="operateType">
  117. <template #default="scope">
  118. <dict-tag :type="DICT_TYPE.INFRA_OPERATE_TYPE" :value="scope.row.operateType" />
  119. </template>
  120. </el-table-column>
  121. <el-table-column label="操作" align="center" fixed="right" width="60">
  122. <template #default="scope">
  123. <el-button
  124. link
  125. type="primary"
  126. @click="openDetail(scope.row)"
  127. v-hasPermi="['infra:api-access-log:query']"
  128. >
  129. 详细
  130. </el-button>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. <!-- 分页组件 -->
  135. <Pagination
  136. :total="total"
  137. v-model:page="queryParams.pageNo"
  138. v-model:limit="queryParams.pageSize"
  139. @pagination="getList"
  140. />
  141. </ContentWrap>
  142. <!-- 表单弹窗:详情 -->
  143. <ApiAccessLogDetail ref="detailRef" />
  144. </template>
  145. <script lang="ts" setup>
  146. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  147. import download from '@/utils/download'
  148. import { formatDate } from '@/utils/formatTime'
  149. import * as ApiAccessLogApi from '@/api/infra/apiAccessLog'
  150. import ApiAccessLogDetail from './ApiAccessLogDetail.vue'
  151. defineOptions({ name: 'InfraApiAccessLog' })
  152. const message = useMessage() // 消息弹窗
  153. const loading = ref(true) // 列表的加载中
  154. const total = ref(0) // 列表的总页数
  155. const list = ref([]) // 列表的数据
  156. const queryParams = reactive({
  157. pageNo: 1,
  158. pageSize: 10,
  159. userId: null,
  160. userType: null,
  161. applicationName: null,
  162. requestUrl: null,
  163. duration: null,
  164. resultCode: null,
  165. beginTime: []
  166. })
  167. const queryFormRef = ref() // 搜索的表单
  168. const exportLoading = ref(false) // 导出的加载中
  169. /** 查询列表 */
  170. const getList = async () => {
  171. loading.value = true
  172. try {
  173. const data = await ApiAccessLogApi.getApiAccessLogPage(queryParams)
  174. list.value = data.list
  175. total.value = data.total
  176. } finally {
  177. loading.value = false
  178. }
  179. }
  180. /** 搜索按钮操作 */
  181. const handleQuery = () => {
  182. queryParams.pageNo = 1
  183. getList()
  184. }
  185. /** 重置按钮操作 */
  186. const resetQuery = () => {
  187. queryFormRef.value.resetFields()
  188. handleQuery()
  189. }
  190. /** 详情操作 */
  191. const detailRef = ref()
  192. const openDetail = (data: ApiAccessLogApi.ApiAccessLogVO) => {
  193. detailRef.value.open(data)
  194. }
  195. /** 导出按钮操作 */
  196. const handleExport = async () => {
  197. try {
  198. // 导出的二次确认
  199. await message.exportConfirm()
  200. // 发起导出
  201. exportLoading.value = true
  202. const data = await ApiAccessLogApi.exportApiAccessLog(queryParams)
  203. download.excel(data, 'API 访问日志.xls')
  204. } catch {
  205. } finally {
  206. exportLoading.value = false
  207. }
  208. }
  209. /** 初始化 **/
  210. onMounted(() => {
  211. getList()
  212. })
  213. </script>