新增系统日志页面,待完善
This commit is contained in:
parent
73022787ed
commit
b377e208b4
Binary file not shown.
@ -35,11 +35,21 @@ class SystemLog extends HTMLElement {
|
||||
background: #f5f7fa;
|
||||
border-radius: 8px;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.toolbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
flex: 1;
|
||||
width: 320px;
|
||||
min-width: 180px;
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.search-box input {
|
||||
@ -69,6 +79,7 @@ class SystemLog extends HTMLElement {
|
||||
.filter-group {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.filter-select {
|
||||
@ -89,6 +100,7 @@ class SystemLog extends HTMLElement {
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
@ -133,7 +145,7 @@ class SystemLog extends HTMLElement {
|
||||
|
||||
.log-header {
|
||||
display: grid;
|
||||
grid-template-columns: 180px 120px 120px 1fr;
|
||||
grid-template-columns: 180px 120px 120px 120px 1fr;
|
||||
padding: 12px 16px;
|
||||
background: #f5f7fa;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
@ -148,7 +160,7 @@ class SystemLog extends HTMLElement {
|
||||
|
||||
.log-item {
|
||||
display: grid;
|
||||
grid-template-columns: 180px 120px 120px 1fr;
|
||||
grid-template-columns: 180px 120px 120px 120px 1fr;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
font-size: 14px;
|
||||
@ -219,6 +231,11 @@ class SystemLog extends HTMLElement {
|
||||
color: #c0c4cc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.icon-small {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
</style>
|
||||
<div class="log-container">
|
||||
<div class="toolbar">
|
||||
@ -226,6 +243,7 @@ class SystemLog extends HTMLElement {
|
||||
<img src="assets/icons/png/search_b.png" alt="搜索" class="search-icon">
|
||||
<input type="text" placeholder="搜索日志内容...">
|
||||
</div>
|
||||
<div class="toolbar-right">
|
||||
<div class="filter-group">
|
||||
<select class="filter-select" id="levelFilter">
|
||||
<option value="">所有级别</option>
|
||||
@ -244,13 +262,10 @@ class SystemLog extends HTMLElement {
|
||||
</div>
|
||||
<div class="action-buttons">
|
||||
<button class="btn btn-default" id="refreshBtn">
|
||||
<img src="assets/icons/png/refresh.png" alt="刷新" class="icon-small">
|
||||
<img src="assets/icons/png/refresh_b.png" alt="刷新" class="icon-small">
|
||||
刷新
|
||||
</button>
|
||||
<button class="btn btn-primary" id="exportBtn">
|
||||
<img src="assets/icons/png/download.png" alt="导出" class="icon-small">
|
||||
导出
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="log-content">
|
||||
@ -258,6 +273,7 @@ class SystemLog extends HTMLElement {
|
||||
<div>时间</div>
|
||||
<div>级别</div>
|
||||
<div>来源</div>
|
||||
<div>用户</div>
|
||||
<div>内容</div>
|
||||
</div>
|
||||
<div class="log-list" id="logList">
|
||||
@ -300,12 +316,6 @@ class SystemLog extends HTMLElement {
|
||||
this.loadLogs();
|
||||
});
|
||||
|
||||
// 导出按钮事件
|
||||
const exportBtn = this.shadowRoot.querySelector('#exportBtn');
|
||||
exportBtn.addEventListener('click', () => {
|
||||
this.exportLogs();
|
||||
});
|
||||
|
||||
// 分页按钮事件
|
||||
const prevPage = this.shadowRoot.querySelector('#prevPage');
|
||||
const nextPage = this.shadowRoot.querySelector('#nextPage');
|
||||
@ -319,29 +329,11 @@ class SystemLog extends HTMLElement {
|
||||
|
||||
async loadLogs() {
|
||||
try {
|
||||
// 这里应该调用后端API获取日志数据
|
||||
// 示例数据
|
||||
const logs = [
|
||||
{
|
||||
timestamp: '2024-03-20 10:00:00',
|
||||
level: 'info',
|
||||
source: '系统',
|
||||
content: '系统启动成功'
|
||||
},
|
||||
{
|
||||
timestamp: '2024-03-20 10:01:00',
|
||||
level: 'warning',
|
||||
source: '数据库',
|
||||
content: '数据库连接池接近最大连接数'
|
||||
},
|
||||
{
|
||||
timestamp: '2024-03-20 10:02:00',
|
||||
level: 'error',
|
||||
source: 'API',
|
||||
content: 'API请求超时'
|
||||
const response = await fetch('/api/system-log/logs');
|
||||
if (!response.ok) {
|
||||
throw new Error('网络响应失败');
|
||||
}
|
||||
];
|
||||
|
||||
const logs = await response.json();
|
||||
this.renderLogs(logs);
|
||||
} catch (error) {
|
||||
console.error('加载日志失败:', error);
|
||||
@ -352,10 +344,11 @@ class SystemLog extends HTMLElement {
|
||||
const logList = this.shadowRoot.querySelector('#logList');
|
||||
logList.innerHTML = logs.map(log => `
|
||||
<div class="log-item">
|
||||
<div>${log.timestamp}</div>
|
||||
<div>${log.time || ''}</div>
|
||||
<div><span class="log-level level-${log.level}">${this.getLevelText(log.level)}</span></div>
|
||||
<div>${log.source}</div>
|
||||
<div>${log.content}</div>
|
||||
<div>${log.source || ''}</div>
|
||||
<div>${log.user || ''}</div>
|
||||
<div>${log.log || ''}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
@ -379,11 +372,6 @@ class SystemLog extends HTMLElement {
|
||||
this.loadLogs();
|
||||
}
|
||||
|
||||
exportLogs() {
|
||||
// 实现日志导出功能
|
||||
console.log('导出日志');
|
||||
}
|
||||
|
||||
changePage(delta) {
|
||||
// 实现分页功能
|
||||
console.log('切换页面:', delta);
|
||||
|
@ -634,7 +634,8 @@
|
||||
'个人中心': 'user',
|
||||
'用户管理': 'users',
|
||||
'模型开发': 'cube',
|
||||
'服务开发': 'settings'
|
||||
'服务开发': 'settings',
|
||||
'系统日志': 'file-text'
|
||||
};
|
||||
|
||||
return iconMap[title] || parentTool || 'con';
|
||||
|
26
XNSimHtml/routes/system-log.js
Normal file
26
XNSimHtml/routes/system-log.js
Normal file
@ -0,0 +1,26 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { getSystemLogs, addSystemLog } = require('../utils/db-utils');
|
||||
|
||||
// 获取所有系统日志
|
||||
router.get('/logs', async (req, res) => {
|
||||
try {
|
||||
const logs = await getSystemLogs();
|
||||
res.json(logs);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: '无法获取系统日志' });
|
||||
}
|
||||
});
|
||||
|
||||
// 添加系统日志
|
||||
router.post('/logs', async (req, res) => {
|
||||
const { level, user, log, source } = req.body;
|
||||
try {
|
||||
const result = await addSystemLog({ level, user, log, source });
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: '无法添加系统日志' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
@ -26,6 +26,7 @@ const icdImportRoutes = require('./routes/icd-import');
|
||||
const qaRoutes = require('./routes/qa');
|
||||
const todoRoutes = require('./routes/todos');
|
||||
const userRoutes = require('./routes/users');
|
||||
const systemLogRoutes = require('./routes/system-log');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
@ -93,6 +94,7 @@ app.use('/api/icd', icdImportRoutes);
|
||||
app.use('/api/qa', qaRoutes);
|
||||
app.use('/api/todos', todoRoutes);
|
||||
app.use('/api', userRoutes);
|
||||
app.use('/api/system-log', systemLogRoutes);
|
||||
|
||||
// 接口配置页面路由
|
||||
app.get('/interface-config', (req, res) => {
|
||||
|
@ -1443,6 +1443,97 @@ function getUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有系统日志
|
||||
function getSystemLogs() {
|
||||
try {
|
||||
const xnCorePath = getXNCorePath();
|
||||
if (!xnCorePath) {
|
||||
throw new Error('XNCore环境变量未设置,无法获取数据库路径');
|
||||
}
|
||||
|
||||
const dbPath = xnCorePath + '/database/XNSim.db';
|
||||
if (!dbPath) {
|
||||
throw new Error('无法找到数据库文件');
|
||||
}
|
||||
|
||||
// 打开数据库连接
|
||||
const db = new Database(dbPath, { readonly: true });
|
||||
|
||||
const logs = db.prepare(`
|
||||
SELECT id, time, level, user, source, log
|
||||
FROM SystemLog
|
||||
ORDER BY time DESC
|
||||
`).all();
|
||||
|
||||
db.close();
|
||||
|
||||
return logs;
|
||||
} catch (error) {
|
||||
console.error('获取系统日志失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加系统日志
|
||||
function addSystemLog(logData) {
|
||||
try {
|
||||
// 验证必填字段
|
||||
if (!logData.level || !logData.source) {
|
||||
throw new Error('日志级别和来源是必填字段');
|
||||
}
|
||||
|
||||
const xnCorePath = getXNCorePath();
|
||||
if (!xnCorePath) {
|
||||
throw new Error('XNCore环境变量未设置,无法获取数据库路径');
|
||||
}
|
||||
|
||||
const dbPath = xnCorePath + '/database/XNSim.db';
|
||||
if (!dbPath) {
|
||||
throw new Error('无法找到数据库文件');
|
||||
}
|
||||
|
||||
// 打开数据库连接
|
||||
const db = new Database(dbPath);
|
||||
|
||||
// 获取当前本地时间
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
const localDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
|
||||
// 在插入日志时添加时间
|
||||
const result = db.prepare(`
|
||||
INSERT INTO SystemLog (level, user, source, log, time)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
`).run(
|
||||
logData.level,
|
||||
logData.user || null,
|
||||
logData.source,
|
||||
logData.log || null,
|
||||
localDateTime
|
||||
);
|
||||
|
||||
db.close();
|
||||
|
||||
if (result.changes > 0) {
|
||||
return {
|
||||
success: true,
|
||||
id: result.lastInsertRowid,
|
||||
message: '系统日志添加成功'
|
||||
};
|
||||
} else {
|
||||
throw new Error('系统日志添加失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('添加系统日志失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getATAChapters,
|
||||
getModelsByChapterId,
|
||||
@ -1467,5 +1558,7 @@ module.exports = {
|
||||
addTodo,
|
||||
updateTodoStatus,
|
||||
deleteTodo,
|
||||
getUsers
|
||||
getUsers,
|
||||
getSystemLogs,
|
||||
addSystemLog
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user