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