Showing
5 changed files
with
48 additions
and
5 deletions
1 | 1 | <script lang="ts" setup> |
2 | 2 | import type { ECharts, EChartsOption } from 'echarts'; |
3 | - import { PropType } from 'vue'; | |
3 | + import { PropType, watch } from 'vue'; | |
4 | 4 | import { nextTick, onMounted, onUnmounted, ref, unref, computed } from 'vue'; |
5 | 5 | import { init } from 'echarts'; |
6 | 6 | import { |
... | ... | @@ -10,6 +10,8 @@ |
10 | 10 | InstrumentComponentType, |
11 | 11 | update_instrument_1_font, |
12 | 12 | update_instrument_2_font, |
13 | + update_instrument_1_value, | |
14 | + update_instrument_2_value, | |
13 | 15 | } from './dashBoardComponent.config'; |
14 | 16 | import { dateUtil } from '/@/utils/dateUtil'; |
15 | 17 | import { |
... | ... | @@ -69,6 +71,20 @@ |
69 | 71 | unref(chartRef)?.resize(); |
70 | 72 | } |
71 | 73 | |
74 | + const getUpdateValueFn = (componentType: InstrumentComponentType) => { | |
75 | + if (componentType === 'instrument-component-1') return update_instrument_1_value; | |
76 | + if (componentType === 'instrument-component-2') return update_instrument_2_value; | |
77 | + return (_radio: number) => {}; | |
78 | + }; | |
79 | + | |
80 | + watch( | |
81 | + () => props.value.value, | |
82 | + (newValue) => { | |
83 | + const updateFn = getUpdateValueFn(props.layout.componentType); | |
84 | + unref(chartRef)?.setOption((updateFn(newValue || 0) as unknown as EChartsOption) || {}); | |
85 | + } | |
86 | + ); | |
87 | + | |
72 | 88 | onMounted(() => { |
73 | 89 | initChart(); |
74 | 90 | props.add && props.add(props.value.id, update); | ... | ... |
... | ... | @@ -262,6 +262,29 @@ export const update_instrument_2_font = (radio: number) => { |
262 | 262 | } as EChartsOption; |
263 | 263 | }; |
264 | 264 | |
265 | +export const update_instrument_1_value = (value) => { | |
266 | + return { | |
267 | + series: [ | |
268 | + { | |
269 | + data: [{ value }], | |
270 | + }, | |
271 | + { | |
272 | + data: [{ value }], | |
273 | + }, | |
274 | + ], | |
275 | + } as EChartsOption; | |
276 | +}; | |
277 | + | |
278 | +export const update_instrument_2_value = (value) => { | |
279 | + return { | |
280 | + series: [ | |
281 | + { | |
282 | + data: [{ value }], | |
283 | + }, | |
284 | + ], | |
285 | + } as EChartsOption; | |
286 | +}; | |
287 | + | |
265 | 288 | function setGradientInfo(dataSource: DataSource) { |
266 | 289 | const componentInfo = dataSource.componentInfo; |
267 | 290 | return instrumentComponent2({ | ... | ... |
... | ... | @@ -16,6 +16,7 @@ export interface TextComponentValue { |
16 | 16 | updateTime?: string; |
17 | 17 | fontColor?: string; |
18 | 18 | iconColor?: string; |
19 | + deviceName?: string; | |
19 | 20 | } |
20 | 21 | |
21 | 22 | export type TextComponentType = |
... | ... | @@ -88,6 +89,7 @@ export const transformTextComponentConfig = ( |
88 | 89 | } as TextComponentLayout, |
89 | 90 | value: { |
90 | 91 | name: dataSourceRecord.attributeRename || dataSourceRecord.attribute, |
92 | + deviceName: dataSourceRecord.deviceRename || dataSourceRecord.deviceId, | |
91 | 93 | value: dataSourceRecord.componentInfo.value, |
92 | 94 | icon: dataSourceRecord.componentInfo.icon, |
93 | 95 | unit: dataSourceRecord.componentInfo.unit, | ... | ... |
... | ... | @@ -72,8 +72,9 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { |
72 | 72 | waitSendQueue.length = 0; |
73 | 73 | } |
74 | 74 | }, |
75 | - onMessage(ws, message) { | |
75 | + onMessage(_ws, message) { | |
76 | 76 | try { |
77 | + // console.log({ dataSource: unref(dataSourceRef), cmdIdMapping }); | |
77 | 78 | const res: ResponseMessage = JSON.parse(message.data); |
78 | 79 | const { subscriptionId, data = {} } = res; |
79 | 80 | const mappingRecord = cmdIdMapping.get(subscriptionId); |
... | ... | @@ -98,12 +99,13 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { |
98 | 99 | |
99 | 100 | const transformSocketMessageItem = () => { |
100 | 101 | const messageList: SocketMessageItem[] = []; |
101 | - console.log(dataSourceRef); | |
102 | + let index = 0; | |
102 | 103 | unref(dataSourceRef).forEach((record, recordIndex) => { |
103 | 104 | const componentId = record.record.id; |
104 | 105 | record.record.dataSource.forEach((dataSource, dataSourceIndex) => { |
105 | 106 | const { deviceId, attribute } = dataSource; |
106 | - const cmdId = recordIndex * dataSourceIndex + recordIndex; | |
107 | + const cmdId = index; | |
108 | + index++; | |
107 | 109 | setCmdId(cmdId, { |
108 | 110 | componentId, |
109 | 111 | deviceId, | ... | ... |