Commit dc1239e372b9571830c416d8199cfdfecefad35a

Authored by fengwotao
1 parent 40d8840e

fix(src/packages): 信息控件下的时间选择器新增面版内快捷选择

... ... @@ -13,7 +13,7 @@ export const option = {
13 13 // 下拉展示
14 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 18 defaultType: DefaultTypeEnum.STATIC,
19 19 // 动态默认值偏移单位
... ...
... ... @@ -5,20 +5,21 @@
5 5 :panel="!!chartConfig.option.isPanel"
6 6 :type="chartConfig.option.componentInteractEventKey"
7 7 :style="`width:${w}px;`"
8   - :to="false"
  8 + :to="true"
9 9 @update:value="onChange"
  10 + :shortcuts="rangeShortcuts"
10 11 />
11 12 </template>
12 13
13 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 17 import { CreateComponentType } from '@/packages/index.d'
17 18 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
18 19 import { useChartInteract } from '@/hooks/external/useChartDateInteract.hook'
19 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 24 const props = defineProps({
24 25 chartConfig: {
... ... @@ -28,8 +29,24 @@ const props = defineProps({
28 29 })
29 30
30 31 const { w, h } = toRefs(props.chartConfig.attr)
  32 +
31 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 50 const option = shallowReactive({
34 51 dataset: props.chartConfig.option.dataset
35 52 })
... ... @@ -38,36 +55,35 @@ const isRange = computed(() => {
38 55 return props.chartConfig.option.componentInteractEventKey.endsWith('range')
39 56 })
40 57
41   -
42 58 // 监听事件改变
43 59 const onChange = (v: number | number[] | null) => {
44 60 if (isRange.value) {
45 61 let dateStart = null
46 62 let dateEnd = null
47 63 let daterange = null
48   - if(v instanceof Array){
  64 + if (v instanceof Array) {
49 65 dateStart = v[0]
50 66 dateEnd = v[1]
51 67 daterange = `${v[0]}-${v[1]}`
52 68 }
53 69 // 存储到联动数据
54 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 80 } else {
65 81 // 存储到联动数据
66 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 103 case ComponentInteractEventEnum.YEAR:
88 104 case ComponentInteractEventEnum.YEAR_RANGE:
89 105 date = date.startOf('year')
90   - break
  106 + break
91 107 case ComponentInteractEventEnum.QUARTER:
92 108 case ComponentInteractEventEnum.QUARTER_RANGE:
93 109 date = date.startOf('quarter')
... ... @@ -99,48 +115,50 @@ const getDiffDate = (type: ComponentInteractEventEnum, date: dayjs.Dayjs) => {
99 115 }
100 116
101 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 159 watch(
142 160 () => props.chartConfig.option.shortcut,
143   - (newData) => {
  161 + newData => {
144 162 if (!newData) return
145 163 const startTs = Date.now() - newData
146 164 const endTs = Date.now()
... ... @@ -153,7 +171,6 @@ watch(
153 171 )
154 172 </script>
155 173
156   -
157 174 <style lang="scss" scoped>
158 175 @include deep() {
159 176 .n-input {
... ... @@ -162,4 +179,4 @@ watch(
162 179 align-items: center;
163 180 }
164 181 }
165   -</style>
\ No newline at end of file
  182 +</style>
... ...