678 lines
25 KiB
Vue
678 lines
25 KiB
Vue
<template>
|
|
<div class="p-6">
|
|
<div class="mb-6 flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">
|
|
<div>
|
|
<p class="text-sm" :class="[mutedTextClass]">FileCodeBox Admin</p>
|
|
<h2 class="text-2xl font-bold" :class="[primaryTextClass]">
|
|
{{ t('admin.dashboard.title') }}
|
|
</h2>
|
|
<p class="mt-1 text-xs" :class="[mutedTextClass]">
|
|
{{ t('admin.dashboard.lastUpdated', { time: lastUpdatedText }) }}
|
|
</p>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
:disabled="isLoading"
|
|
@click="fetchDashboardData"
|
|
class="inline-flex items-center justify-center rounded-lg px-4 py-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-70"
|
|
:class="[
|
|
isDarkMode
|
|
? 'bg-gray-800 text-gray-200 hover:bg-gray-700'
|
|
: 'bg-white text-gray-700 shadow-sm hover:bg-gray-50'
|
|
]"
|
|
>
|
|
<RefreshCwIcon class="mr-2 h-4 w-4" :class="{ 'animate-spin': isLoading }" />
|
|
{{ isLoading ? t('admin.dashboard.refreshing') : t('admin.dashboard.refresh') }}
|
|
</button>
|
|
</div>
|
|
|
|
<div
|
|
v-if="errorMessage"
|
|
class="mb-6 rounded-lg border px-4 py-3 text-sm"
|
|
:class="[
|
|
isDarkMode
|
|
? 'border-red-900/50 bg-red-950/30 text-red-200'
|
|
: 'border-red-200 bg-red-50 text-red-700'
|
|
]"
|
|
>
|
|
{{ errorMessage }}
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
|
|
<StatCard
|
|
:title="t('admin.dashboard.totalFiles')"
|
|
:value="dashboardData.totalFiles"
|
|
:icon="FilesIcon"
|
|
icon-color="indigo"
|
|
>
|
|
<template #description>
|
|
{{ t('admin.dashboard.yesterdayShares', { count: dashboardData.yesterdayCount }) }}
|
|
</template>
|
|
</StatCard>
|
|
|
|
<StatCard
|
|
:title="t('admin.dashboard.storageSpace')"
|
|
:value="dashboardData.storageUsedText"
|
|
:icon="HardDriveIcon"
|
|
icon-color="purple"
|
|
>
|
|
<template #description>
|
|
{{ t('admin.dashboard.todayIncrease', { count: dashboardData.todaySizeText }) }}
|
|
</template>
|
|
</StatCard>
|
|
|
|
<StatCard
|
|
:title="t('admin.dashboard.todayShares')"
|
|
:value="dashboardData.todayCount"
|
|
:icon="UploadCloudIcon"
|
|
icon-color="green"
|
|
>
|
|
<template #description>
|
|
{{ t('admin.dashboard.yesterdayShares', { count: dashboardData.yesterdayCount }) }}
|
|
</template>
|
|
</StatCard>
|
|
|
|
<StatCard
|
|
:title="t('admin.dashboard.totalRetrievals')"
|
|
:value="dashboardData.usedCount"
|
|
:icon="DownloadCloudIcon"
|
|
icon-color="blue"
|
|
>
|
|
<template #description>
|
|
{{ t('admin.dashboard.serverUptime') }} {{ dashboardData.sysUptimeText }}
|
|
</template>
|
|
</StatCard>
|
|
</div>
|
|
|
|
<div v-if="dashboardData.hasExtendedStats" class="mt-6 grid grid-cols-1 gap-6 xl:grid-cols-3">
|
|
<section
|
|
class="rounded-[30px] p-5 shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:shadow-lg xl:col-span-2"
|
|
:class="[panelClass, cardHoverClass]"
|
|
>
|
|
<div class="mb-5 flex items-center justify-between">
|
|
<div>
|
|
<h3 class="text-lg font-semibold" :class="[primaryTextClass]">
|
|
{{ t('admin.dashboard.fileHealth') }}
|
|
</h3>
|
|
<p class="text-sm" :class="[mutedTextClass]">
|
|
{{ t('admin.dashboard.fileHealthDesc') }}
|
|
</p>
|
|
</div>
|
|
<ActivityIcon
|
|
class="h-5 w-5"
|
|
:class="[isDarkMode ? 'text-indigo-300' : 'text-indigo-500']"
|
|
/>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
|
|
<MetricProgress
|
|
:label="t('admin.dashboard.activeFileRatio')"
|
|
:value="dashboardData.activeRatio"
|
|
:detail="`${dashboardData.activeCount} / ${dashboardData.totalFiles}`"
|
|
tone="green"
|
|
/>
|
|
<MetricProgress
|
|
:label="t('admin.dashboard.fileShareRatio')"
|
|
:value="dashboardData.fileRatio"
|
|
:detail="t('admin.dashboard.binaryFiles', { count: dashboardData.fileCount })"
|
|
tone="indigo"
|
|
/>
|
|
<MetricProgress
|
|
:label="t('admin.dashboard.textShareRatio')"
|
|
:value="dashboardData.textRatio"
|
|
:detail="t('admin.dashboard.textShares', { count: dashboardData.textCount })"
|
|
tone="purple"
|
|
/>
|
|
</div>
|
|
|
|
<div class="mt-6 grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-5">
|
|
<button
|
|
v-for="action in healthActions"
|
|
:key="action.key"
|
|
type="button"
|
|
class="group flex min-h-28 flex-col justify-between rounded-[30px] border p-4 text-left transition-colors"
|
|
:class="getHealthActionClass(action.tone)"
|
|
@click="openHealthQueue(action.health)"
|
|
>
|
|
<span class="flex items-start justify-between gap-3">
|
|
<span>
|
|
<span class="block text-2xl font-semibold">{{ action.count }}</span>
|
|
<span class="mt-1 block text-sm font-medium">{{ action.label }}</span>
|
|
</span>
|
|
<component :is="getHealthActionIcon(action.tone)" class="h-5 w-5 shrink-0" />
|
|
</span>
|
|
<span class="mt-3 flex items-center justify-between gap-2 text-xs">
|
|
<span class="line-clamp-2">{{ action.description }}</span>
|
|
<ArrowRightIcon
|
|
class="h-4 w-4 shrink-0 transition-transform group-hover:translate-x-0.5"
|
|
/>
|
|
</span>
|
|
</button>
|
|
</div>
|
|
|
|
<div class="mt-6 grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
<div
|
|
class="rounded-[30px] border p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md"
|
|
:class="[subtlePanelClass, cardHoverClass]"
|
|
>
|
|
<p class="text-sm" :class="[mutedTextClass]">
|
|
{{ t('admin.dashboard.expiredFiles') }}
|
|
</p>
|
|
<div class="mt-2 flex items-end justify-between">
|
|
<strong class="text-3xl" :class="[primaryTextClass]">
|
|
{{ dashboardData.expiredCount }}
|
|
</strong>
|
|
<span class="text-sm" :class="[mutedTextClass]">
|
|
{{ t('admin.dashboard.needCleanup') }}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
class="rounded-[30px] border p-4 transition-all duration-200 hover:-translate-y-0.5 hover:shadow-md"
|
|
:class="[subtlePanelClass, cardHoverClass]"
|
|
>
|
|
<p class="text-sm" :class="[mutedTextClass]">
|
|
{{ t('admin.dashboard.chunkedFiles') }}
|
|
</p>
|
|
<div class="mt-2 flex items-end justify-between">
|
|
<strong class="text-3xl" :class="[primaryTextClass]">
|
|
{{ dashboardData.chunkedCount }}
|
|
</strong>
|
|
<span class="text-sm" :class="[mutedTextClass]">
|
|
{{ dashboardData.enableChunk ? t('common.enabled') : t('common.disabled') }}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section
|
|
class="rounded-[30px] p-5 shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:shadow-lg"
|
|
:class="[panelClass, cardHoverClass]"
|
|
>
|
|
<div class="mb-5">
|
|
<h3 class="text-lg font-semibold" :class="[primaryTextClass]">
|
|
{{ t('admin.dashboard.storagePolicy') }}
|
|
</h3>
|
|
<p class="text-sm" :class="[mutedTextClass]">
|
|
{{ t('admin.dashboard.storagePolicyDesc') }}
|
|
</p>
|
|
</div>
|
|
|
|
<div class="space-y-4">
|
|
<PolicyRow
|
|
:label="t('admin.dashboard.storageBackend')"
|
|
:value="dashboardData.storageBackend"
|
|
/>
|
|
<PolicyRow
|
|
:label="t('admin.dashboard.singleFileLimit')"
|
|
:value="dashboardData.uploadSizeLimitText"
|
|
/>
|
|
<PolicyRow
|
|
:label="t('admin.dashboard.guestUpload')"
|
|
:value="dashboardData.openUpload ? t('common.enabled') : t('common.disabled')"
|
|
/>
|
|
<PolicyRow :label="t('admin.dashboard.maxSaveTime')" :value="maxSaveTimeText" />
|
|
</div>
|
|
|
|
<div class="mt-5">
|
|
<div class="mb-2 flex items-center justify-between text-sm">
|
|
<span :class="[mutedTextClass]">{{ t('admin.dashboard.todayCapacityReference') }}</span>
|
|
<span :class="[primaryTextClass]">{{ dashboardData.todaySizeRatio }}%</span>
|
|
</div>
|
|
<div
|
|
class="h-2 overflow-hidden rounded-full"
|
|
:class="[isDarkMode ? 'bg-gray-700' : 'bg-gray-100']"
|
|
>
|
|
<div
|
|
class="h-full rounded-full bg-indigo-500"
|
|
:style="{ width: `${dashboardData.todaySizeRatio}%` }"
|
|
></div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<div class="mt-6 grid grid-cols-1 gap-6 xl:grid-cols-2">
|
|
<section
|
|
class="rounded-[30px] p-5 shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:shadow-lg"
|
|
:class="[panelClass, cardHoverClass]"
|
|
>
|
|
<div class="mb-5 flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
|
<div>
|
|
<h3 class="text-lg font-semibold" :class="[primaryTextClass]">下载/上传趋势</h3>
|
|
<p class="text-sm" :class="[mutedTextClass]">
|
|
{{ analyticsSummaryText }}
|
|
</p>
|
|
</div>
|
|
<div class="flex flex-wrap items-center gap-2">
|
|
<input
|
|
v-model="analyticsStart"
|
|
type="date"
|
|
min="1900-01-01"
|
|
max="2100-12-31"
|
|
class="native-date-input h-12 min-w-0 flex-1 cursor-pointer rounded-xl border px-3 text-sm sm:flex-none sm:min-w-40"
|
|
:class="[fieldClass]"
|
|
@click="openNativeDatePicker"
|
|
@change="fetchAnalyticsData"
|
|
/>
|
|
<input
|
|
v-model="analyticsEnd"
|
|
type="date"
|
|
min="1900-01-01"
|
|
max="2100-12-31"
|
|
class="native-date-input h-12 min-w-0 flex-1 cursor-pointer rounded-xl border px-3 text-sm sm:flex-none sm:min-w-40"
|
|
:class="[fieldClass]"
|
|
@click="openNativeDatePicker"
|
|
@change="fetchAnalyticsData"
|
|
/>
|
|
<button
|
|
type="button"
|
|
class="h-11 rounded-lg border px-3 text-sm font-medium transition-colors"
|
|
:class="detailActionClass"
|
|
@click="trendCanvas?.zoom(0.75)"
|
|
>
|
|
放大
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="h-11 rounded-lg border px-3 text-sm font-medium transition-colors"
|
|
:class="detailActionClass"
|
|
@click="trendCanvas?.zoom(1.33)"
|
|
>
|
|
缩小
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="h-11 rounded-lg border px-3 text-sm font-medium transition-colors"
|
|
:class="detailActionClass"
|
|
@click="trendCanvas?.resetWindow()"
|
|
>
|
|
重置
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div
|
|
v-if="analyticsError"
|
|
class="mb-4 rounded-lg border px-4 py-3 text-sm"
|
|
:class="[
|
|
isDarkMode
|
|
? 'border-red-900/50 bg-red-950/30 text-red-200'
|
|
: 'border-red-200 bg-red-50 text-red-700'
|
|
]"
|
|
>
|
|
{{ analyticsError }}
|
|
</div>
|
|
<SmoothTrendCanvas
|
|
ref="trendCanvas"
|
|
:rows="analyticsDailyRows"
|
|
:is-dark-mode="isDarkMode"
|
|
@window-change="analyticsWindowText = $event"
|
|
/>
|
|
</section>
|
|
|
|
<section
|
|
class="rounded-[30px] p-5 shadow-sm transition-all duration-200 hover:-translate-y-0.5 hover:shadow-lg"
|
|
:class="[panelClass, cardHoverClass]"
|
|
>
|
|
<div class="mb-5 flex items-center justify-between">
|
|
<div>
|
|
<h3 class="text-lg font-semibold" :class="[primaryTextClass]">热门下载 Top 5</h3>
|
|
<p class="text-sm" :class="[mutedTextClass]">统计当前日期范围内的下载次数和流量</p>
|
|
</div>
|
|
<DownloadCloudIcon
|
|
class="h-5 w-5"
|
|
:class="[isDarkMode ? 'text-indigo-300' : 'text-indigo-500']"
|
|
/>
|
|
</div>
|
|
<div class="overflow-x-auto">
|
|
<table
|
|
class="min-w-full divide-y"
|
|
:class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-200']"
|
|
>
|
|
<thead>
|
|
<tr>
|
|
<th
|
|
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
|
:class="[mutedTextClass]"
|
|
>
|
|
文件
|
|
</th>
|
|
<th
|
|
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
|
:class="[mutedTextClass]"
|
|
>
|
|
下载
|
|
</th>
|
|
<th
|
|
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
|
:class="[mutedTextClass]"
|
|
>
|
|
流量
|
|
</th>
|
|
<th
|
|
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
|
:class="[mutedTextClass]"
|
|
>
|
|
状态
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y" :class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-100']">
|
|
<tr v-if="analyticsTopFiles.length === 0">
|
|
<td colspan="4" class="px-4 py-8 text-center text-sm" :class="[mutedTextClass]">
|
|
暂无下载记录
|
|
</td>
|
|
</tr>
|
|
<tr
|
|
v-for="file in analyticsTopFiles"
|
|
:key="file.code"
|
|
:class="[isDarkMode ? 'hover:bg-gray-700/60' : 'hover:bg-gray-50']"
|
|
>
|
|
<td
|
|
class="max-w-xs truncate px-4 py-3 text-sm font-medium"
|
|
:class="[primaryTextClass]"
|
|
:title="file.name"
|
|
>
|
|
{{ file.name }}
|
|
</td>
|
|
<td class="px-4 py-3 text-sm" :class="[primaryTextClass]">
|
|
{{ file.download_count || 0 }}
|
|
</td>
|
|
<td class="px-4 py-3 text-sm" :class="[primaryTextClass]">
|
|
{{ formatBytes(file.download_traffic) }}
|
|
</td>
|
|
<td class="px-4 py-3 text-sm" :class="[mutedTextClass]">
|
|
{{ file.current ? '现存' : '历史' }}
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<footer
|
|
class="mt-6 flex flex-col gap-2 border-t pt-4 text-xs sm:flex-row sm:items-center sm:justify-between"
|
|
:class="[isDarkMode ? 'border-gray-800 text-gray-500' : 'border-gray-200 text-gray-500']"
|
|
>
|
|
<span>{{ t('admin.dashboard.footerProduct') }}</span>
|
|
<span class="inline-flex items-center gap-2">
|
|
<span>{{ t('admin.dashboard.runtimeVersion') }}</span>
|
|
<span
|
|
class="rounded-md border px-2 py-0.5 font-medium"
|
|
:class="[
|
|
isDarkMode
|
|
? 'border-gray-700 bg-gray-800/70 text-gray-300'
|
|
: 'border-gray-200 bg-white text-gray-700'
|
|
]"
|
|
>
|
|
{{ versionText }}
|
|
</span>
|
|
</span>
|
|
</footer>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, defineComponent, h, onMounted, ref } from 'vue'
|
|
import type { Component, PropType } from 'vue'
|
|
import { storeToRefs } from 'pinia'
|
|
import { useRouter } from 'vue-router'
|
|
import {
|
|
ActivityIcon,
|
|
AlertTriangleIcon,
|
|
ArrowRightIcon,
|
|
CheckCircleIcon,
|
|
DownloadCloudIcon,
|
|
FilesIcon,
|
|
HardDriveIcon,
|
|
RefreshCwIcon,
|
|
ShieldCheckIcon,
|
|
UploadCloudIcon
|
|
} from 'lucide-vue-next'
|
|
import StatCard from '@/components/common/StatCard.vue'
|
|
import SmoothTrendCanvas from '@/components/common/SmoothTrendCanvas.vue'
|
|
import { useDashboardStats, useInjectedDarkMode, useTransferAnalytics } from '@/composables'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { ROUTES } from '@/constants'
|
|
import { useConfigStore } from '@/stores/configStore'
|
|
import { formatFileSize } from '@/utils/common'
|
|
import type { AnalyticsData, AnalyticsFileRow, DashboardHealthAction } from '@/types'
|
|
|
|
const isDarkMode = useInjectedDarkMode()
|
|
const { t } = useI18n()
|
|
const router = useRouter()
|
|
const configStore = useConfigStore()
|
|
const { appVersion } = storeToRefs(configStore)
|
|
const { dashboardData, errorMessage, fetchDashboardData, isLoading, lastUpdatedText } =
|
|
useDashboardStats({
|
|
loadFailedMessage: t('admin.dashboard.loadFailed')
|
|
})
|
|
const { fetchAnalytics } = useTransferAnalytics()
|
|
|
|
const primaryTextClass = computed(() => (isDarkMode.value ? 'text-white' : 'text-gray-900'))
|
|
const mutedTextClass = computed(() => (isDarkMode.value ? 'text-gray-400' : 'text-gray-500'))
|
|
const versionText = computed(() => appVersion.value || t('admin.dashboard.versionPending'))
|
|
const panelClass = computed(() =>
|
|
isDarkMode.value ? 'bg-gray-800/80 border border-gray-700' : 'bg-white border border-gray-100'
|
|
)
|
|
const fieldClass = computed(() =>
|
|
isDarkMode.value
|
|
? 'border-gray-600 bg-gray-700 text-white'
|
|
: 'border-gray-300 bg-white text-gray-900'
|
|
)
|
|
const detailActionClass = computed(() =>
|
|
isDarkMode.value
|
|
? 'border-gray-700 bg-gray-700/50 text-gray-300 hover:border-gray-600 hover:bg-gray-700'
|
|
: 'border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50'
|
|
)
|
|
const subtlePanelClass = computed(() =>
|
|
isDarkMode.value ? 'border-gray-700 bg-gray-900/30' : 'border-gray-100 bg-gray-50'
|
|
)
|
|
const cardHoverClass = computed(() =>
|
|
isDarkMode.value
|
|
? 'hover:border-indigo-500/40 hover:bg-gray-800 hover:shadow-black/20'
|
|
: 'hover:border-indigo-200 hover:shadow-gray-200/80'
|
|
)
|
|
const maxSaveTimeText = computed(() => {
|
|
if (!dashboardData.maxSaveSeconds) return t('admin.dashboard.noSaveLimit')
|
|
const days = Math.floor(dashboardData.maxSaveSeconds / 86400)
|
|
if (days >= 1) return `${days}${t('common.day')}`
|
|
const hours = Math.floor(dashboardData.maxSaveSeconds / 3600)
|
|
if (hours >= 1) return `${hours}${t('common.hour')}`
|
|
return `${Math.floor(dashboardData.maxSaveSeconds / 60)}${t('common.minute')}`
|
|
})
|
|
|
|
const today = () => new Date().toISOString().slice(0, 10)
|
|
const daysAgo = (days: number) => {
|
|
const date = new Date()
|
|
date.setDate(date.getDate() - days)
|
|
return date.toISOString().slice(0, 10)
|
|
}
|
|
const openNativeDatePicker = (event: MouseEvent) => {
|
|
const input = event.currentTarget as HTMLInputElement & { showPicker?: () => void }
|
|
input.showPicker?.()
|
|
}
|
|
const trendCanvas = ref<InstanceType<typeof SmoothTrendCanvas> | null>(null)
|
|
const analyticsStart = ref(daysAgo(120))
|
|
const analyticsEnd = ref(today())
|
|
const analyticsData = ref<AnalyticsData | null>(null)
|
|
const analyticsError = ref('')
|
|
const analyticsWindowText = ref('无数据')
|
|
const analyticsDailyRows = computed(() => analyticsData.value?.daily || [])
|
|
const analyticsTopFiles = computed<AnalyticsFileRow[]>(() => analyticsData.value?.topFiles || [])
|
|
const analyticsUploadTrafficText = computed(() =>
|
|
formatBytes(analyticsData.value?.totals?.uploadTraffic || 0)
|
|
)
|
|
const analyticsDownloadTrafficText = computed(() =>
|
|
formatBytes(analyticsData.value?.totals?.downloadTraffic || 0)
|
|
)
|
|
const analyticsSummaryText = computed(
|
|
() =>
|
|
`${analyticsWindowText.value},下载 ${analyticsData.value?.totals?.totalDownloads || 0} 次 / ${
|
|
analyticsDownloadTrafficText.value
|
|
},上传 ${analyticsData.value?.totals?.totalUploads || 0} 次 / ${
|
|
analyticsUploadTrafficText.value
|
|
}`
|
|
)
|
|
const formatBytes = (value: number | string | undefined) => formatFileSize(Number(value || 0), 1)
|
|
|
|
const fetchAnalyticsData = async () => {
|
|
analyticsError.value = ''
|
|
try {
|
|
analyticsData.value = await fetchAnalytics(analyticsStart.value, analyticsEnd.value)
|
|
} catch (error) {
|
|
analyticsError.value = error instanceof Error ? error.message : '统计加载失败'
|
|
}
|
|
}
|
|
|
|
const healthActions = computed<DashboardHealthAction[]>(() => [
|
|
{
|
|
key: 'attention',
|
|
label: t('admin.dashboard.healthActions.attention.title'),
|
|
description: t('admin.dashboard.healthActions.attention.description'),
|
|
count: dashboardData.healthAttentionCount,
|
|
health: 'attention',
|
|
tone: dashboardData.healthAttentionCount > 0 ? 'danger' : 'success'
|
|
},
|
|
{
|
|
key: 'storageIssue',
|
|
label: t('admin.dashboard.healthActions.storageIssue.title'),
|
|
description: t('admin.dashboard.healthActions.storageIssue.description'),
|
|
count: dashboardData.storageIssueCount,
|
|
health: 'storage_issue',
|
|
tone: dashboardData.storageIssueCount > 0 ? 'danger' : 'success'
|
|
},
|
|
{
|
|
key: 'expiringSoon',
|
|
label: t('admin.dashboard.healthActions.expiringSoon.title'),
|
|
description: t('admin.dashboard.healthActions.expiringSoon.description'),
|
|
count: dashboardData.expiringSoonCount,
|
|
health: 'expiring_soon',
|
|
tone: dashboardData.expiringSoonCount > 0 ? 'warning' : 'success'
|
|
},
|
|
{
|
|
key: 'neverRetrieved',
|
|
label: t('admin.dashboard.healthActions.neverRetrieved.title'),
|
|
description: t('admin.dashboard.healthActions.neverRetrieved.description'),
|
|
count: dashboardData.neverRetrievedCount,
|
|
health: 'never_retrieved',
|
|
tone: dashboardData.neverRetrievedCount > 0 ? 'neutral' : 'success'
|
|
},
|
|
{
|
|
key: 'permanent',
|
|
label: t('admin.dashboard.healthActions.permanent.title'),
|
|
description: t('admin.dashboard.healthActions.permanent.description'),
|
|
count: dashboardData.permanentCount,
|
|
health: 'permanent',
|
|
tone: 'success'
|
|
}
|
|
])
|
|
|
|
const healthActionIconMap: Record<DashboardHealthAction['tone'], Component> = {
|
|
danger: AlertTriangleIcon,
|
|
warning: AlertTriangleIcon,
|
|
success: CheckCircleIcon,
|
|
neutral: ShieldCheckIcon
|
|
}
|
|
|
|
const getHealthActionIcon = (tone: DashboardHealthAction['tone']) => healthActionIconMap[tone]
|
|
|
|
const getHealthActionClass = (tone: DashboardHealthAction['tone']) => {
|
|
const darkClasses: Record<DashboardHealthAction['tone'], string> = {
|
|
danger: 'border-red-500/20 bg-red-500/10 text-red-200 hover:border-red-400/40',
|
|
warning: 'border-amber-500/20 bg-amber-500/10 text-amber-200 hover:border-amber-400/40',
|
|
success: 'border-emerald-500/20 bg-emerald-500/10 text-emerald-200 hover:border-emerald-400/40',
|
|
neutral: 'border-gray-700 bg-gray-900/30 text-gray-300 hover:border-gray-600'
|
|
}
|
|
const lightClasses: Record<DashboardHealthAction['tone'], string> = {
|
|
danger: 'border-red-100 bg-red-50 text-red-700 hover:border-red-200',
|
|
warning: 'border-amber-100 bg-amber-50 text-amber-700 hover:border-amber-200',
|
|
success: 'border-emerald-100 bg-emerald-50 text-emerald-700 hover:border-emerald-200',
|
|
neutral: 'border-gray-100 bg-gray-50 text-gray-700 hover:border-gray-200'
|
|
}
|
|
|
|
return isDarkMode.value ? darkClasses[tone] : lightClasses[tone]
|
|
}
|
|
|
|
const openHealthQueue = (health: DashboardHealthAction['health']) => {
|
|
void router.push({
|
|
path: ROUTES.FILE_MANAGE,
|
|
query: { health }
|
|
})
|
|
}
|
|
|
|
const MetricProgress = defineComponent({
|
|
name: 'MetricProgress',
|
|
props: {
|
|
label: { type: String, required: true },
|
|
value: { type: Number, required: true },
|
|
detail: { type: String, required: true },
|
|
tone: {
|
|
type: String as PropType<'green' | 'indigo' | 'purple'>,
|
|
required: true
|
|
}
|
|
},
|
|
setup(props) {
|
|
const toneClass = computed(() => {
|
|
const classes = {
|
|
green: 'bg-green-500',
|
|
indigo: 'bg-indigo-500',
|
|
purple: 'bg-purple-500'
|
|
}
|
|
return classes[props.tone]
|
|
})
|
|
|
|
return () =>
|
|
h(
|
|
'div',
|
|
{
|
|
class:
|
|
'rounded-[30px] border border-gray-200/60 p-4 transition-all duration-200 hover:-translate-y-0.5 hover:border-indigo-200 hover:shadow-md hover:shadow-gray-200/80 dark:border-gray-700 dark:hover:border-indigo-500/40 dark:hover:bg-gray-800 dark:hover:shadow-black/20'
|
|
},
|
|
[
|
|
h('div', { class: 'mb-2 flex items-center justify-between text-sm' }, [
|
|
h('span', { class: 'text-gray-500 dark:text-gray-400' }, props.label),
|
|
h('span', { class: 'font-medium text-gray-900 dark:text-white' }, `${props.value}%`)
|
|
]),
|
|
h('div', { class: 'h-2 overflow-hidden rounded-full bg-gray-100 dark:bg-gray-700' }, [
|
|
h('div', {
|
|
class: ['h-full rounded-full', toneClass.value],
|
|
style: { width: `${props.value}%` }
|
|
})
|
|
]),
|
|
h('p', { class: 'mt-2 text-sm text-gray-500 dark:text-gray-400' }, props.detail)
|
|
]
|
|
)
|
|
}
|
|
})
|
|
|
|
const PolicyRow = defineComponent({
|
|
name: 'PolicyRow',
|
|
props: {
|
|
label: { type: String, required: true },
|
|
value: { type: String, required: true }
|
|
},
|
|
setup(props) {
|
|
return () =>
|
|
h(
|
|
'div',
|
|
{
|
|
class:
|
|
'flex items-center justify-between gap-4 border-b border-gray-200/60 pb-3 last:border-b-0 dark:border-gray-700'
|
|
},
|
|
[
|
|
h('span', { class: 'text-sm text-gray-500 dark:text-gray-400' }, props.label),
|
|
h('span', { class: 'text-sm font-medium text-gray-900 dark:text-white' }, props.value)
|
|
]
|
|
)
|
|
}
|
|
})
|
|
|
|
onMounted(() => {
|
|
void Promise.all([fetchDashboardData(), fetchAnalyticsData()])
|
|
})
|
|
</script>
|