✨ 新增回收站与操作记录页面
This commit is contained in:
1 parent
d47d0edbce
commit
2bf610ac22
14 files changed
+418
-1
No files matched your search
@@ -0,0 +1,96 @@
|
||||
<template>
|
||||
<div class="p-4 sm:p-6">
|
||||
<header class="mb-5 flex flex-col gap-3 sm:mb-6 sm:flex-row sm:items-end sm:justify-between">
|
||||
<div>
|
||||
<p class="text-xs font-medium tracking-[0.16em]" :class="mutedTextClass">RECYCLE BIN</p>
|
||||
<h2 class="mt-1 text-2xl font-bold" :class="primaryTextClass">回收站</h2>
|
||||
<p class="mt-1 text-sm" :class="mutedTextClass">删除文件会先保留在这里;恢复后将生成新的 8 位取件码。</p>
|
||||
</div>
|
||||
<BaseButton variant="secondary" :loading="isLoading" @click="loadTrash">
|
||||
<template #icon><RefreshCwIcon class="mr-2 h-4 w-4" /></template>
|
||||
刷新回收站
|
||||
</BaseButton>
|
||||
</header>
|
||||
|
||||
<section class="mb-5 grid gap-3 sm:mb-6 sm:grid-cols-3">
|
||||
<div class="theme-2026-card rounded-[20px] border p-3.5 shadow-sm sm:rounded-[24px] sm:p-4" :class="panelClass">
|
||||
<p class="text-xs" :class="mutedTextClass">回收站记录</p><strong class="mt-1 block text-2xl" :class="primaryTextClass">{{ total }}</strong>
|
||||
</div>
|
||||
<div class="theme-2026-card rounded-[20px] border p-3.5 shadow-sm sm:rounded-[24px] sm:p-4" :class="panelClass">
|
||||
<p class="text-xs" :class="mutedTextClass">可恢复</p><strong class="mt-1 block text-2xl" :class="primaryTextClass">{{ recoverableCount }}</strong>
|
||||
</div>
|
||||
<div class="theme-2026-card rounded-[20px] border p-3.5 shadow-sm sm:rounded-[24px] sm:p-4" :class="panelClass">
|
||||
<p class="text-xs" :class="mutedTextClass">仅审计记录</p><strong class="mt-1 block text-2xl" :class="primaryTextClass">{{ purgedCount }}</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="theme-2026-card overflow-hidden rounded-[24px] border shadow-md sm:rounded-[30px]" :class="panelClass">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 border-b px-4 py-3 sm:px-6 sm:py-4" :class="dividerClass">
|
||||
<div><h3 class="text-base font-semibold" :class="primaryTextClass">已删除文件</h3><p class="mt-0.5 text-xs" :class="mutedTextClass">物理清理只释放文件本体,文件记录和取件历史会持续保留。</p></div>
|
||||
<span class="inline-flex items-center rounded-full px-3 py-1 text-xs font-medium" :class="isDarkMode ? 'bg-[#263941] text-[#b8d6de]' : 'bg-[#e5f0f1] text-[#365a66]'"><ShieldCheckIcon class="mr-1.5 h-3.5 w-3.5" />审计保留</span>
|
||||
</div>
|
||||
|
||||
<div v-if="isLoading" class="flex min-h-64 items-center justify-center text-sm" :class="mutedTextClass"><RefreshCwIcon class="mr-2 h-4 w-4 animate-spin" />正在加载回收站…</div>
|
||||
<div v-else-if="errorText" class="px-4 py-12 text-center sm:px-6"><p class="text-sm font-medium text-red-600">{{ errorText }}</p><BaseButton class="mt-3" variant="secondary" @click="loadTrash">重新加载</BaseButton></div>
|
||||
<div v-else-if="items.length === 0" class="px-4 py-14 text-center sm:px-6"><Trash2Icon class="mx-auto h-9 w-9" :class="mutedTextClass" /><p class="mt-3 text-sm" :class="mutedTextClass">回收站目前为空</p></div>
|
||||
|
||||
<div v-else class="divide-y" :class="dividerClass">
|
||||
<article v-for="item in items" :key="item.id" class="grid gap-3 px-4 py-4 transition-colors sm:grid-cols-[auto_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">
|
||||
<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>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<DataPagination v-if="total > 0" :current-page="page" :page-size="size" :total="total" @page-change="changePage" @page-size-change="changePageSize" />
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { EraserIcon, FileX2Icon, InfinityIcon, RefreshCwIcon, RotateCcwIcon, ShieldCheckIcon, Trash2Icon } from 'lucide-vue-next'
|
||||
import BaseButton from '@/components/common/BaseButton.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 { fetchTrash, purgeTrashItem, restoreTrashItem, updateTrashRetention } = useAdminTrash()
|
||||
const items = ref<TrashFileItem[]>([])
|
||||
const page = ref(1)
|
||||
const size = ref(20)
|
||||
const total = ref(0)
|
||||
const isLoading = ref(false)
|
||||
const errorText = ref('')
|
||||
const busyId = ref<number | null>(null)
|
||||
const busyAction = ref('')
|
||||
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 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 } }
|
||||
const run = async (item: TrashFileItem, action: string, operation: () => Promise<unknown>) => { busyId.value = item.id; busyAction.value = action; try { await operation(); await loadTrash() } catch (error: unknown) { errorText.value = (error as { response?: { data?: { detail?: string } } })?.response?.data?.detail || '操作未完成,请稍后重试。' } finally { busyId.value = null; busyAction.value = '' } }
|
||||
const restore = (item: TrashFileItem) => run(item, 'restore', () => restoreTrashItem(item.id))
|
||||
const makePermanent = (item: TrashFileItem) => run(item, 'retention', () => updateTrashRetention(item.id, 0))
|
||||
const purge = (item: TrashFileItem) => { if (!window.confirm(`确定物理清理“${fileName(item)}”吗?文件本体不可恢复,但审计记录会永久保留。`)) return; void run(item, 'purge', () => purgeTrashItem(item.id)) }
|
||||
const changePage = (nextPage: number) => { page.value = nextPage; void loadTrash() }
|
||||
const changePageSize = (nextSize: number) => { size.value = nextSize; page.value = 1; void loadTrash() }
|
||||
void loadTrash()
|
||||
</script>
|
||||
Reference in new issue
Block a user