mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-21 07:04:45 +08:00
fix(admin): default dashboard date range to today
This commit is contained in:
@@ -323,15 +323,12 @@ const formatLocalDate = (date: Date): string => {
|
|||||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize date range immediately
|
const getTodayLocalDate = () => formatLocalDate(new Date())
|
||||||
const now = new Date()
|
|
||||||
const weekAgo = new Date(now)
|
|
||||||
weekAgo.setDate(weekAgo.getDate() - 6)
|
|
||||||
|
|
||||||
// Date range
|
// Date range
|
||||||
const granularity = ref<'day' | 'hour'>('day')
|
const granularity = ref<'day' | 'hour'>('day')
|
||||||
const startDate = ref(formatLocalDate(weekAgo))
|
const startDate = ref(getTodayLocalDate())
|
||||||
const endDate = ref(formatLocalDate(now))
|
const endDate = ref(getTodayLocalDate())
|
||||||
|
|
||||||
// Granularity options for Select component
|
// Granularity options for Select component
|
||||||
const granularityOptions = computed(() => [
|
const granularityOptions = computed(() => [
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ const formatLD = (d: Date) => {
|
|||||||
const day = String(d.getDate()).padStart(2, '0')
|
const day = String(d.getDate()).padStart(2, '0')
|
||||||
return `${year}-${month}-${day}`
|
return `${year}-${month}-${day}`
|
||||||
}
|
}
|
||||||
const now = new Date(); const weekAgo = new Date(); weekAgo.setDate(weekAgo.getDate() - 6)
|
const getTodayLocalDate = () => formatLD(new Date())
|
||||||
const startDate = ref(formatLD(weekAgo)); const endDate = ref(formatLD(now))
|
const startDate = ref(getTodayLocalDate()); const endDate = ref(getTodayLocalDate())
|
||||||
const filters = ref<AdminUsageQueryParams>({ user_id: undefined, model: undefined, group_id: undefined, request_type: undefined, billing_type: null, start_date: startDate.value, end_date: endDate.value })
|
const filters = ref<AdminUsageQueryParams>({ user_id: undefined, model: undefined, group_id: undefined, request_type: undefined, billing_type: null, start_date: startDate.value, end_date: endDate.value })
|
||||||
const pagination = reactive({ page: 1, page_size: 20, total: 0 })
|
const pagination = reactive({ page: 1, page_size: 20, total: 0 })
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ const loadChartData = async () => {
|
|||||||
}
|
}
|
||||||
const applyFilters = () => { pagination.page = 1; loadLogs(); loadStats(); loadChartData() }
|
const applyFilters = () => { pagination.page = 1; loadLogs(); loadStats(); loadChartData() }
|
||||||
const refreshData = () => { loadLogs(); loadStats(); loadChartData() }
|
const refreshData = () => { loadLogs(); loadStats(); loadChartData() }
|
||||||
const resetFilters = () => { startDate.value = formatLD(weekAgo); endDate.value = formatLD(now); filters.value = { start_date: startDate.value, end_date: endDate.value, request_type: undefined, billing_type: null }; granularity.value = 'day'; applyFilters() }
|
const resetFilters = () => { startDate.value = getTodayLocalDate(); endDate.value = getTodayLocalDate(); filters.value = { start_date: startDate.value, end_date: endDate.value, request_type: undefined, billing_type: null }; granularity.value = 'day'; applyFilters() }
|
||||||
const handlePageChange = (p: number) => { pagination.page = p; loadLogs() }
|
const handlePageChange = (p: number) => { pagination.page = p; loadLogs() }
|
||||||
const handlePageSizeChange = (s: number) => { pagination.page_size = s; pagination.page = 1; loadLogs() }
|
const handlePageSizeChange = (s: number) => { pagination.page_size = s; pagination.page = 1; loadLogs() }
|
||||||
const cancelExport = () => exportAbortController?.abort()
|
const cancelExport = () => exportAbortController?.abort()
|
||||||
|
|||||||
Reference in New Issue
Block a user