index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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="username">
  13. <el-input
  14. v-model="queryParams.username"
  15. placeholder="请输入用户名称"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item label="登录地址" prop="userIp">
  22. <el-input
  23. v-model="queryParams.userIp"
  24. placeholder="请输入登录地址"
  25. clearable
  26. @keyup.enter="handleQuery"
  27. class="!w-240px"
  28. />
  29. </el-form-item>
  30. <el-form-item label="登录日期" prop="createTime">
  31. <el-date-picker
  32. v-model="queryParams.createTime"
  33. value-format="YYYY-MM-DD HH:mm:ss"
  34. type="daterange"
  35. start-placeholder="开始日期"
  36. end-placeholder="结束日期"
  37. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  38. class="!w-240px"
  39. />
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  43. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  44. <el-button
  45. type="success"
  46. plain
  47. @click="handleExport"
  48. :loading="exportLoading"
  49. v-hasPermi="['infra:config:export']"
  50. >
  51. <Icon icon="ep:download" class="mr-5px" /> 导出
  52. </el-button>
  53. </el-form-item>
  54. </el-form>
  55. </ContentWrap>
  56. <!-- 列表 -->
  57. <ContentWrap>
  58. <el-table v-loading="loading" :data="list">
  59. <el-table-column label="日志编号" align="center" prop="id" />
  60. <el-table-column label="操作类型" align="center" prop="logType">
  61. <template #default="scope">
  62. <dict-tag :type="DICT_TYPE.SYSTEM_LOGIN_TYPE" :value="scope.row.logType" />
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="用户名称" align="center" prop="username" width="180" />
  66. <el-table-column label="登录地址" align="center" prop="userIp" width="180" />
  67. <el-table-column label="浏览器" align="center" prop="userAgent" />
  68. <el-table-column label="登陆结果" align="center" prop="result">
  69. <template #default="scope">
  70. <dict-tag :type="DICT_TYPE.SYSTEM_LOGIN_RESULT" :value="scope.row.result" />
  71. </template>
  72. </el-table-column>
  73. <el-table-column
  74. label="登录日期"
  75. align="center"
  76. prop="createTime"
  77. width="180"
  78. :formatter="dateFormatter"
  79. />
  80. <el-table-column label="操作" align="center">
  81. <template #default="scope">
  82. <el-button
  83. link
  84. type="primary"
  85. @click="openDetail(scope.row)"
  86. v-hasPermi="['infra:config:query']"
  87. >
  88. 详情
  89. </el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <!-- 分页 -->
  94. <Pagination
  95. :total="total"
  96. v-model:page="queryParams.pageNo"
  97. v-model:limit="queryParams.pageSize"
  98. @pagination="getList"
  99. />
  100. </ContentWrap>
  101. <!-- 表单弹窗:详情 -->
  102. <LoginLogDetail ref="detailRef" />
  103. </template>
  104. <script lang="ts" setup>
  105. import { DICT_TYPE } from '@/utils/dict'
  106. import { dateFormatter } from '@/utils/formatTime'
  107. import download from '@/utils/download'
  108. import * as LoginLogApi from '@/api/system/loginLog'
  109. import LoginLogDetail from './LoginLogDetail.vue'
  110. defineOptions({ name: 'SystemLoginLog' })
  111. const message = useMessage() // 消息弹窗
  112. const loading = ref(true) // 列表的加载中
  113. const total = ref(0) // 列表的总页数
  114. const list = ref([]) // 列表的数据
  115. const queryParams = reactive({
  116. pageNo: 1,
  117. pageSize: 10,
  118. username: undefined,
  119. userIp: undefined,
  120. createTime: []
  121. })
  122. const queryFormRef = ref() // 搜索的表单
  123. const exportLoading = ref(false) // 导出的加载中
  124. /** 查询列表 */
  125. const getList = async () => {
  126. loading.value = true
  127. try {
  128. const data = await LoginLogApi.getLoginLogPage(queryParams)
  129. list.value = data.list
  130. total.value = data.total
  131. } finally {
  132. loading.value = false
  133. }
  134. }
  135. /** 搜索按钮操作 */
  136. const handleQuery = () => {
  137. queryParams.pageNo = 1
  138. getList()
  139. }
  140. /** 重置按钮操作 */
  141. const resetQuery = () => {
  142. queryFormRef.value.resetFields()
  143. handleQuery()
  144. }
  145. /** 详情操作 */
  146. const detailRef = ref()
  147. const openDetail = (data: LoginLogApi.LoginLogVO) => {
  148. detailRef.value.open(data)
  149. }
  150. /** 导出按钮操作 */
  151. const handleExport = async () => {
  152. try {
  153. // 导出的二次确认
  154. await message.exportConfirm()
  155. // 发起导出
  156. exportLoading.value = true
  157. const data = await LoginLogApi.exportLoginLog(queryParams)
  158. download.excel(data, '登录日志.xls')
  159. } catch {
  160. } finally {
  161. exportLoading.value = false
  162. }
  163. }
  164. /** 初始化 **/
  165. onMounted(() => {
  166. getList()
  167. })
  168. </script>