✨ feat(core): 实现回收站条目展示逻辑及UI组件

* 新增 TrashItemInfo 组件以优化回收站列表项展示
* 封装 trashPresentation 工具类处理时间显示逻辑
* 调整 TrashView 布局,重构列表项渲染逻辑
* 新增回收站功能相关的集成测试与单元测试
* 更新测试文档以说明回收站日期格式化测试规则
* 更新 package.json 依赖配置
This commit is contained in:
orion committed 2026-09-16 18:01:23 +08:00
1 parent af009cf3c5
commit 614b9a2104
7 files changed
+243 -14

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import type { TrashFileItem } from '../types/trash'
const parseTime = (value?: string | null) => value ? new Date(value).getTime() : NaN
export function formatTrashTime(value?: string | null, now?: number): string {
const timestamp = parseTime(value)
if (!Number.isFinite(timestamp)) return '未记录'
const delta = now === undefined ? Infinity : timestamp - now
const distance = Math.abs(delta)
if (distance <= 7 * 86400000) {
if (distance < 60000) return delta <= 0 ? '刚刚' : '即将到达'
const unit = distance >= 86400000 ? '天' : distance >= 3600000 ? '小时' : '分钟'
const divisor = distance >= 86400000 ? 86400000 : distance >= 3600000 ? 3600000 : 60000
return `${Math.floor(distance / divisor)} ${unit}${delta < 0 ? '前' : '后'}`
}
const date = new Date(timestamp)
const pad = (n: number) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}
export function getTrashPresentation(item: TrashFileItem, now: number) {
const reason = item.trashReason === 'manual' ? '手动删除'
: item.trashReason === 'expired' ? '已过期或次数用尽'
: item.trashReason ? '其他原因' : '未记录'
if (item.isTrashPurged) return {
state: '已清理', tone: 'muted', reason, reminder: '',
timeLabel: '清理时间', timeText: formatTrashTime(item.trashPurgedAt, now),
note: '文件不可恢复,审计记录和取件历史仍保留。'
}
if (item.isTrashPermanent) return {
state: '永久保留', tone: 'permanent', reason, reminder: '',
timeLabel: '清理计划', timeText: '不自动清理', note: ''
}
const deadline = parseTime(item.trashExpiresAt)
const valid = Number.isFinite(deadline)
const remainingMs = deadline - now
const reminder = !valid || remainingMs > 3 * 86400000 ? '' : remainingMs <= 0 ? '等待清理' : '即将清理'
return {
state: '可恢复', tone: valid && remainingMs <= 3 * 86400000 ? 'warning' : 'normal',
reason, reminder, timeLabel: '自动清理时间',
timeText: valid ? formatTrashTime(item.trashExpiresAt, now) : '待确认',
note: valid && remainingMs <= 0 ? '已到清理时间,等待后台处理。' : ''
}
}