index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="main_container custom_container">
  3. <div class="page_item end_item" >
  4. <div class="page_search">
  5. <div class="search_content">
  6. <div class="content_left">
  7. <div class="grade_title">后台操作日志监控</div>
  8. </div>
  9. </div>
  10. </div>
  11. <div class="page_jg_20"></div>
  12. <div class="page_search">
  13. <div class="search_content" style="justify-content: flex-start; gap: 20px;">
  14. <div class="content_left" >
  15. <FormSearchGroup :searchList="differentTypeLogSearchList" @searchChange="handleSearchChange"></FormSearchGroup>
  16. </div>
  17. <div class="content_right">
  18. <el-button type="primary" @click="handleSearch">查询</el-button>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="page_jg_10"></div>
  23. <Table :currentPage="currentPage" :pageSize="pageSize" :totalNum="totalNum" :tableColumns="tableColumns"
  24. :tableData="logTableData" @paginationChange="handlePaginationChange">
  25. <template #num="{ row, currentIndex }">
  26. {{ (currentIndex ?? 0) + pageSize * (currentPage - 1) }}
  27. </template>
  28. <template #action="{ row }">
  29. <div class="table_row_option">
  30. <span class="option_button_editor" @click="GoToLogMonitorDetail(row)">查看详情</span>
  31. </div>
  32. </template>
  33. </Table>
  34. <LogMonitorDetail v-model="detailVisible" :rowData="currentRow"></LogMonitorDetail>
  35. </div>
  36. </div>
  37. </template>
  38. <script setup lang="ts">
  39. import { ref, onMounted } from 'vue';
  40. import FormSearchGroup from '@/baseComponents/FormSearchGroup.vue';
  41. import Table from '@/baseComponents/Table.vue';
  42. import LogMonitorDetail from './LogMonitorDetail.vue';
  43. import { differentTypeLogSearchList } from './formSearchGroup'
  44. import { tableColumns } from './table'
  45. import { getLogHeadApi, getLogPageApi } from '@/api/logMonitor'
  46. const currentPage = ref(1)
  47. const totalNum = ref(0)
  48. const pageSize = ref(20)
  49. // 日志表格数据
  50. const logTableData = ref<any[]>([])
  51. // 搜索参数
  52. const searchParams = ref({
  53. schoolId: 0,
  54. accountTypeCode: 0,
  55. moduleCode: 0,
  56. operationTypeCode: 0,
  57. userAccount: '',
  58. })
  59. // 详情弹窗
  60. const detailVisible = ref(false)
  61. const currentRow = ref<any>({})
  62. // 打开日志详情弹窗
  63. const GoToLogMonitorDetail = (row: any) => {
  64. currentRow.value = row
  65. detailVisible.value = true
  66. }
  67. // 处理搜索变化
  68. const handleSearchChange = (data: Record<string, any>, key: string) => {
  69. const fieldMap: Record<string, string> = {
  70. schoolId: 'schoolId',
  71. accountType: 'accountTypeCode',
  72. moduleType: 'moduleCode',
  73. operationType: 'operationTypeCode',
  74. userAccount: 'userAccount',
  75. }
  76. if (fieldMap[key]) {
  77. const val = data[key]
  78. const field = fieldMap[key] as keyof typeof searchParams.value
  79. // userAccount 是字符串类型,其他是数字类型
  80. if (field === 'userAccount') {
  81. searchParams.value[field] = (val !== undefined && val !== null) ? String(val) : ''
  82. } else {
  83. searchParams.value[field] = (val !== undefined && val !== null && val !== '') ? Number(val) : 0
  84. }
  85. }
  86. currentPage.value = 1
  87. getLogTableData()
  88. }
  89. // 处理查询
  90. const handleSearch = () => {
  91. currentPage.value = 1
  92. getLogTableData()
  93. }
  94. // 获取日志表格数据
  95. const getLogTableData = async () => {
  96. try {
  97. const params = {
  98. ...searchParams.value,
  99. pageParam: {
  100. pageNum: currentPage.value,
  101. pageSize: pageSize.value,
  102. },
  103. }
  104. const res = await getLogPageApi(params)
  105. const data = res.data || res
  106. logTableData.value = data.records || []
  107. totalNum.value = data.total || 0
  108. } catch (err) {
  109. console.error('getLogPageApi 请求失败:', err)
  110. }
  111. }
  112. // 处理分页变化
  113. const handlePaginationChange = (data: { type: string; val: number }) => {
  114. if (data.type === 'currentPage') {
  115. currentPage.value = data.val
  116. } else if (data.type === 'pageSize') {
  117. pageSize.value = data.val
  118. currentPage.value = 1
  119. }
  120. getLogTableData()
  121. }
  122. // 获取日志头
  123. const getLogHead = async () => {
  124. try {
  125. const res = await getLogHeadApi()
  126. const data = res.data || res
  127. const optionMap: Record<string, { label: string; value: any }[]> = {
  128. accountType: (data.accountTypeList || []).map((item: any) => ({ label: item.name, value: item.code })),
  129. moduleType: (data.moduleTypeList || []).map((item: any) => ({ label: item.name, value: item.code })),
  130. operationType: (data.operationTypeList || []).map((item: any) => ({ label: item.name, value: item.code })),
  131. schoolId: (data.schoolList || []).map((item: any) => ({ label: item.schoolName, value: item.schoolId })),
  132. }
  133. differentTypeLogSearchList.value = differentTypeLogSearchList.value.map(item => {
  134. if (optionMap[item.key]) {
  135. item.options = optionMap[item.key]
  136. }
  137. return { ...item }
  138. })
  139. } catch (err) {
  140. console.error('getLogHeadApi 请求失败:', err)
  141. }
  142. }
  143. // 获取日志表格数据
  144. onMounted(async () => {
  145. await getLogHead()
  146. await getLogTableData()
  147. })
  148. </script>
  149. <style lang="scss" scoped>
  150. .page_search{
  151. .search_content{
  152. .content_right{
  153. :deep(.el-button){
  154. width: 100px !important;
  155. background-color: #2e64fa !important;
  156. color: #fff !important;
  157. border: none !important;
  158. }
  159. }
  160. }
  161. }
  162. </style>