Commit 249ce62578cc67f8b44808fa0edddd0ef3fa481c
1 parent
70ce47e7
fix: DEFECT-683 component add random value change animation
Showing
6 changed files
with
57 additions
and
5 deletions
@@ -38,6 +38,10 @@ | @@ -38,6 +38,10 @@ | ||
38 | type: Object as PropType<RadioRecord>, | 38 | type: Object as PropType<RadioRecord>, |
39 | default: () => DEFAULT_RADIO_RECORD, | 39 | default: () => DEFAULT_RADIO_RECORD, |
40 | }, | 40 | }, |
41 | + random: { | ||
42 | + type: Boolean, | ||
43 | + default: true, | ||
44 | + }, | ||
41 | }); | 45 | }); |
42 | 46 | ||
43 | const getControlsWidgetId = () => `widget-chart-${props.value.id}`; | 47 | const getControlsWidgetId = () => `widget-chart-${props.value.id}`; |
@@ -85,13 +89,24 @@ | @@ -85,13 +89,24 @@ | ||
85 | } | 89 | } |
86 | ); | 90 | ); |
87 | 91 | ||
92 | + let timeout: Nullable<number> = null; | ||
93 | + | ||
94 | + function handleRandomValue() { | ||
95 | + const newValue = Math.floor(Math.random() * 100); | ||
96 | + const updateFn = getUpdateValueFn(props.layout.componentType); | ||
97 | + unref(chartRef)?.setOption((updateFn(newValue) as unknown as EChartsOption) || {}); | ||
98 | + } | ||
99 | + | ||
88 | onMounted(() => { | 100 | onMounted(() => { |
89 | initChart(); | 101 | initChart(); |
90 | props.add && props.add(props.value.id, update); | 102 | props.add && props.add(props.value.id, update); |
103 | + if (props.random) timeout = setInterval(handleRandomValue, 2000) as unknown as number; | ||
91 | }); | 104 | }); |
92 | 105 | ||
93 | onUnmounted(() => { | 106 | onUnmounted(() => { |
94 | unref(chartRef)?.clear(); | 107 | unref(chartRef)?.clear(); |
108 | + clearInterval(timeout as number); | ||
109 | + timeout = null; | ||
95 | }); | 110 | }); |
96 | 111 | ||
97 | defineExpose({ update }); | 112 | defineExpose({ update }); |
1 | <script lang="ts" setup> | 1 | <script lang="ts" setup> |
2 | - import { computed, unref } from 'vue'; | 2 | + import { computed, onMounted, onUnmounted, ref, unref } from 'vue'; |
3 | import { Space, Tooltip } from 'ant-design-vue'; | 3 | import { Space, Tooltip } from 'ant-design-vue'; |
4 | import { | 4 | import { |
5 | DigitalComponentDefaultConfig, | 5 | DigitalComponentDefaultConfig, |
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | RadioRecord, | 12 | RadioRecord, |
13 | DEFAULT_DATE_FORMAT, | 13 | DEFAULT_DATE_FORMAT, |
14 | DEFAULT_RADIO_RECORD, | 14 | DEFAULT_RADIO_RECORD, |
15 | + DEFAULT_ANIMATION_INTERVAL, | ||
15 | } from '../../detail/config/util'; | 16 | } from '../../detail/config/util'; |
16 | import { isNaN } from 'lodash'; | 17 | import { isNaN } from 'lodash'; |
17 | 18 | ||
@@ -19,10 +20,13 @@ | @@ -19,10 +20,13 @@ | ||
19 | layout: DigitalDashBoardLayout; | 20 | layout: DigitalDashBoardLayout; |
20 | value: DigitalDashBoardValue; | 21 | value: DigitalDashBoardValue; |
21 | radio?: RadioRecord; | 22 | radio?: RadioRecord; |
23 | + random?: boolean; | ||
22 | }>(); | 24 | }>(); |
23 | 25 | ||
26 | + const changeValue = ref(0); | ||
27 | + | ||
24 | const getPropsValue = computed(() => { | 28 | const getPropsValue = computed(() => { |
25 | - return { ...DigitalComponentDefaultConfig, ...props.value }; | 29 | + return { value: unref(changeValue), ...DigitalComponentDefaultConfig, ...props.value }; |
26 | }); | 30 | }); |
27 | 31 | ||
28 | const integerPart = computed(() => { | 32 | const integerPart = computed(() => { |
@@ -52,6 +56,23 @@ | @@ -52,6 +56,23 @@ | ||
52 | const { radio } = props.radio || DEFAULT_RADIO_RECORD; | 56 | const { radio } = props.radio || DEFAULT_RADIO_RECORD; |
53 | return radio; | 57 | return radio; |
54 | }); | 58 | }); |
59 | + | ||
60 | + let timeout: Nullable<number> = null; | ||
61 | + | ||
62 | + const handleRandom = () => { | ||
63 | + const newValue = Math.floor(Math.random() * 100); | ||
64 | + changeValue.value = newValue; | ||
65 | + }; | ||
66 | + | ||
67 | + onMounted(() => { | ||
68 | + if (props.random) | ||
69 | + timeout = setInterval(handleRandom, DEFAULT_ANIMATION_INTERVAL) as unknown as number; | ||
70 | + }); | ||
71 | + | ||
72 | + onUnmounted(() => { | ||
73 | + clearInterval(timeout as number); | ||
74 | + timeout = null; | ||
75 | + }); | ||
55 | </script> | 76 | </script> |
56 | 77 | ||
57 | <template> | 78 | <template> |
@@ -6,6 +6,7 @@ import { | @@ -6,6 +6,7 @@ import { | ||
6 | Instrument2DefaultConfig, | 6 | Instrument2DefaultConfig, |
7 | instrumentComponent1, | 7 | instrumentComponent1, |
8 | instrumentComponent2, | 8 | instrumentComponent2, |
9 | + InstrumentComponentType, | ||
9 | } from './dashBoardComponent.config'; | 10 | } from './dashBoardComponent.config'; |
10 | import DashBoardComponent from './DashBoardComponent.vue'; | 11 | import DashBoardComponent from './DashBoardComponent.vue'; |
11 | import DigitalDashBoard from './DigitalDashBoard.vue'; | 12 | import DigitalDashBoard from './DigitalDashBoard.vue'; |
@@ -13,6 +14,7 @@ import { buildUUID } from '/@/utils/uuid'; | @@ -13,6 +14,7 @@ import { buildUUID } from '/@/utils/uuid'; | ||
13 | 14 | ||
14 | export interface DashboardComponentLayout { | 15 | export interface DashboardComponentLayout { |
15 | chartOption: EChartsOption; | 16 | chartOption: EChartsOption; |
17 | + componentType: InstrumentComponentType; | ||
16 | } | 18 | } |
17 | 19 | ||
18 | interface InstrumentComponentConfig { | 20 | interface InstrumentComponentConfig { |
@@ -25,13 +27,19 @@ interface InstrumentComponentConfig { | @@ -25,13 +27,19 @@ interface InstrumentComponentConfig { | ||
25 | export const instrumentComponentConfig: InstrumentComponentConfig[] = [ | 27 | export const instrumentComponentConfig: InstrumentComponentConfig[] = [ |
26 | { | 28 | { |
27 | id: 'instrument-component-1', | 29 | id: 'instrument-component-1', |
28 | - layout: { chartOption: instrumentComponent1(Instrument1DefaultConfig) }, | 30 | + layout: { |
31 | + chartOption: instrumentComponent1(Instrument1DefaultConfig), | ||
32 | + componentType: 'instrument-component-1', | ||
33 | + }, | ||
29 | component: DashBoardComponent, | 34 | component: DashBoardComponent, |
30 | value: { id: buildUUID() }, | 35 | value: { id: buildUUID() }, |
31 | }, | 36 | }, |
32 | { | 37 | { |
33 | id: 'instrument-component-2', | 38 | id: 'instrument-component-2', |
34 | - layout: { chartOption: instrumentComponent2(Instrument2DefaultConfig) }, | 39 | + layout: { |
40 | + chartOption: instrumentComponent2(Instrument2DefaultConfig), | ||
41 | + componentType: 'instrument-component-2', | ||
42 | + }, | ||
35 | component: DashBoardComponent, | 43 | component: DashBoardComponent, |
36 | value: { id: buildUUID() }, | 44 | value: { id: buildUUID() }, |
37 | }, | 45 | }, |
@@ -59,7 +59,12 @@ | @@ -59,7 +59,12 @@ | ||
59 | :control-id="item.id" | 59 | :control-id="item.id" |
60 | @change="handleCheck" | 60 | @change="handleCheck" |
61 | > | 61 | > |
62 | - <component :is="item.component" :layout="item.layout" :value="item.value" /> | 62 | + <component |
63 | + :is="item.component" | ||
64 | + :random="true" | ||
65 | + :layout="item.layout" | ||
66 | + :value="item.value" | ||
67 | + /> | ||
63 | </VisualWidgetSelect> | 68 | </VisualWidgetSelect> |
64 | </List.Item> | 69 | </List.Item> |
65 | </template> | 70 | </template> |
@@ -5,6 +5,8 @@ export interface RadioRecord { | @@ -5,6 +5,8 @@ export interface RadioRecord { | ||
5 | radio: number; | 5 | radio: number; |
6 | } | 6 | } |
7 | 7 | ||
8 | +export const DEFAULT_ANIMATION_INTERVAL = 2000; | ||
9 | + | ||
8 | export const DEFAULT_RADIO_RECORD: RadioRecord = { | 10 | export const DEFAULT_RADIO_RECORD: RadioRecord = { |
9 | width: 300, | 11 | width: 300, |
10 | height: 300, | 12 | height: 300, |
@@ -383,6 +383,7 @@ | @@ -383,6 +383,7 @@ | ||
383 | :update="update" | 383 | :update="update" |
384 | :radio="record.radio || {}" | 384 | :radio="record.radio || {}" |
385 | v-bind="getComponentConfig(item.record, record)" | 385 | v-bind="getComponentConfig(item.record, record)" |
386 | + :random="false" | ||
386 | /> | 387 | /> |
387 | </template> | 388 | </template> |
388 | </WidgetWrapper> | 389 | </WidgetWrapper> |