perf: set default date range to 1 week in HistoryDiagCard

This commit is contained in:
yangsy
2025-09-10 15:49:24 +08:00
parent 27e71fa797
commit 13c558bfc1
12 changed files with 72 additions and 49 deletions

View File

@@ -3,9 +3,10 @@ import { postSnmpLogPage } from '@/apis/requests';
import { DEVICE_SNMP_LOGS_QUERY_KEY } from '@/constants';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
import dayjs from 'dayjs';
import type { DatePickerProps } from 'naive-ui';
import { computed, watch, type Ref } from 'vue';
export function useDeviceSnmpLogsQuery(stationCode: Ref<string>, ndmDevice: Ref<NdmDeviceResultVO>, dateTimeRange: Ref<[number, number]>, page: Ref<number>, pageSize: Ref<number>) {
export function useDeviceSnmpLogsQuery(stationCode: Ref<string>, ndmDevice: Ref<NdmDeviceResultVO>, dateTimeRange: Ref<DatePickerProps['value']>, page: Ref<number>, pageSize: Ref<number>) {
const queryClient = useQueryClient();
const queryKey = computed(() => [DEVICE_SNMP_LOGS_QUERY_KEY, stationCode, ndmDevice, dateTimeRange, page.value, pageSize.value]);
@@ -15,13 +16,16 @@ export function useDeviceSnmpLogsQuery(stationCode: Ref<string>, ndmDevice: Ref<
isPending,
isFetching,
error,
refetch,
} = useQuery({
queryKey,
enabled: computed(() => dateTimeRange.value.every((dateTime) => dateTime > 0)),
enabled: computed(() => !!dateTimeRange.value),
queryFn: async () => {
if (!dateTimeRange.value) throw new Error('请选择时间范围');
const range = dateTimeRange.value as [number, number];
const deviceId = ndmDevice.value.id;
const createdTime_precisest = dayjs(dateTimeRange.value[0]).format('YYYY-MM-DD HH:mm:ss');
const createdTime_preciseed = dayjs(dateTimeRange.value[1]).format('YYYY-MM-DD HH:mm:ss');
const createdTime_precisest = dayjs(range[0]).format('YYYY-MM-DD HH:mm:ss');
const createdTime_preciseed = dayjs(range[1]).format('YYYY-MM-DD HH:mm:ss');
const restParams: Omit<PageParams<{ id: string }>, 'model' | 'extra'> = {
current: page.value,
size: pageSize.value,
@@ -53,6 +57,7 @@ export function useDeviceSnmpLogsQuery(stationCode: Ref<string>, ndmDevice: Ref<
isPending,
isFetching,
error,
refetch,
refresh,
};
}