Commit dc1239e372b9571830c416d8199cfdfecefad35a
1 parent
40d8840e
fix(src/packages): 信息控件下的时间选择器新增面版内快捷选择
Showing
2 changed files
with
75 additions
and
58 deletions
@@ -13,7 +13,7 @@ export const option = { | @@ -13,7 +13,7 @@ export const option = { | ||
13 | // 下拉展示 | 13 | // 下拉展示 |
14 | isPanel: 0, | 14 | isPanel: 0, |
15 | // 默认值 | 15 | // 默认值 |
16 | - dataset: dayjs().valueOf() as number | number[] | null, | 16 | + dataset: [new Date().getTime() - 86400000,new Date().getTime()], |
17 | // 默认值类型 | 17 | // 默认值类型 |
18 | defaultType: DefaultTypeEnum.STATIC, | 18 | defaultType: DefaultTypeEnum.STATIC, |
19 | // 动态默认值偏移单位 | 19 | // 动态默认值偏移单位 |
@@ -5,20 +5,21 @@ | @@ -5,20 +5,21 @@ | ||
5 | :panel="!!chartConfig.option.isPanel" | 5 | :panel="!!chartConfig.option.isPanel" |
6 | :type="chartConfig.option.componentInteractEventKey" | 6 | :type="chartConfig.option.componentInteractEventKey" |
7 | :style="`width:${w}px;`" | 7 | :style="`width:${w}px;`" |
8 | - :to="false" | 8 | + :to="true" |
9 | @update:value="onChange" | 9 | @update:value="onChange" |
10 | + :shortcuts="rangeShortcuts" | ||
10 | /> | 11 | /> |
11 | </template> | 12 | </template> |
12 | 13 | ||
13 | <script setup lang="ts"> | 14 | <script setup lang="ts"> |
14 | -import { PropType, toRefs, shallowReactive, watch ,ref,computed} from 'vue' | ||
15 | -import dayjs, {ManipulateType} from 'dayjs' | 15 | +import { PropType, toRefs, shallowReactive, watch, ref, computed } from 'vue' |
16 | +import dayjs, { ManipulateType } from 'dayjs' | ||
16 | import { CreateComponentType } from '@/packages/index.d' | 17 | import { CreateComponentType } from '@/packages/index.d' |
17 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | 18 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
18 | import { useChartInteract } from '@/hooks/external/useChartDateInteract.hook' | 19 | import { useChartInteract } from '@/hooks/external/useChartDateInteract.hook' |
19 | import { InteractEventOn } from '@/enums/eventEnum' | 20 | import { InteractEventOn } from '@/enums/eventEnum' |
20 | -import {ComponentInteractEventEnum, ComponentInteractParamsEnum, DefaultTypeEnum} from './interact' | ||
21 | -import quarterOfYear from 'dayjs/plugin/quarterOfYear'; | 21 | +import { ComponentInteractEventEnum, ComponentInteractParamsEnum, DefaultTypeEnum } from './interact' |
22 | +import quarterOfYear from 'dayjs/plugin/quarterOfYear' | ||
22 | 23 | ||
23 | const props = defineProps({ | 24 | const props = defineProps({ |
24 | chartConfig: { | 25 | chartConfig: { |
@@ -28,8 +29,24 @@ const props = defineProps({ | @@ -28,8 +29,24 @@ const props = defineProps({ | ||
28 | }) | 29 | }) |
29 | 30 | ||
30 | const { w, h } = toRefs(props.chartConfig.attr) | 31 | const { w, h } = toRefs(props.chartConfig.attr) |
32 | + | ||
31 | const rangeDate = ref<number | number[]>() | 33 | const rangeDate = ref<number | number[]>() |
32 | 34 | ||
35 | +const rangeShortcuts = { | ||
36 | + 昨天: () => { | ||
37 | + const cur = new Date().getTime() | ||
38 | + return [cur - 86400000, cur] as const | ||
39 | + }, | ||
40 | + 最近7天: () => { | ||
41 | + const cur = new Date().getTime() | ||
42 | + return [cur - 604800000, cur] as const | ||
43 | + }, | ||
44 | + 最近30天: () => { | ||
45 | + const cur = new Date().getTime() | ||
46 | + return [cur - 2592000000, cur] as const | ||
47 | + } | ||
48 | +} | ||
49 | + | ||
33 | const option = shallowReactive({ | 50 | const option = shallowReactive({ |
34 | dataset: props.chartConfig.option.dataset | 51 | dataset: props.chartConfig.option.dataset |
35 | }) | 52 | }) |
@@ -38,36 +55,35 @@ const isRange = computed(() => { | @@ -38,36 +55,35 @@ const isRange = computed(() => { | ||
38 | return props.chartConfig.option.componentInteractEventKey.endsWith('range') | 55 | return props.chartConfig.option.componentInteractEventKey.endsWith('range') |
39 | }) | 56 | }) |
40 | 57 | ||
41 | - | ||
42 | // 监听事件改变 | 58 | // 监听事件改变 |
43 | const onChange = (v: number | number[] | null) => { | 59 | const onChange = (v: number | number[] | null) => { |
44 | if (isRange.value) { | 60 | if (isRange.value) { |
45 | let dateStart = null | 61 | let dateStart = null |
46 | let dateEnd = null | 62 | let dateEnd = null |
47 | let daterange = null | 63 | let daterange = null |
48 | - if(v instanceof Array){ | 64 | + if (v instanceof Array) { |
49 | dateStart = v[0] | 65 | dateStart = v[0] |
50 | dateEnd = v[1] | 66 | dateEnd = v[1] |
51 | daterange = `${v[0]}-${v[1]}` | 67 | daterange = `${v[0]}-${v[1]}` |
52 | } | 68 | } |
53 | // 存储到联动数据 | 69 | // 存储到联动数据 |
54 | useChartInteract( | 70 | useChartInteract( |
55 | - props.chartConfig, | ||
56 | - useChartEditStore, | ||
57 | - { | ||
58 | - [ComponentInteractParamsEnum.DATE_START]: dateStart, | ||
59 | - [ComponentInteractParamsEnum.DATE_END]: dateEnd, | ||
60 | - [ComponentInteractParamsEnum.DATE_RANGE]: daterange | ||
61 | - }, | ||
62 | - InteractEventOn.CHANGE | 71 | + props.chartConfig, |
72 | + useChartEditStore, | ||
73 | + { | ||
74 | + [ComponentInteractParamsEnum.DATE_START]: dateStart, | ||
75 | + [ComponentInteractParamsEnum.DATE_END]: dateEnd, | ||
76 | + [ComponentInteractParamsEnum.DATE_RANGE]: daterange | ||
77 | + }, | ||
78 | + InteractEventOn.CHANGE | ||
63 | ) | 79 | ) |
64 | } else { | 80 | } else { |
65 | // 存储到联动数据 | 81 | // 存储到联动数据 |
66 | useChartInteract( | 82 | useChartInteract( |
67 | - props.chartConfig, | ||
68 | - useChartEditStore, | ||
69 | - { [ComponentInteractParamsEnum.DATE]: v }, | ||
70 | - InteractEventOn.CHANGE | 83 | + props.chartConfig, |
84 | + useChartEditStore, | ||
85 | + { [ComponentInteractParamsEnum.DATE]: v }, | ||
86 | + InteractEventOn.CHANGE | ||
71 | ) | 87 | ) |
72 | } | 88 | } |
73 | } | 89 | } |
@@ -87,7 +103,7 @@ const getDiffDate = (type: ComponentInteractEventEnum, date: dayjs.Dayjs) => { | @@ -87,7 +103,7 @@ const getDiffDate = (type: ComponentInteractEventEnum, date: dayjs.Dayjs) => { | ||
87 | case ComponentInteractEventEnum.YEAR: | 103 | case ComponentInteractEventEnum.YEAR: |
88 | case ComponentInteractEventEnum.YEAR_RANGE: | 104 | case ComponentInteractEventEnum.YEAR_RANGE: |
89 | date = date.startOf('year') | 105 | date = date.startOf('year') |
90 | - break | 106 | + break |
91 | case ComponentInteractEventEnum.QUARTER: | 107 | case ComponentInteractEventEnum.QUARTER: |
92 | case ComponentInteractEventEnum.QUARTER_RANGE: | 108 | case ComponentInteractEventEnum.QUARTER_RANGE: |
93 | date = date.startOf('quarter') | 109 | date = date.startOf('quarter') |
@@ -99,48 +115,50 @@ const getDiffDate = (type: ComponentInteractEventEnum, date: dayjs.Dayjs) => { | @@ -99,48 +115,50 @@ const getDiffDate = (type: ComponentInteractEventEnum, date: dayjs.Dayjs) => { | ||
99 | } | 115 | } |
100 | 116 | ||
101 | watch( | 117 | watch( |
102 | - () => { | ||
103 | - return { | ||
104 | - type: props.chartConfig.option.componentInteractEventKey as ComponentInteractEventEnum, | ||
105 | - defaultType: props.chartConfig.option.defaultType as string, | ||
106 | - differValue: props.chartConfig.option.differValue as number[], | ||
107 | - differUnit: props.chartConfig.option.differUnit as ManipulateType[], | ||
108 | - dataset: props.chartConfig.option.dataset as number | number[] | null, | ||
109 | - }; | ||
110 | - }, | ||
111 | - (newData, oldData) => { | ||
112 | - const hasTypeChanged = newData.type !== oldData?.type; | ||
113 | - const hasDefaultTypeChanged = newData.defaultType !== oldData?.defaultType; | ||
114 | - const hasDifferValueChanged = newData.differValue !== oldData?.differValue; | ||
115 | - const hasDifferUnitChanged = newData.differUnit !== oldData?.differUnit; | 118 | + () => { |
119 | + return { | ||
120 | + type: props.chartConfig.option.componentInteractEventKey as ComponentInteractEventEnum, | ||
121 | + defaultType: props.chartConfig.option.defaultType as string, | ||
122 | + differValue: props.chartConfig.option.differValue as number[], | ||
123 | + differUnit: props.chartConfig.option.differUnit as ManipulateType[], | ||
124 | + dataset: props.chartConfig.option.dataset as number | number[] | null | ||
125 | + } | ||
126 | + }, | ||
127 | + (newData, oldData) => { | ||
128 | + const hasTypeChanged = newData.type !== oldData?.type | ||
129 | + const hasDefaultTypeChanged = newData.defaultType !== oldData?.defaultType | ||
130 | + const hasDifferValueChanged = newData.differValue !== oldData?.differValue | ||
131 | + const hasDifferUnitChanged = newData.differUnit !== oldData?.differUnit | ||
116 | 132 | ||
117 | - if (hasTypeChanged || hasDefaultTypeChanged || hasDifferValueChanged || hasDifferUnitChanged) { | ||
118 | - if (newData.defaultType === DefaultTypeEnum.NONE) { | ||
119 | - props.chartConfig.option.dataset = null; | ||
120 | - } else if (newData.defaultType === DefaultTypeEnum.DYNAMIC) { | ||
121 | - let date = dayjs(); | ||
122 | - if (isRange.value) { | ||
123 | - props.chartConfig.option.dataset = [ | ||
124 | - getDiffDate(newData.type,date.add(newData.differValue[0], newData.differUnit[0])).valueOf(), | ||
125 | - getDiffDate(newData.type,date.add(newData.differValue[1], newData.differUnit[1])).valueOf(), | ||
126 | - ]; | ||
127 | - } else { | ||
128 | - props.chartConfig.option.dataset = getDiffDate(newData.type,date.add(newData.differValue[0], newData.differUnit[0])).valueOf() | ||
129 | - } | 133 | + if (hasTypeChanged || hasDefaultTypeChanged || hasDifferValueChanged || hasDifferUnitChanged) { |
134 | + if (newData.defaultType === DefaultTypeEnum.NONE) { | ||
135 | + props.chartConfig.option.dataset = null | ||
136 | + } else if (newData.defaultType === DefaultTypeEnum.DYNAMIC) { | ||
137 | + let date = dayjs() | ||
138 | + if (isRange.value) { | ||
139 | + props.chartConfig.option.dataset = [ | ||
140 | + getDiffDate(newData.type, date.add(newData.differValue[0], newData.differUnit[0])).valueOf(), | ||
141 | + getDiffDate(newData.type, date.add(newData.differValue[1], newData.differUnit[1])).valueOf() | ||
142 | + ] | ||
143 | + } else { | ||
144 | + props.chartConfig.option.dataset = getDiffDate( | ||
145 | + newData.type, | ||
146 | + date.add(newData.differValue[0], newData.differUnit[0]) | ||
147 | + ).valueOf() | ||
130 | } | 148 | } |
131 | } | 149 | } |
132 | - option.dataset = props.chartConfig.option.dataset; | ||
133 | - onChange(option.dataset); | ||
134 | - }, | ||
135 | - { | ||
136 | - immediate: true, | ||
137 | } | 150 | } |
138 | -); | ||
139 | - | 151 | + option.dataset = props.chartConfig.option.dataset |
152 | + onChange(option.dataset) | ||
153 | + }, | ||
154 | + { | ||
155 | + immediate: true | ||
156 | + } | ||
157 | +) | ||
140 | 158 | ||
141 | watch( | 159 | watch( |
142 | () => props.chartConfig.option.shortcut, | 160 | () => props.chartConfig.option.shortcut, |
143 | - (newData) => { | 161 | + newData => { |
144 | if (!newData) return | 162 | if (!newData) return |
145 | const startTs = Date.now() - newData | 163 | const startTs = Date.now() - newData |
146 | const endTs = Date.now() | 164 | const endTs = Date.now() |
@@ -153,7 +171,6 @@ watch( | @@ -153,7 +171,6 @@ watch( | ||
153 | ) | 171 | ) |
154 | </script> | 172 | </script> |
155 | 173 | ||
156 | - | ||
157 | <style lang="scss" scoped> | 174 | <style lang="scss" scoped> |
158 | @include deep() { | 175 | @include deep() { |
159 | .n-input { | 176 | .n-input { |
@@ -162,4 +179,4 @@ watch( | @@ -162,4 +179,4 @@ watch( | ||
162 | align-items: center; | 179 | align-items: center; |
163 | } | 180 | } |
164 | } | 181 | } |
165 | -</style> | ||
182 | +</style> |