Files
dns-server/.trae/documents/修复日志显示undefined问题.md
2026-01-14 23:08:46 +08:00

68 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 问题分析
从截图中可以看到,日志表格显示了"Invalid Date"、"undefined"等错误值这表明前端代码在解析API返回的JSON数据时出现了问题。
## 根本原因
1. 后端`QueryLog`结构体的JSON标签使用了小写字段名`json:"timestamp"``json:"clientIP"`等)
2. 前端代码使用了大写的字段名(如`log.Timestamp``log.ClientIP`等)来访问数据
3. 字段名大小写不匹配导致前端无法正确解析API返回的数据
## 修复方案
修改前端代码使用正确的小写字段名来访问API返回的数据与后端返回的JSON格式匹配。
## 具体修改点
1. **`updateLogsTable`函数**约435-621行
*`log.Timestamp`改为`log.timestamp`
*`log.ClientIP`改为`log.clientIP`
*`log.Domain`改为`log.domain`
*`log.QueryType`改为`log.queryType`
*`log.ResponseTime`改为`log.responseTime`
*`log.Result`改为`log.result`
*`log.BlockRule`改为`log.blockRule`
*`log.FromCache`改为`log.fromCache`
*`log.DNSSEC`改为`log.dnssec`
*`log.EDNS`改为`log.edns`
*`log.DNSServer`改为`log.dnsServer`
*`log.DNSSECServer`改为`log.dnssecServer`
*`log.ResponseCode`改为`log.responseCode`
2. **`showLogDetailModal`函数**约1450-1597行
* 同样修改所有字段名的大小写
3. **其他可能的访问点**
* 检查并修改任何其他访问日志数据的地方
## 修复原则
* 保持前端代码与后端API返回的JSON格式一致
* 遵循REST API的最佳实践使用小写字段名
* 确保所有日志数据访问点都得到修复
## 验证方法
1. 修复代码后,重新编译并运行服务器
2. 访问日志页面,检查日志数据是否正确显示
3. 测试不同类型的日志(允许、屏蔽、错误),确保都能正确显示
4. 测试日志详情模态框,确保所有字段都能正确显示