✨ feat(core): 实现回收站条目展示逻辑及UI组件
* 新增 TrashItemInfo 组件以优化回收站列表项展示 * 封装 trashPresentation 工具类处理时间显示逻辑 * 调整 TrashView 布局,重构列表项渲染逻辑 * 新增回收站功能相关的集成测试与单元测试 * 更新测试文档以说明回收站日期格式化测试规则 * 更新 package.json 依赖配置
This commit is contained in:
1 parent
af009cf3c5
commit
614b9a2104
7 files changed
+243
-14
No files matched your search
@@ -0,0 +1,69 @@
|
||||
<template>
|
||||
<div class="trash-item-info min-w-0" :class="{ 'trash-item-info--dark': isDarkMode }">
|
||||
<div class="flex min-w-0 items-start gap-3">
|
||||
<div class="trash-file-icon flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl" :class="`trash-tone-${info.tone}`">
|
||||
<component :is="item.isTrashPurged ? FileX2Icon : item.text != null ? FileTextIcon : FileIcon" class="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex flex-wrap items-center gap-x-2.5 gap-y-1.5">
|
||||
<p class="trash-file-name min-w-0 text-sm font-semibold leading-6 sm:text-base">{{ name }}</p>
|
||||
<span class="trash-state shrink-0 rounded-full border px-2.5 py-0.5 text-xs font-medium" :class="`trash-tone-${info.tone}`">{{ info.state }}</span>
|
||||
</div>
|
||||
<dl class="trash-file-meta mt-2 flex flex-wrap gap-x-5 gap-y-2 text-xs leading-5">
|
||||
<div class="flex flex-wrap gap-x-1.5"><dt>原取件码</dt><dd class="font-mono font-medium tracking-wide">{{ item.code || '未记录' }}</dd></div>
|
||||
<div class="flex gap-x-1.5"><dt>文件大小</dt><dd>{{ sizeText }}</dd></div>
|
||||
<div class="flex flex-wrap gap-x-1.5"><dt>移入原因</dt><dd>{{ info.reason }}</dd></div>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="trash-time-panel mt-3 rounded-2xl border px-3 py-2.5 sm:ml-14">
|
||||
<dl class="grid min-w-0 gap-3 text-xs sm:grid-cols-2">
|
||||
<div class="min-w-0">
|
||||
<dt class="trash-time-label flex items-center gap-1.5"><Clock3Icon class="h-3.5 w-3.5" aria-hidden="true" />移入时间</dt>
|
||||
<dd class="mt-1.5 font-medium tabular-nums"><time :datetime="item.trashedAt || undefined" :title="formatTrashTime(item.trashedAt)">{{ formatTrashTime(item.trashedAt, now) }}</time></dd>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<dt class="trash-time-label flex items-center gap-1.5"><CalendarClockIcon class="h-3.5 w-3.5" aria-hidden="true" />{{ info.timeLabel }}</dt>
|
||||
<dd class="mt-1.5 flex flex-wrap items-center gap-x-2 gap-y-1 font-medium tabular-nums">
|
||||
<span :title="item.isTrashPermanent && !item.isTrashPurged ? undefined : formatTrashTime(item.isTrashPurged ? item.trashPurgedAt : item.trashExpiresAt)">{{ info.timeText }}</span>
|
||||
<span v-if="info.reminder" class="trash-remaining rounded-full px-2 py-0.5 text-[11px]" :class="`trash-tone-${info.tone}`">{{ info.reminder }}</span>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p v-if="info.note" class="trash-time-label mt-2 text-xs leading-5">{{ info.note }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { CalendarClockIcon, Clock3Icon, FileIcon, FileTextIcon, FileX2Icon } from 'lucide-vue-next'
|
||||
import type { TrashFileItem } from '@/types'
|
||||
import { formatFileSize } from '@/utils/common'
|
||||
import { formatTrashTime, getTrashPresentation } from '@/utils/trashPresentation'
|
||||
|
||||
const props = defineProps<{ item: TrashFileItem; isDarkMode: boolean; now: number }>()
|
||||
const info = computed(() => getTrashPresentation(props.item, props.now))
|
||||
const name = computed(() => props.item.name || `${props.item.prefix || ''}${props.item.suffix || ''}` || '未命名文件')
|
||||
const sizeText = computed(() => {
|
||||
const size = Number(props.item.size)
|
||||
return Number.isFinite(size) && size >= 0 ? formatFileSize(size, 1) : '未记录'
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.trash-item-info { color: #294851; --trash-muted: #617980; --trash-line: #d7e3e5; --trash-surface: #edf3f6; }
|
||||
.trash-item-info--dark { color: #dbe9ee; --trash-muted: #a9bdc2; --trash-line: #40545c; --trash-surface: #26383f; }
|
||||
.trash-file-name { overflow-wrap: anywhere; }
|
||||
.trash-file-meta dt, .trash-time-label { color: var(--trash-muted); }
|
||||
.trash-time-panel { background: var(--trash-surface); border-color: var(--trash-line); }
|
||||
.trash-state { border-color: var(--trash-line); }
|
||||
.trash-tone-normal { background: #e4f0ed; color: #355e56; }
|
||||
.trash-tone-warning { background: #fff0d8; color: #885512; }
|
||||
.trash-tone-permanent { background: #eeebf8; color: #62528e; }
|
||||
.trash-tone-muted { background: #e8edef; color: #596b73; }
|
||||
.trash-item-info--dark .trash-tone-normal { background: #29473f; color: #c0e5d8; }
|
||||
.trash-item-info--dark .trash-tone-warning { background: #514026; color: #f5d599; }
|
||||
.trash-item-info--dark .trash-tone-permanent { background: #3e3556; color: #ddd2f6; }
|
||||
.trash-item-info--dark .trash-tone-muted { background: #344249; color: #bbc9cf; }
|
||||
</style>
|
||||
@@ -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 ? '已到清理时间,等待后台处理。' : ''
|
||||
}
|
||||
}
|
||||
@@ -44,16 +44,11 @@
|
||||
<article
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="fcb-interactive-row group grid gap-3 px-4 py-4 sm:grid-cols-[auto_minmax(0,1fr)_auto] sm:items-center sm:px-6"
|
||||
class="fcb-interactive-row group grid gap-3 px-4 py-4 xl:grid-cols-[minmax(0,1fr)_auto] sm:items-center sm:px-6"
|
||||
:class="isDarkMode ? 'hover:bg-[#253941]/60' : 'hover:bg-[#f2f8f8]'"
|
||||
>
|
||||
<div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl" :class="item.isTrashPurged ? (isDarkMode ? 'bg-[#30383c] text-[#aab7ba]' : 'bg-[#edf0f1] text-[#61747a]') : (isDarkMode ? 'bg-amber-950/45 text-amber-300' : 'bg-amber-50 text-amber-700')"><FileX2Icon class="h-5 w-5" /></div>
|
||||
<div class="min-w-0">
|
||||
<div class="flex flex-wrap items-center gap-2"><p class="break-all text-sm font-semibold" :class="primaryTextClass">{{ fileName(item) }}</p><span class="rounded-full border px-2 py-0.5 text-[11px] font-medium" :class="badgeClass">{{ stateLabel(item) }}</span></div>
|
||||
<div class="mt-1 flex flex-wrap gap-x-3 gap-y-1 text-xs" :class="mutedTextClass"><span>旧取件码 {{ item.code }}</span><span>{{ formatFileSize(Number(item.size || 0), 1) }}</span><span>移入 {{ formatTimestamp(item.trashedAt || '') }}</span></div>
|
||||
<p class="mt-1 text-xs" :class="mutedTextClass">{{ expiryLabel(item) }}</p>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2 sm:justify-end">
|
||||
<TrashItemInfo :item="item" :is-dark-mode="isDarkMode" :now="now" />
|
||||
<div class="flex flex-wrap items-center gap-2 sm:pl-14 xl:justify-end xl:pl-0">
|
||||
<BaseButton v-if="!item.isTrashPurged" size="sm" variant="success" :loading="busyId === item.id && busyAction === 'restore'" @click="restore(item)"><template #icon><RotateCcwIcon class="mr-2 h-4 w-4" /></template>恢复</BaseButton>
|
||||
<BaseButton v-if="!item.isTrashPurged" size="sm" variant="outline" :loading="busyId === item.id && busyAction === 'retention'" @click="makePermanent(item)"><template #icon><InfinityIcon class="mr-2 h-4 w-4" /></template>永久保留</BaseButton>
|
||||
<BaseButton v-if="!item.isTrashPurged" size="sm" variant="danger" :loading="busyId === item.id && busyAction === 'purge'" @click="purge(item)"><template #icon><EraserIcon class="mr-2 h-4 w-4" /></template>物理清理</BaseButton>
|
||||
@@ -67,14 +62,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { EraserIcon, FileX2Icon, InfinityIcon, RefreshCwIcon, RotateCcwIcon, Settings2Icon, ShieldCheckIcon, Trash2Icon } from 'lucide-vue-next'
|
||||
import { EraserIcon, InfinityIcon, RefreshCwIcon, RotateCcwIcon, Settings2Icon, ShieldCheckIcon, Trash2Icon } from 'lucide-vue-next'
|
||||
import BaseButton from '@/components/common/BaseButton.vue'
|
||||
import TrashItemInfo from '@/components/manage/TrashItemInfo.vue'
|
||||
import DataPagination from '@/components/common/DataPagination.vue'
|
||||
import { useAdminTrash, useInjectedDarkMode } from '@/composables'
|
||||
import type { TrashFileItem } from '@/types'
|
||||
import { formatFileSize, formatTimestamp } from '@/utils/common'
|
||||
|
||||
const isDarkMode = useInjectedDarkMode()
|
||||
const router = useRouter()
|
||||
@@ -87,16 +82,17 @@ const isLoading = ref(false)
|
||||
const errorText = ref('')
|
||||
const busyId = ref<number | null>(null)
|
||||
const busyAction = ref('')
|
||||
const now = ref(Date.now())
|
||||
let clockTimer: ReturnType<typeof setInterval> | undefined
|
||||
onMounted(() => { clockTimer = setInterval(() => { now.value = Date.now() }, 60_000) })
|
||||
onUnmounted(() => { clearInterval(clockTimer) })
|
||||
const primaryTextClass = computed(() => isDarkMode.value ? 'text-white' : 'text-[#1f3c45]')
|
||||
const mutedTextClass = computed(() => isDarkMode.value ? 'text-[#a9bdc2]' : 'text-[#617980]')
|
||||
const panelClass = computed(() => isDarkMode.value ? 'border-[#40545c] bg-[#202f36]/90' : 'border-[#d7e3e5] bg-[#f8fbfb]')
|
||||
const dividerClass = computed(() => isDarkMode.value ? 'divide-[#40545c] border-[#40545c]' : 'divide-[#d7e3e5] border-[#d7e3e5]')
|
||||
const badgeClass = computed(() => isDarkMode.value ? 'border-[#50666f] text-[#b8d6de]' : 'border-[#c8d8dc] text-[#4e6c75]')
|
||||
const recoverableCount = computed(() => items.value.filter(item => !item.isTrashPurged).length)
|
||||
const purgedCount = computed(() => items.value.filter(item => item.isTrashPurged).length)
|
||||
const fileName = (item: TrashFileItem) => item.name || `${item.prefix || ''}${item.suffix || ''}` || '未命名文件'
|
||||
const stateLabel = (item: TrashFileItem) => item.isTrashPurged ? '仅审计记录' : item.isTrashPermanent ? '永久保留' : '可恢复'
|
||||
const expiryLabel = (item: TrashFileItem) => item.isTrashPurged ? `文件本体已于 ${formatTimestamp(item.trashPurgedAt || '')} 清理` : item.isTrashPermanent ? '不会自动清理文件本体' : `预计清理:${formatTimestamp(item.trashExpiresAt || '')}`
|
||||
const openRetentionSettings = () => { void router.push({ path: '/admin/settings', hash: '#settings-upload' }) }
|
||||
|
||||
const loadTrash = async () => { isLoading.value = true; errorText.value = ''; try { const detail = await fetchTrash({ page: page.value, size: size.value }); items.value = detail?.data || []; total.value = Number(detail?.total || 0) } catch (error: unknown) { errorText.value = (error as { response?: { data?: { detail?: string } } })?.response?.data?.detail || '回收站加载失败,请稍后重试。' } finally { isLoading.value = false } }
|
||||
|
||||
Reference in new issue
Block a user