// Filename: frontend/js/pages/logs/logList.js class LogList { constructor(container) { this.container = container; if (!this.container) { console.error("LogList: container element (tbody) not found."); } } renderLoading() { if (!this.container) return; this.container.innerHTML = ` 加载日志中...`; } render(logs) { if (!this.container) return; if (!logs || logs.length === 0) { this.container.innerHTML = `没有找到相关的日志记录。`; return; } const logsHtml = logs.map(log => this.createLogRowHtml(log)).join(''); this.container.innerHTML = logsHtml; } createLogRowHtml(log) { // [后端协作点] 假设后端未来会提供 GroupDisplayName 和 APIKeyName const groupName = log.GroupDisplayName || (log.GroupID ? `Group #${log.GroupID}` : 'N/A'); const apiKeyName = log.APIKeyName || (log.KeyID ? `Key #${log.KeyID}` : 'N/A'); const errorTag = log.IsSuccess ? `成功` : `${log.ErrorCode || '失败'}`; // 使用 toLocaleString 格式化时间,更符合用户本地习惯 const requestTime = new Date(log.RequestTime).toLocaleString(); return ` #${log.ID} ${apiKeyName} ${groupName} ${log.ErrorMessage || (log.IsSuccess ? '' : '未知错误')} ${errorTag} ${log.ModelName} ${requestTime} `; } } export default LogList;