Commit 09c1aa049332da29ee335e030d6ff6f1947ec7d9
1 parent
ccd59f74
perf(src/packages/components): 优化日期控件,区分是否是从快捷选项里选择的
Showing
2 changed files
with
22 additions
and
9 deletions
@@ -73,10 +73,11 @@ export const useChartDataFetch = ( | @@ -73,10 +73,11 @@ export const useChartDataFetch = ( | ||
73 | let endTsValue = null | 73 | let endTsValue = null |
74 | const {requestParams} = toRaw(targetComponent.request) | 74 | const {requestParams} = toRaw(targetComponent.request) |
75 | const {Params} = requestParams | 75 | const {Params} = requestParams |
76 | - const {entityType, startTs, endTs} = Params | 76 | + const {startTs, endTs, shortcutsSelect} = Params |
77 | let days = Math.ceil(((endTs as unknown as number) - (startTs as unknown as number)) / (1 * 60 * 60 * 24 * 1000)) | 77 | let days = Math.ceil(((endTs as unknown as number) - (startTs as unknown as number)) / (1 * 60 * 60 * 24 * 1000)) |
78 | const ShortcutsDays = [1, 7, 30] | 78 | const ShortcutsDays = [1, 7, 30] |
79 | - if (entityType === 'DEVICE') { | 79 | + // shortcutsSelect为真 |
80 | + if (shortcutsSelect) { | ||
80 | //等于这三个,说明是从快捷选项里面选的 | 81 | //等于这三个,说明是从快捷选项里面选的 |
81 | if(ShortcutsDays.includes(days)) { | 82 | if(ShortcutsDays.includes(days)) { |
82 | days = days <= 2 ? 1 : days<= 8 ? 7 : 30 | 83 | days = days <= 2 ? 1 : days<= 8 ? 7 : 30 |
@@ -85,12 +86,12 @@ export const useChartDataFetch = ( | @@ -85,12 +86,12 @@ export const useChartDataFetch = ( | ||
85 | endTsValue = dayjs().endOf('day').valueOf() | 86 | endTsValue = dayjs().endOf('day').valueOf() |
86 | ;(toRaw(targetComponent.request).requestParams.Params.startTs as unknown as number) = startTsValue as number | 87 | ;(toRaw(targetComponent.request).requestParams.Params.startTs as unknown as number) = startTsValue as number |
87 | ;(toRaw(targetComponent.request).requestParams.Params.endTs as unknown as number) = endTsValue | 88 | ;(toRaw(targetComponent.request).requestParams.Params.endTs as unknown as number) = endTsValue |
88 | - } else { | ||
89 | - //否则,选择的是什么日期区间就是什么 | ||
90 | - (toRaw(targetComponent.request).requestParams.Params.startTs as unknown as number) = startTs as unknown as number | ||
91 | - (toRaw(targetComponent.request).requestParams.Params.endTs as unknown as number) = endTs as unknown as number | ||
92 | } | 89 | } |
93 | - } | 90 | + } else { |
91 | + //否则,选择的是什么日期区间就是什么 | ||
92 | + (toRaw(targetComponent.request).requestParams.Params.startTs as unknown as number) = startTs as unknown as number | ||
93 | + (toRaw(targetComponent.request).requestParams.Params.endTs as unknown as number) = endTs as unknown as number | ||
94 | + } | ||
94 | const res = await customRequest(toRaw(targetComponent.request)) | 95 | const res = await customRequest(toRaw(targetComponent.request)) |
95 | if (res) { | 96 | if (res) { |
96 | try { | 97 | try { |
@@ -11,6 +11,7 @@ interface Value { | @@ -11,6 +11,7 @@ interface Value { | ||
11 | startTs?: Nullable<number> | 11 | startTs?: Nullable<number> |
12 | endTs?: Nullable<number> | 12 | endTs?: Nullable<number> |
13 | limit?: Nullable<number> | 13 | limit?: Nullable<number> |
14 | + shortcutsSelect?: Nullable<boolean> | ||
14 | } | 15 | } |
15 | 16 | ||
16 | const props = withDefaults( | 17 | const props = withDefaults( |
@@ -32,20 +33,25 @@ const timePeriod = ref<Nullable<[number, number]>>(null) | @@ -32,20 +33,25 @@ const timePeriod = ref<Nullable<[number, number]>>(null) | ||
32 | const agg = ref() | 33 | const agg = ref() |
33 | const interval = ref() | 34 | const interval = ref() |
34 | const limit = ref(7) | 35 | const limit = ref(7) |
36 | +//区分是否是从快捷选项里选择的 | ||
37 | +const shortcutsSelect = ref(false) | ||
35 | const rangeShortcuts = { | 38 | const rangeShortcuts = { |
36 | 昨天: () => { | 39 | 昨天: () => { |
40 | + shortcutsSelect.value = true | ||
37 | return [ | 41 | return [ |
38 | dayjs().startOf('day').valueOf(), | 42 | dayjs().startOf('day').valueOf(), |
39 | dayjs().endOf('day').valueOf() | 43 | dayjs().endOf('day').valueOf() |
40 | ] as const | 44 | ] as const |
41 | }, | 45 | }, |
42 | 最近7天: () => { | 46 | 最近7天: () => { |
47 | + shortcutsSelect.value = true | ||
43 | return [ | 48 | return [ |
44 | dayjs().subtract(6, 'day').startOf('day').valueOf(), | 49 | dayjs().subtract(6, 'day').startOf('day').valueOf(), |
45 | dayjs().endOf('day').valueOf() | 50 | dayjs().endOf('day').valueOf() |
46 | ] as const | 51 | ] as const |
47 | }, | 52 | }, |
48 | 最近30天: () => { | 53 | 最近30天: () => { |
54 | + shortcutsSelect.value = true | ||
49 | return [ | 55 | return [ |
50 | dayjs().subtract(29, 'day').startOf('day').valueOf(), | 56 | dayjs().subtract(29, 'day').startOf('day').valueOf(), |
51 | dayjs().endOf('day').valueOf() | 57 | dayjs().endOf('day').valueOf() |
@@ -74,10 +80,15 @@ const getIntervalTimeOptions = computed(() => { | @@ -74,10 +80,15 @@ const getIntervalTimeOptions = computed(() => { | ||
74 | return getRangeOptions(diff) | 80 | return getRangeOptions(diff) |
75 | }) | 81 | }) |
76 | 82 | ||
83 | +const handleTimeRangeBlur = () => { | ||
84 | + //从面板里面选择 | ||
85 | + shortcutsSelect.value = false | ||
86 | +} | ||
87 | + | ||
77 | const handleTimePerionChange = (value: number[]) => { | 88 | const handleTimePerionChange = (value: number[]) => { |
78 | const [startTs, endTs] = value || [] | 89 | const [startTs, endTs] = value || [] |
79 | - emit('update:value', {...props.value, startTs, endTs, interval: null}) | ||
80 | - emit('change', {...props.value || {}, startTs, endTs, interval: null}) | 90 | + emit('update:value', {...props.value, startTs, endTs, interval: null, shortcutsSelect: shortcutsSelect.value}) |
91 | + emit('change', {...props.value || {}, startTs, endTs, interval: null, shortcutsSelect: shortcutsSelect.value}) | ||
81 | } | 92 | } |
82 | 93 | ||
83 | const handleAggChange = (value: string) => { | 94 | const handleAggChange = (value: string) => { |
@@ -120,6 +131,7 @@ watch(() => props.value, (target) => { | @@ -120,6 +131,7 @@ watch(() => props.value, (target) => { | ||
120 | <NFormItem :show-label="false"> | 131 | <NFormItem :show-label="false"> |
121 | <NDatePicker :shortcuts="rangeShortcuts" v-model:value="timePeriod" type="datetimerange" | 132 | <NDatePicker :shortcuts="rangeShortcuts" v-model:value="timePeriod" type="datetimerange" |
122 | placeholder="请选择时间范围" | 133 | placeholder="请选择时间范围" |
134 | + @blur="handleTimeRangeBlur" | ||
123 | @update-value="handleTimePerionChange" clearable | 135 | @update-value="handleTimePerionChange" clearable |
124 | :default-time="['00:00:00', '23:59:59']"></NDatePicker> | 136 | :default-time="['00:00:00', '23:59:59']"></NDatePicker> |
125 | </NFormItem> | 137 | </NFormItem> |