增加运行日志查看

This commit is contained in:
凌尛 2025-06-25 17:34:17 +08:00
parent 5806be9409
commit 8130f60b49
6 changed files with 414 additions and 14 deletions

View File

@ -0,0 +1,25 @@
import instance from '../../utils/axios.js'
const runningApi = {
// 获取查询参数与分页参数
pageQuery: (params) => {
// 转换分页参数名称
const convertedParams = {
...params,
pageNum: params.page,
pageSize: params.size
}
// 删除旧的参数
delete convertedParams.page
delete convertedParams.size
return instance.get('/runningLog/pageQuery', {
params: convertedParams
})
},
viewLog: (fileName) => {
return instance.get('/runningLog/viewLog?fileName='+fileName);
}
}
export { runningApi }

View File

@ -14,13 +14,7 @@ const violationApi = {
delete convertedParams.size delete convertedParams.size
return instance.get('/violation/pageQuery', { return instance.get('/violation/pageQuery', {
params: convertedParams, params: convertedParams
// paramsSerializer: params => {
// return Object.entries(params)
// .filter(([_, v]) => v !== undefined)
// .map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
// .join('&')
// }
}) })
}, },

View File

@ -95,7 +95,19 @@
path: '/examine/violation/list' path: '/examine/violation/list'
}] }]
}] }]
} },
{
title: '日志管理',
path: '/log',
children:[{
title: '运行日志',
path: '/log/runningLog',
children:[{
title: '日志列表',
path: '/log/runningLog/list'
}]
}]
},
// ... // ...
]) ])
</script> </script>

View File

@ -42,6 +42,11 @@ const routes = [{
path: '/examine/violation/list', path: '/examine/violation/list',
component: () => import('@/views/Examine/Violation/List.vue'), component: () => import('@/views/Examine/Violation/List.vue'),
meta: { title: '违规列表' } meta: { title: '违规列表' }
},
{
path: '/log/runningLog/list',
component: () => import('@/views/log/RunningLog/List.vue'),
meta: { title: '日志列表' }
} }
] ]
}] }]

View File

