Commit 5004159d6303f6ecad6eae17bd16bce22acb3286
Committed by
xp.Huang
1 parent
386a679d
perf(src/views/share): 优化日期控件,添加快捷选项,动态更新时间
Showing
3 changed files
with
35 additions
and
6 deletions
| ... | ... | @@ -9,6 +9,8 @@ import { useChartDataSocket } from './useChartDataSocket' |
| 9 | 9 | import { customRequest } from '@/api/external/customRequest' |
| 10 | 10 | import { useFilterFn } from './useFilterFn' |
| 11 | 11 | import { RequestContentTypeEnum } from '@/enums/external/httpEnum' |
| 12 | +import dayjs from 'dayjs' | |
| 13 | + | |
| 12 | 14 | |
| 13 | 15 | // 获取类型 |
| 14 | 16 | type ChartEditStoreType = typeof useChartEditStore |
| ... | ... | @@ -67,6 +69,18 @@ export const useChartDataFetch = ( |
| 67 | 69 | clearInterval(fetchInterval) |
| 68 | 70 | |
| 69 | 71 | const fetchFn = async () => { |
| 72 | + let startTsValue = null | |
| 73 | + let endTsValue = null | |
| 74 | + const { requestParams } = toRaw(targetComponent.request) | |
| 75 | + const { Params } = requestParams | |
| 76 | + const { entityType, startTs, endTs } = Params | |
| 77 | + const days = Math.ceil((endTs - startTs) / (1 * 60 * 60 * 24 * 1000)) | |
| 78 | + if (entityType === 'DEVICE') { | |
| 79 | + startTsValue = Date.now() - days <= 32 ? 2592000000: days <= 8 ? 604800000 : startTs | |
| 80 | + endTsValue = Date.now() | |
| 81 | + toRaw(targetComponent.request).requestParams.Params.startTs = startTsValue | |
| 82 | + toRaw(targetComponent.request).requestParams.Params.endTs = endTsValue | |
| 83 | + } | |
| 70 | 84 | const res = await customRequest(toRaw(targetComponent.request)) |
| 71 | 85 | if (res) { |
| 72 | 86 | try { |
| ... | ... | @@ -106,9 +120,9 @@ export const useChartDataFetch = ( |
| 106 | 120 | } catch (error) { |
| 107 | 121 | console.log(error) |
| 108 | 122 | } |
| 109 | - } | |
| 123 | + } | |
| 110 | 124 | |
| 111 | - if (isPreview()) { | |
| 125 | + if (isPreview()) { | |
| 112 | 126 | requestIntervalFn() |
| 113 | 127 | const chartEditStore = useChartEditStore() |
| 114 | 128 | const { initial } = useChartDataSocket() |
| ... | ... | @@ -116,9 +130,9 @@ export const useChartDataFetch = ( |
| 116 | 130 | * 支持分组也可以接受ws |
| 117 | 131 | * 如果是分组并且绑定了ws |
| 118 | 132 | */ |
| 119 | - chartEditStore.getComponentList?.forEach((item:CreateComponentType | CreateComponentGroupType)=>{ | |
| 120 | - if(item.isGroup){ | |
| 121 | - if(item.request.requestUrl?.includes('ws')){ | |
| 133 | + chartEditStore.getComponentList?.forEach((item: CreateComponentType | CreateComponentGroupType) => { | |
| 134 | + if (item.isGroup) { | |
| 135 | + if (item.request.requestUrl?.includes('ws')) { | |
| 122 | 136 | initial(item, useChartEditStore, updateCallback) |
| 123 | 137 | } |
| 124 | 138 | } | ... | ... |
| ... | ... | @@ -240,6 +240,7 @@ const defaultTypeUpdate = (v: string) => { |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | const shortCutSelect = (value: number) => { |
| 243 | + console.log(value) | |
| 243 | 244 | startTs.value = Date.now() - value |
| 244 | 245 | endTs.value = Date.now() |
| 245 | 246 | props.optionData.dataset = [startTs.value, endTs.value] as any | ... | ... |
| ... | ... | @@ -31,6 +31,20 @@ const timePeriod = ref<Nullable<[number, number]>>(null) |
| 31 | 31 | const agg = ref() |
| 32 | 32 | const interval = ref() |
| 33 | 33 | const limit = ref(7) |
| 34 | +const rangeShortcuts = { | |
| 35 | + 昨天: () => { | |
| 36 | + const cur = new Date().getTime() | |
| 37 | + return [cur - 86400000, cur] as const | |
| 38 | + }, | |
| 39 | + 最近7天: () => { | |
| 40 | + const cur = new Date().getTime() | |
| 41 | + return [cur - 604800000, cur] as const | |
| 42 | + }, | |
| 43 | + 最近30天: () => { | |
| 44 | + const cur = new Date().getTime() | |
| 45 | + return [cur - 2592000000, cur] as const | |
| 46 | + } | |
| 47 | +} | |
| 34 | 48 | |
| 35 | 49 | const getRangeOptions = (number: number) => { |
| 36 | 50 | for (let i = 0; i < defaultIntervalOptions.length; i++) { |
| ... | ... | @@ -97,7 +111,7 @@ watch(() => props.value, (target) => { |
| 97 | 111 | <NGrid :cols="24"> |
| 98 | 112 | <NGi :span="16"> |
| 99 | 113 | <NFormItem :show-label="false"> |
| 100 | - <NDatePicker v-model:value="timePeriod" type="datetimerange" placeholder="请选择时间范围" | |
| 114 | + <NDatePicker :shortcuts="rangeShortcuts" v-model:value="timePeriod" type="datetimerange" placeholder="请选择时间范围" | |
| 101 | 115 | @update-value="handleTimePerionChange" clearable :default-time="['00:00:00', '23:59:59']"></NDatePicker> |
| 102 | 116 | </NFormItem> |
| 103 | 117 | </NGi> | ... | ... |