-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-logs.html
More file actions
232 lines (218 loc) · 7.89 KB
/
test-logs.html
File metadata and controls
232 lines (218 loc) · 7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>日志测试</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
button {
padding: 6px 12px;
background-color: #1890ff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #40a9ff;
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
}
.modal-content {
background-color: white;
margin: 5% auto;
padding: 20px;
border-radius: 8px;
width: 80%;
max-width: 900px;
max-height: 80vh;
overflow-y: auto;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: black;
}
.detail-section {
margin: 15px 0;
}
.detail-section strong {
display: block;
margin-bottom: 5px;
}
pre {
background-color: #f5f5f5;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
}
</style>
</head>
<body>
<h1>日志列表测试</h1>
<p>测试日志详情按钮点击功能</p>
<table id="logsTable">
<thead>
<tr>
<th>ID</th>
<th>时间</th>
<th>状态</th>
<th>模型</th>
<th>请求摘要</th>
<th>响应预览</th>
<th>操作</th>
</tr>
</thead>
<tbody id="logsBody">
<tr><td colspan="7">加载中...</td></tr>
</tbody>
</table>
<div id="detailModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>请求详情</h2>
<div id="detailContent"></div>
</div>
</div>
<script>
const configId = 'aba7827a-ffd0-402d-9928-eb80fc3917c7';
const modal = document.getElementById('detailModal');
const closeBtn = document.getElementsByClassName('close')[0];
// 关闭模态框
closeBtn.onclick = function() {
modal.style.display = 'none';
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
}
// 加载日志列表
async function loadLogs() {
try {
const response = await fetch(`http://localhost:8083/api/configs/${configId}/logs?page=1&page_size=10`);
const data = await response.json();
const tbody = document.getElementById('logsBody');
tbody.innerHTML = '';
data.logs.forEach(log => {
const row = tbody.insertRow();
row.innerHTML = `
<td>${log.id}</td>
<td>${new Date(log.created_at).toLocaleString('zh-CN')}</td>
<td>${log.status === 'success' ? '✅ 成功' : '❌ 失败'}</td>
<td>${log.model}</td>
<td>${log.request_summary || '-'}</td>
<td>${log.response_preview || '-'}</td>
<td><button onclick="showDetail(${log.id})">详情</button></td>
`;
});
} catch (error) {
console.error('加载日志失败:', error);
document.getElementById('logsBody').innerHTML = '<tr><td colspan="7">加载失败</td></tr>';
}
}
// 显示详情
async function showDetail(logId) {
console.log('显示日志详情, ID:', logId);
try {
const response = await fetch(`http://localhost:8083/api/configs/${configId}/logs?page=1&page_size=100`);
const data = await response.json();
const log = data.logs.find(l => l.id === logId);
if (!log) {
alert('日志记录不存在');
return;
}
const detailContent = document.getElementById('detailContent');
detailContent.innerHTML = `
<div class="detail-section">
<strong>ID:</strong> ${log.id}
</div>
<div class="detail-section">
<strong>时间:</strong> ${new Date(log.created_at).toLocaleString('zh-CN')}
</div>
<div class="detail-section">
<strong>模型:</strong> ${log.model}
</div>
<div class="detail-section">
<strong>状态:</strong> ${log.status === 'success' ? '✅ 成功' : '❌ 失败'}
</div>
<div class="detail-section">
<strong>耗时:</strong> ${log.duration_ms}ms
</div>
<div class="detail-section">
<strong>Token使用:</strong> 输入: ${log.input_tokens}, 输出: ${log.output_tokens}, 总计: ${log.total_tokens}
</div>
${log.error_message ? `
<div class="detail-section">
<strong style="color: red;">错误信息:</strong>
<pre>${log.error_message}</pre>
</div>
` : ''}
${log.request_summary ? `
<div class="detail-section">
<strong>请求摘要:</strong>
<pre>${log.request_summary}</pre>
</div>
` : ''}
${log.response_preview ? `
<div class="detail-section">
<strong>响应预览:</strong>
<pre>${log.response_preview}</pre>
</div>
` : ''}
${log.request_body ? `
<div class="detail-section">
<strong>完整请求体:</strong>
<pre>${JSON.stringify(JSON.parse(log.request_body), null, 2)}</pre>
</div>
` : ''}
${log.response_body ? `
<div class="detail-section">
<strong>完整响应体:</strong>
<pre>${log.response_body.substring(0, 1000)}${log.response_body.length > 1000 ? '...' : ''}</pre>
</div>
` : ''}
`;
modal.style.display = 'block';
} catch (error) {
console.error('获取详情失败:', error);
alert('获取详情失败: ' + error.message);
}
}
// 页面加载时获取日志
loadLogs();
</script>
</body>
</html>