@ -522,17 +522,13 @@ const editSubmit = async() =>{
:global(.warning-row) { /* :global(.warning-row) {
/* background: red !important;
color: white !important; */
background:#fdf6ec !important background:#fdf6ec !important
} }
:global(.shenhe-row) { :global(.shenhe-row) {
/* background: red !important;
color: white !important; */
background:#fde8e8 !important background:#fde8e8 !important
} } */
.unit-label { .unit-label {
margin-left: 5px; margin-left: 5px;

View File

@ -0,0 +1,368 @@
<template>
<div class="list-container">
<!-- 搜索区域 -->
<div class="search-area">
<!-- <el-form :inline="true" :model="searchForm">
<el-form-item label="违规类型">
<el-select v-model="searchForm.type" placeholder="请选择违规类型" clearable style="min-width: 150px;">
<el-option label="isbn" :value="0" />
<el-option label="书名" :value="1" />
<el-option label="作者" :value="2" />
<el-option label="出版社" :value="3" />
</el-select>
</el-form-item>
<el-form-item label="违规内容">
<el-input v-model="searchForm.name" placeholder="请输入违规内容" clearable />
</el-form-item>
<el-form-item label="审核状态">
<el-select v-model="searchForm.review" placeholder="请选择审核状态" clearable style="min-width: 150px;">
<el-option label="待提交" :value="0" />
<el-option label="待审核" :value="1" />
<el-option label="已审核" :value="2" />
<el-option label="已撤回" :value="3" />
<el-option label="审核失败" :value="4" />
</el-select>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="searchForm.status" placeholder="请选择状态" clearable style="min-width: 150px;">
<el-option label="正常" :value="0" />
<el-option label="停用" :value="1" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleSearch">搜索</el-button>
<el-button @click="resetSearch">重置</el-button>
</el-form-item>
</el-form> -->
</div>
<div class="search-area">
<!-- 操作按钮 -->
<ActionBar @refresh="refreshData">
<!-- <template #left>
<el-button type="success" :disabled="multiple" @click="btnSuccess()">通过</el-button>
<el-button type="danger" :disabled="multiple" @click="btnError()" >驳回</el-button>
<el-button type="danger" :disabled="multiple" @click="btnRemove()" >删除</el-button>
<el-button type="warning" :disabled="single" @click="btnEdit()">修改</el-button>
</template> -->
</ActionBar>
<!-- 数据表格 -->
<el-table
ref="tableRef"
:data="tableData"
border
stripe
style="width: 100%;"
v-loading="loading"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="主键" align="center" prop="id" v-if="false" />
<el-table-column label="文件名称" align="center" prop="fileName" />
<el-table-column label="文件类型" align="center" prop="fileType" />
<el-table-column label="排序" align="center" prop="fileOrder" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<el-button type="primary" @click="viewLog(scope.row.fileName)">查看日志</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<div class="pagination-container">
<el-pagination
v-model:current-page="pagination.current"
v-model:page-size="pagination.size"
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
:total="pagination.total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</div>
<el-dialog
v-model="logVisible"
width="1300px"
:close-on-click-modal="false"
>
<el-input
v-model="logContent"
style="width: 100%;"
:rows="30"
type="textarea"
placeholder="暂无日志信息"
disabled
ref="logTextareaRef"
/>
<template #footer>
<span class="dialog-footer">
<el-button @click="closeLog">关闭</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { ref, reactive, onMounted,nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { runningApi } from '@/api/modules/runningLog.js'
import RefreshButton from '@/components/RefreshButton.vue'
import ActionBar from '@/components/ActionBar.vue'
//
const tableData = ref([])
const loading = ref(false)
const tableRef = ref(null)
const remark = ref('')
const logVisible = ref(false);
//
const searchForm = reactive({
type:'',
name:'',
review:'',
status:''
})
//
const pagination = reactive({
current: 1,
size: 10,
total: 0
})
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
/** 多选框选中数据 */
const handleSelectionChange = (selection) => {
ids.value = selection.map(item => item.id);
single.value = selection.length != 1;
multiple.value = !selection.length;
}
//
onMounted(() => {
fetchData()
})
//
const fetchData = async () => {
loading.value = true
try {
//
const params = {
page: pagination.current,
size: pagination.size
}
// 使API
const res = await runningApi.pageQuery(params)
// response.data使res
if (res.code === 200) {
tableData.value = res.data.list || []
pagination.total = res.data.total || 0
} else {
ElMessage.error(res.message || '获取数据失败')
}
} catch (error) {
console.error('获取数据失败:', error)
//
if (error.code === 'ECONNABORTED') {
ElMessage.error('请求超时,请检查网络连接或联系管理员')
} else if (error.response) {
ElMessage.error(`请求失败: ${error.response.status} ${error.response.statusText}`)
} else if (error.request) {
ElMessage.error('服务器未响应,请稍后再试')
} else {
ElMessage.error(`请求错误: ${error.message}`)
}
//
tableData.value = []
pagination.total = 0
} finally {
loading.value = false
}
}
const logContent = ref();
const logTextareaRef = ref(null); // textarea
let timer = null;
//
const viewLog = async (fileName) => {
clearInterval(timer)
timer = null
logContent.value = '';
logVisible.value = true;
await fetchLogContent(fileName);
timer = setInterval( async () => {
await fetchLogContent(fileName);
}, 5000)
}
//
const fetchLogContent = async (fileName) => {
const res = await runningApi.viewLog(fileName);
logContent.value = res.data;
//
nextTick(() => {
const textarea = logTextareaRef.value?.$el?.querySelector('textarea');
if (textarea) {
textarea.scrollTop = textarea.scrollHeight; //
}
});
};
const closeLog = () =>{
clearInterval(timer)
timer = null
logVisible.value = false;
logContent.value = '';
}
//
const refreshData = () => {
fetchData()
}
//
const handleSearch = () => {
pagination.current = 1
fetchData()
}
//
const resetSearch = () => {
pagination.current = 1
fetchData()
}
//
const handleSizeChange = (size) => {
pagination.size = size
pagination.current = 1
fetchData()
}
//
const handleCurrentChange = (current) => {
pagination.current = current
fetchData()
}
</script>
<style scoped>
/* .list-container {
padding: 5px;
} */
.search-area {
margin-bottom: 20px;
padding: 15px;
background-color: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
text-align: left;
}
.search-area .el-form-item {
margin-right: 18px;
margin-bottom: 10px;
}
.action-bar {
margin-bottom: 10px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
text-align: left;
}
.action-left {
display: flex;
gap: 10px;
}
.action-right {
display: flex;
gap: 10px;
}
.pagination-container {
margin-top: 20px;
display: flex;
justify-content: flex-start;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
}
.card-secret-content {
text-align: left;
p {
margin-bottom: 15px;
font-size: 16px;
}
}
.card-params-content {
text-align: left;
p {
margin-bottom: 15px;
font-size: 16px;
}
}
:global(.el-textarea.is-disabled .el-textarea__inner){
background-color: #000 !important;
color: #fff !important; /* 文字颜色设为白色 */
font-family: monospace; /* 等宽字体,适合日志显示 */
}
.unit-label {
margin-left: 5px;
}
</style>