blob: c2e6239fe2c331884d03ae08de79a53f0cf6bb7c [file] [log] [blame]
TRM-coding267df742025-06-15 16:05:28 +08001import React, { useEffect, useState } from 'react';
2import './Admin.css';
3
4function LogsDashboard() {
5 const [logs, setLogs] = useState([]);
6 const [stats, setStats] = useState({});
7
8 useEffect(() => {
9 fetch('/api/logs')
10 .then(res => res.json())
11 .then(setLogs)
12 .catch(console.error);
13 fetch('/api/stats')
14 .then(res => res.json())
15 .then(setStats)
16 .catch(console.error);
17 }, []);
18
19 return (
20 <div className="admin-container">
21 <h2>运行日志 & 性能 Dashboard</h2>
22 <section className="dashboard-stats">
23 <pre>{JSON.stringify(stats, null, 2)}</pre>
24 </section>
25 <section className="dashboard-logs">
26 <table className="admin-table">
27 <thead>
28 <tr><th>时间</th><th>级别</th><th>消息</th></tr>
29 </thead>
30 <tbody>
31 {logs.map((log, i) => (
32 <tr key={i}>
33 <td>{new Date(log.time).toLocaleString()}</td>
34 <td>{log.level}</td>
35 <td>{log.message}</td>
36 </tr>
37 ))}
38 </tbody>
39 </table>
40 </section>
41 </div>
42 );
43}
44
45export default LogsDashboard;