TRM-coding | 85e5c32 | 2025-06-18 19:49:21 +0800 | [diff] [blame] | 1 | import React, { useState, useEffect } from 'react'; |
| 2 | import { fetchRecordLog } from '../api/posts_trm'; |
| 3 | |
| 4 | function TransactionLogs({ userId }) { |
| 5 | const [records, setRecords] = useState([]); |
| 6 | |
| 7 | useEffect(() => { |
| 8 | fetchRecordLog(userId) |
| 9 | .then(data => setRecords(data)) |
| 10 | .catch(err => console.error('fetchRecordLog error:', err)); |
| 11 | }, [userId]); |
| 12 | |
| 13 | return ( |
| 14 | <section className="dashboard-logs"> |
| 15 | <table className="admin-table"> |
| 16 | <thead> |
| 17 | <tr> |
| 18 | <th>ID</th> |
| 19 | <th>用户ID</th> |
| 20 | <th>类型</th> |
| 21 | <th>内容</th> |
| 22 | <th>IP</th> |
| 23 | <th>创建时间</th> |
| 24 | </tr> |
| 25 | </thead> |
| 26 | <tbody> |
| 27 | {records.length > 0 |
| 28 | ? records.map((r, i) => ( |
| 29 | <tr key={i}> |
| 30 | <td>{r.id}</td> |
| 31 | <td>{r.user_id}</td> |
| 32 | <td>{r.type}</td> |
| 33 | <td>{r.content}</td> |
| 34 | <td>{r.ip}</td> |
| 35 | <td>{new Date(r.created_at).toLocaleString()}</td> |
| 36 | </tr> |
| 37 | )) |
| 38 | : ( |
| 39 | <tr> |
| 40 | <td colSpan="6" style={{ textAlign: 'center' }}>暂无数据</td> |
| 41 | </tr> |
| 42 | ) |
| 43 | } |
| 44 | </tbody> |
| 45 | </table> |
| 46 | </section> |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | export default TransactionLogs; |