Route analytics access through composable
This commit is contained in:
@@ -11,3 +11,4 @@ export { useRouteLoading } from './useRouteLoading'
|
||||
export { useSendFlow } from './useSendFlow'
|
||||
export { useSystemConfig } from './useSystemConfig'
|
||||
export { useTheme } from './useTheme'
|
||||
export { useTransferAnalytics } from './useTransferAnalytics'
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { StatsService } from '@/services'
|
||||
import type { AnalyticsData } from '@/types'
|
||||
|
||||
export function useTransferAnalytics() {
|
||||
const fetchAnalytics = async (start?: string, end?: string): Promise<AnalyticsData | null> => {
|
||||
const response = await StatsService.getAnalytics(start, end)
|
||||
return response.detail || null
|
||||
}
|
||||
|
||||
return {
|
||||
fetchAnalytics
|
||||
}
|
||||
}
|
||||
@@ -430,11 +430,10 @@ import {
|
||||
} from 'lucide-vue-next'
|
||||
import StatCard from '@/components/common/StatCard.vue'
|
||||
import SmoothTrendCanvas from '@/components/common/SmoothTrendCanvas.vue'
|
||||
import { useDashboardStats, useInjectedDarkMode } from '@/composables'
|
||||
import { useDashboardStats, useInjectedDarkMode, useTransferAnalytics } from '@/composables'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ROUTES } from '@/constants'
|
||||
import { useConfigStore } from '@/stores/configStore'
|
||||
import { StatsService } from '@/services'
|
||||
import { formatFileSize } from '@/utils/common'
|
||||
import type { AnalyticsData, AnalyticsFileRow, DashboardHealthAction } from '@/types'
|
||||
|
||||
@@ -447,6 +446,7 @@ const { dashboardData, errorMessage, fetchDashboardData, isLoading, lastUpdatedT
|
||||
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'))
|
||||
@@ -503,8 +503,7 @@ const formatBytes = (value: number | string | undefined) => formatFileSize(Numbe
|
||||
const fetchAnalyticsData = async () => {
|
||||
analyticsError.value = ''
|
||||
try {
|
||||
const response = await StatsService.getAnalytics(analyticsStart.value, analyticsEnd.value)
|
||||
analyticsData.value = response.detail || null
|
||||
analyticsData.value = await fetchAnalytics(analyticsStart.value, analyticsEnd.value)
|
||||
} catch (error) {
|
||||
analyticsError.value = error instanceof Error ? error.message : '统计加载失败'
|
||||
}
|
||||
|
||||
@@ -1376,14 +1376,14 @@ import DataPagination from '@/components/common/DataPagination.vue'
|
||||
import FileEditField from '@/components/common/FileEditField.vue'
|
||||
import BaseModal from '@/components/common/BaseModal.vue'
|
||||
import BaseButton from '@/components/common/BaseButton.vue'
|
||||
import { useAdminFiles, useInjectedDarkMode } from '@/composables'
|
||||
import { StatsService } from '@/services'
|
||||
import { useAdminFiles, useInjectedDarkMode, useTransferAnalytics } from '@/composables'
|
||||
import { formatFileSize, formatTimestamp } from '@/utils/common'
|
||||
|
||||
const { t } = useI18n()
|
||||
const isDarkMode = useInjectedDarkMode()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { fetchAnalytics } = useTransferAnalytics()
|
||||
|
||||
const fileTableHeaders = computed(() => [
|
||||
t('fileManage.headers.select'),
|
||||
@@ -1491,8 +1491,8 @@ const historyPageRows = computed(() => {
|
||||
const loadHistoryFiles = async () => {
|
||||
isHistoryLoading.value = true
|
||||
try {
|
||||
const response = await StatsService.getAnalytics()
|
||||
historyRows.value = response.detail?.historyFiles || []
|
||||
const analytics = await fetchAnalytics()
|
||||
historyRows.value = analytics?.historyFiles || []
|
||||
historyPage.value = 1
|
||||
} finally {
|
||||
isHistoryLoading.value = false
|
||||
|
||||
Reference in New Issue
Block a user