## 新增功能 - 文件管理模块:分类树 + 文件上传/下载/删除 - 文件上传支持拖拽(Dragger)+ 手动上传(customRequest 模式) ## 页面布局统一(参照评测执行页) - 仪表盘/评测对象/评测场景/评测报告 全部改为全高 flex 布局 - 统一内联页头样式(h2 + 竖线分隔 + 描述) - 表格撑满高度、overflow 处理 - 每页添加刷新按钮 ## Bug 修复 - 分类树操作按钮 hover 不可见(CSS 规则缺失) - 文件上传失败(multipart boundary 缺失) - LLM API 响应 content blocks 数组格式支持(_extract_content_from_api_response) - response_time_max_ms 被静默忽略(隐式规则传空 params) - 空 messages 导致 IndexError 崩溃 - poll_reply 异常中止整个 run(缺 try/catch) - engine finally 未关闭 session - 3 个页面 UTC 时间戳解析偏差 8 小时 ## 后端 - EvalEngine: poll_reply 异常保护、空 dialog 保护、session 关闭 - LLM API 响应解析支持 content-block-array 格式 - 隐式 response_time 规则正确传递 max_ms 参数 ## 前端 - api.ts: 移除手动 Content-Type(让浏览器自动添加 boundary) - Files.tsx: customRequest 替代 beforeUpload、布局优化 - index.css: 分类树 hover 规则 - Targets/Scenarios/Home/Reports: 全高布局改造 - 3 个页面时间戳改用 formatDateTime()(修复 UTC 偏差) Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
// Shared date/time formatting helpers.
|
||
|
||
/**
|
||
* 后端存储的是 UTC naive datetime(SQLite 不保留时区),
|
||
* 序列化后无 Z/+00:00 后缀。JavaScript 对无时区字符串按本地时间处理,
|
||
* 所以必须显式加 Z,让 Date 正确当作 UTC 解析,浏览器再转换为本地时区显示。
|
||
*/
|
||
export function toDate(iso: string): Date {
|
||
if (iso.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(iso)) return new Date(iso)
|
||
return new Date(iso + 'Z')
|
||
}
|
||
|
||
/** 省略当年年份的紧凑格式,用于空间受限的列表行 */
|
||
export function shortDateTime(iso?: string | null): string {
|
||
if (!iso) return '-'
|
||
const d = toDate(iso)
|
||
const pad = (n: number) => String(n).padStart(2, '0')
|
||
const now = new Date()
|
||
if (d.getFullYear() === now.getFullYear()) {
|
||
return `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||
}
|
||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||
}
|
||
|
||
export function formatDateTime(iso?: string | null): string {
|
||
if (!iso) return '-'
|
||
const d = toDate(iso)
|
||
const pad = (n: number) => String(n).padStart(2, '0')
|
||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||
}
|
||
|
||
export function elapsedStr(startedAt?: string | null, completedAt?: string | null): string {
|
||
if (!startedAt) return '-'
|
||
const start = toDate(startedAt).getTime()
|
||
const end = completedAt ? toDate(completedAt).getTime() : Date.now()
|
||
const secs = Math.max(0, Math.round((end - start) / 1000))
|
||
if (secs < 60) return `${secs}s`
|
||
const m = Math.floor(secs / 60)
|
||
const s = secs % 60
|
||
if (m < 60) return `${m}m ${s}s`
|
||
const h = Math.floor(m / 60)
|
||
return `${h}h ${m % 60}m`
|
||
}
|