2024-10-22 13:19:13 +08:00
|
|
|
<template>
|
2025-09-11 11:03:14 +08:00
|
|
|
<div class="table-box">
|
|
|
|
|
<ProTable ref="proTable" :columns="columns" :request-api="getTableList">
|
|
|
|
|
<!-- 表格 header 按钮 -->
|
|
|
|
|
<template #tableHeader>
|
2025-10-28 09:26:19 +08:00
|
|
|
<!-- <el-button type="primary" :icon="DataAnalysis">分析</el-button>-->
|
|
|
|
|
<el-button type="primary" icon="Download" @click="handleExport">导出csv</el-button>
|
2025-09-11 11:03:14 +08:00
|
|
|
</template>
|
|
|
|
|
</ProTable>
|
|
|
|
|
</div>
|
2024-10-22 13:19:13 +08:00
|
|
|
</template>
|
2025-09-11 11:03:14 +08:00
|
|
|
<script setup lang="tsx" name="useProTable">
|
2024-10-22 14:47:25 +08:00
|
|
|
// 根据实际路径调整
|
|
|
|
|
import TimeControl from '@/components/TimeControl/index.vue'
|
2024-10-22 13:19:13 +08:00
|
|
|
import ProTable from '@/components/ProTable/index.vue'
|
2025-09-11 11:03:14 +08:00
|
|
|
import type { ColumnProps, ProTableInstance } from '@/components/ProTable/interface'
|
|
|
|
|
import { reactive, ref } from 'vue'
|
|
|
|
|
import { exportCsv, getAuditLog } from '@/api/system/log'
|
|
|
|
|
import { useDownload } from '@/hooks/useDownload'
|
2025-01-15 09:35:36 +08:00
|
|
|
|
2025-02-13 15:40:13 +08:00
|
|
|
// defineOptions({
|
|
|
|
|
// name: 'log'
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
const startDate = ref('')
|
|
|
|
|
const endDate = ref('')
|
2024-10-22 13:19:13 +08:00
|
|
|
// ProTable 实例
|
|
|
|
|
const proTable = ref<ProTableInstance>()
|
2025-01-15 09:35:36 +08:00
|
|
|
|
2025-02-13 15:40:13 +08:00
|
|
|
const getTableList = async (params: any) => {
|
2025-09-11 11:03:14 +08:00
|
|
|
let newParams = JSON.parse(JSON.stringify(params))
|
|
|
|
|
newParams.searchEndTime = endDate.value
|
|
|
|
|
newParams.searchBeginTime = startDate.value
|
|
|
|
|
return getAuditLog(newParams)
|
2025-02-13 15:40:13 +08:00
|
|
|
}
|
2025-01-15 09:35:36 +08:00
|
|
|
|
2024-10-22 13:19:13 +08:00
|
|
|
// 表格配置项
|
2025-09-11 11:03:14 +08:00
|
|
|
const columns = reactive<ColumnProps[]>([
|
|
|
|
|
{ type: 'selection', fixed: 'left', width: 70 },
|
|
|
|
|
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
|
|
|
|
|
{
|
|
|
|
|
prop: 'userName',
|
|
|
|
|
label: '操作用户',
|
|
|
|
|
search: { el: 'input' },
|
|
|
|
|
minWidth: 100
|
2024-10-22 14:47:25 +08:00
|
|
|
},
|
2025-09-11 11:03:14 +08:00
|
|
|
{
|
|
|
|
|
prop: 'ip',
|
|
|
|
|
label: 'IP',
|
|
|
|
|
minWidth: 120
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
prop: 'logTime',
|
|
|
|
|
label: '记录时间',
|
|
|
|
|
minWidth: 180,
|
|
|
|
|
search: {
|
|
|
|
|
render: () => {
|
|
|
|
|
return (
|
|
|
|
|
<div class="flx-flex-start">
|
|
|
|
|
<TimeControl
|
|
|
|
|
include={['日', '周', '月', '自定义']}
|
|
|
|
|
default={'月'}
|
|
|
|
|
onUpdate-dates={handleDateChange}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-15 09:45:00 +08:00
|
|
|
},
|
2025-09-11 11:03:14 +08:00
|
|
|
{
|
|
|
|
|
label: '事件描述',
|
|
|
|
|
minWidth: 450,
|
|
|
|
|
render(scope) {
|
|
|
|
|
return `${scope.row.userName}在${scope.row.logTime}执行了【${scope.row.operateType}】${scope.row.operate}操作,结果为${scope.row.result}。`
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
prop: 'result',
|
|
|
|
|
label: '事件结果',
|
|
|
|
|
minWidth: 120
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
prop: 'warn',
|
|
|
|
|
label: '告警标志',
|
|
|
|
|
minWidth: 100,
|
|
|
|
|
render: scope => {
|
|
|
|
|
return (
|
|
|
|
|
<el-tag type={scope.row.warn == 1 ? 'danger' : 'success'}>
|
|
|
|
|
{scope.row.warn == 1 ? '已告警' : '未告警'}
|
|
|
|
|
</el-tag>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
prop: 'operateType',
|
|
|
|
|
label: '日志类型',
|
|
|
|
|
width: 100
|
|
|
|
|
}
|
2024-10-22 13:19:13 +08:00
|
|
|
])
|
|
|
|
|
|
2025-04-15 09:45:00 +08:00
|
|
|
// 处理日期变化的回调函数
|
2025-02-13 15:40:13 +08:00
|
|
|
const handleDateChange = (startDateTemp: string, endDateTemp: string) => {
|
2025-09-11 11:03:14 +08:00
|
|
|
startDate.value = startDateTemp
|
|
|
|
|
endDate.value = endDateTemp
|
2024-10-22 14:47:25 +08:00
|
|
|
}
|
2024-10-23 19:30:11 +08:00
|
|
|
|
2025-04-15 09:45:00 +08:00
|
|
|
const handleExport = () => {
|
2025-09-11 11:03:14 +08:00
|
|
|
// 获取当前的搜索参数
|
|
|
|
|
let searchParam = proTable.value?.searchParam || {}
|
2025-04-15 09:45:00 +08:00
|
|
|
|
2025-09-11 11:03:14 +08:00
|
|
|
// 将开始时间和结束时间添加到搜索参数中
|
|
|
|
|
searchParam.searchBeginTime = startDate.value
|
|
|
|
|
searchParam.searchEndTime = endDate.value
|
2024-10-23 19:30:11 +08:00
|
|
|
|
2025-09-11 11:03:14 +08:00
|
|
|
useDownload(exportCsv, '日志列表', searchParam, false, '.csv')
|
2025-04-15 09:45:00 +08:00
|
|
|
}
|
2024-10-22 13:19:13 +08:00
|
|
|
</script>
|
|
|
|
|
|
2025-09-11 11:03:14 +08:00
|
|
|
<style scoped></style>
|