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 | 38 | type: Object as PropType<RadioRecord>, |
| 39 | 39 | default: () => DEFAULT_RADIO_RECORD, |
| 40 | 40 | }, |
| 41 | + random: { | |
| 42 | + type: Boolean, | |
| 43 | + default: true, | |
| 44 | + }, | |
| 41 | 45 | }); |
| 42 | 46 | |
| 43 | 47 | const getControlsWidgetId = () => `widget-chart-${props.value.id}`; |
| ... | ... | @@ -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 | 100 | onMounted(() => { |
| 89 | 101 | initChart(); |
| 90 | 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 | 106 | onUnmounted(() => { |
| 94 | 107 | unref(chartRef)?.clear(); |
| 108 | + clearInterval(timeout as number); | |
| 109 | + timeout = null; | |
| 95 | 110 | }); |
| 96 | 111 | |
| 97 | 112 | defineExpose({ update }); | ... | ... |
| 1 | 1 | <script lang="ts" setup> |
| 2 | - import { computed, unref } from 'vue'; | |
| 2 | + import { computed, onMounted, onUnmounted, ref, unref } from 'vue'; | |
| 3 | 3 | import { Space, Tooltip } from 'ant-design-vue'; |
| 4 | 4 | import { |
| 5 | 5 | DigitalComponentDefaultConfig, |
| ... | ... | @@ -12,6 +12,7 @@ |
| 12 | 12 | RadioRecord, |
| 13 | 13 | DEFAULT_DATE_FORMAT, |
| 14 | 14 | DEFAULT_RADIO_RECORD, |
| 15 | + DEFAULT_ANIMATION_INTERVAL, | |
| 15 | 16 | } from '../../detail/config/util'; |
| 16 | 17 | import { isNaN } from 'lodash'; |
| 17 | 18 | |
| ... | ... | @@ -19,10 +20,13 @@ |
| 19 | 20 | layout: DigitalDashBoardLayout; |
| 20 | 21 | value: DigitalDashBoardValue; |
| 21 | 22 | radio?: RadioRecord; |
| 23 | + random?: boolean; | |
| 22 | 24 | }>(); |
| 23 | 25 | |
| 26 | + const changeValue = ref(0); | |
| 27 | + | |
| 24 | 28 | const getPropsValue = computed(() => { |
| 25 | - return { ...DigitalComponentDefaultConfig, ...props.value }; | |
| 29 | + return { value: unref(changeValue), ...DigitalComponentDefaultConfig, ...props.value }; | |
| 26 | 30 | }); |
| 27 | 31 | |
| 28 | 32 | const integerPart = computed(() => { |
| ... | ... | @@ -52,6 +56,23 @@ |
| 52 | 56 | const { radio } = props.radio || DEFAULT_RADIO_RECORD; |
| 53 | 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 | 76 | </script> |
| 56 | 77 | |
| 57 | 78 | <template> | ... | ... |
| ... | ... | @@ -6,6 +6,7 @@ import { |
| 6 | 6 | Instrument2DefaultConfig, |
| 7 | 7 | instrumentComponent1, |
| 8 | 8 | instrumentComponent2, |
| 9 | + InstrumentComponentType, | |
| 9 | 10 | } from './dashBoardComponent.config'; |
| 10 | 11 | import DashBoardComponent from './DashBoardComponent.vue'; |
| 11 | 12 | import DigitalDashBoard from './DigitalDashBoard.vue'; |
| ... | ... | @@ -13,6 +14,7 @@ import { buildUUID } from '/@/utils/uuid'; |
| 13 | 14 | |
| 14 | 15 | export interface DashboardComponentLayout { |
| 15 | 16 | chartOption: EChartsOption; |
| 17 | + componentType: InstrumentComponentType; | |
| 16 | 18 | } |
| 17 | 19 | |
| 18 | 20 | interface InstrumentComponentConfig { |
| ... | ... | @@ -25,13 +27,19 @@ interface InstrumentComponentConfig { |
| 25 | 27 | export const instrumentComponentConfig: InstrumentComponentConfig[] = [ |
| 26 | 28 | { |
| 27 | 29 | id: 'instrument-component-1', |
| 28 | - layout: { chartOption: instrumentComponent1(Instrument1DefaultConfig) }, | |
| 30 | + layout: { | |
| 31 | + chartOption: instrumentComponent1(Instrument1DefaultConfig), | |
| 32 | + componentType: 'instrument-component-1', | |
| 33 | + }, | |
| 29 | 34 | component: DashBoardComponent, |
| 30 | 35 | value: { id: buildUUID() }, |
| 31 | 36 | }, |
| 32 | 37 | { |
| 33 | 38 | id: 'instrument-component-2', |
| 34 | - layout: { chartOption: instrumentComponent2(Instrument2DefaultConfig) }, | |
| 39 | + layout: { | |
| 40 | + chartOption: instrumentComponent2(Instrument2DefaultConfig), | |
| 41 | + componentType: 'instrument-component-2', | |
| 42 | + }, | |
| 35 | 43 | component: DashBoardComponent, |
| 36 | 44 | value: { id: buildUUID() }, |
| 37 | 45 | }, | ... | ... |
| ... | ... | @@ -59,7 +59,12 @@ |
| 59 | 59 | :control-id="item.id" |
| 60 | 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 | 68 | </VisualWidgetSelect> |
| 64 | 69 | </List.Item> |
| 65 | 70 | </template> | ... | ... |