✨ 优化回收站反馈与统计标签
This commit is contained in:
1 parent
c2f0bf1675
commit
363c350458
1 file changed
+28
-11
@@ -11,22 +11,22 @@
|
||||
<template #icon><Settings2Icon class="mr-2 h-4 w-4" /></template>
|
||||
配置默认清理时间
|
||||
</BaseButton>
|
||||
<BaseButton variant="secondary" :loading="isLoading" @click="loadTrash">
|
||||
<BaseButton variant="secondary" :loading="isLoading" :disabled="busyId !== null" @click="loadTrash">
|
||||
<template #icon><RefreshCwIcon class="mr-2 h-4 w-4" /></template>
|
||||
刷新回收站
|
||||
</BaseButton>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="mb-5 grid gap-3 sm:mb-6 sm:grid-cols-3">
|
||||
<section class="mb-5 grid grid-cols-3 gap-2 sm:mb-6 sm:gap-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>
|
||||
<p class="text-[11px] leading-4 sm:text-xs" :class="mutedTextClass">全部记录</p><strong class="mt-1 block text-xl sm: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>
|
||||
<p class="text-[11px] leading-4 sm:text-xs" :class="mutedTextClass">本页可恢复</p><strong class="mt-1 block text-xl sm: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>
|
||||
<p class="text-[11px] leading-4 sm:text-xs" :class="mutedTextClass">本页仅审计</p><strong class="mt-1 block text-xl sm:text-2xl" :class="primaryTextClass">{{ purgedCount }}</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -37,10 +37,11 @@
|
||||
</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-if="errorText && items.length === 0" 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-if="errorText && items.length > 0" class="border-b px-4 py-3 text-sm text-red-600 sm:px-6" :class="dividerClass">{{ errorText }}</div>
|
||||
<div v-if="!errorText && 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">
|
||||
<div v-if="!errorText && items.length > 0" class="divide-y" :class="dividerClass">
|
||||
<article
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
@@ -63,6 +64,14 @@
|
||||
|
||||
<DataPagination v-if="total > 0" :current-page="page" :page-size="size" :total="total" @page-change="changePage" @page-size-change="changePageSize" />
|
||||
</section>
|
||||
<BaseModal :show="showPurgeModal" title="确认物理清理" @close="closePurgeModal">
|
||||
<p class="text-sm" :class="mutedTextClass">确定清理“{{ pendingPurge ? fileName(pendingPurge) : '' }}”吗?文件本体不可恢复,但审计记录会永久保留。</p>
|
||||
<template #footer><BaseButton variant="secondary" @click="closePurgeModal">取消</BaseButton><BaseButton variant="danger" :loading="busyAction === 'purge'" @click="confirmPurge">确认物理清理</BaseButton></template>
|
||||
</BaseModal>
|
||||
<BaseModal :show="Boolean(restoredCode)" title="文件已恢复" @close="restoredCode = ''">
|
||||
<p class="text-sm" :class="mutedTextClass">恢复成功,新的取件码:</p>
|
||||
<div class="mt-3 flex items-center justify-between gap-3 rounded-xl border px-4 py-3" :class="panelClass"><strong class="text-xl tracking-[0.2em]" :class="primaryTextClass">{{ restoredCode }}</strong><BaseButton size="sm" variant="outline" @click="copyCode">复制</BaseButton></div>
|
||||
</BaseModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -71,10 +80,12 @@ import { computed, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { EraserIcon, FileX2Icon, InfinityIcon, RefreshCwIcon, RotateCcwIcon, Settings2Icon, ShieldCheckIcon, Trash2Icon } from 'lucide-vue-next'
|
||||
import BaseButton from '@/components/common/BaseButton.vue'
|
||||
import BaseModal from '@/components/common/BaseModal.vue'
|
||||
import DataPagination from '@/components/common/DataPagination.vue'
|
||||
import { useAdminTrash, useInjectedDarkMode } from '@/composables'
|
||||
import type { TrashFileItem } from '@/types'
|
||||
import { formatFileSize, formatTimestamp } from '@/utils/common'
|
||||
import { copyRetrieveCode } from '@/utils/clipboard'
|
||||
|
||||
const isDarkMode = useInjectedDarkMode()
|
||||
const router = useRouter()
|
||||
@@ -87,6 +98,9 @@ const isLoading = ref(false)
|
||||
const errorText = ref('')
|
||||
const busyId = ref<number | null>(null)
|
||||
const busyAction = ref('')
|
||||
const showPurgeModal = ref(false)
|
||||
const pendingPurge = ref<TrashFileItem | null>(null)
|
||||
const restoredCode = 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]')
|
||||
@@ -100,10 +114,13 @@ const expiryLabel = (item: TrashFileItem) => item.isTrashPurged ? `文件本体
|
||||
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 } }
|
||||
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 run = async (item: TrashFileItem, action: string, operation: () => Promise<unknown>) => { if (busyId.value !== null) return; busyId.value = item.id; busyAction.value = action; errorText.value = ''; try { const response = await operation(); if (action === 'restore') restoredCode.value = String((response as { detail?: { code?: string } })?.detail?.code || ''); 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) => void 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 purge = (item: TrashFileItem) => { if (busyId.value === null) { pendingPurge.value = item; showPurgeModal.value = true } }
|
||||
const closePurgeModal = () => { if (busyId.value === null) { showPurgeModal.value = false; pendingPurge.value = null } }
|
||||
const confirmPurge = () => { if (!pendingPurge.value) return; const item = pendingPurge.value; closePurgeModal(); void run(item, 'purge', () => purgeTrashItem(item.id)) }
|
||||
const copyCode = () => { if (restoredCode.value) void copyRetrieveCode(restoredCode.value) }
|
||||
const changePage = (nextPage: number) => { page.value = nextPage; void loadTrash() }
|
||||
const changePageSize = (nextSize: number) => { size.value = nextSize; page.value = 1; void loadTrash() }
|
||||
void loadTrash()
|
||||
|
||||
Reference in new issue
Block a user