Commit 8c8d92d4a5b5b5b3ee28763cef4e6a3ac8492ac7

Authored by ww
1 parent 7cdf8ee0

feat: basic charts update

1 <script lang="ts" setup> 1 <script lang="ts" setup>
2 import type { ECharts, EChartsOption } from 'echarts'; 2 import type { ECharts, EChartsOption } from 'echarts';
3 - import { PropType } from 'vue'; 3 + import { PropType, watch } from 'vue';
4 import { nextTick, onMounted, onUnmounted, ref, unref, computed } from 'vue'; 4 import { nextTick, onMounted, onUnmounted, ref, unref, computed } from 'vue';
5 import { init } from 'echarts'; 5 import { init } from 'echarts';
6 import { 6 import {
@@ -10,6 +10,8 @@ @@ -10,6 +10,8 @@
10 InstrumentComponentType, 10 InstrumentComponentType,
11 update_instrument_1_font, 11 update_instrument_1_font,
12 update_instrument_2_font, 12 update_instrument_2_font,
  13 + update_instrument_1_value,
  14 + update_instrument_2_value,
13 } from './dashBoardComponent.config'; 15 } from './dashBoardComponent.config';
14 import { dateUtil } from '/@/utils/dateUtil'; 16 import { dateUtil } from '/@/utils/dateUtil';
15 import { 17 import {
@@ -69,6 +71,20 @@ @@ -69,6 +71,20 @@
69 unref(chartRef)?.resize(); 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 onMounted(() => { 88 onMounted(() => {
73 initChart(); 89 initChart();
74 props.add && props.add(props.value.id, update); 90 props.add && props.add(props.value.id, update);
@@ -262,6 +262,29 @@ export const update_instrument_2_font = (radio: number) => { @@ -262,6 +262,29 @@ export const update_instrument_2_font = (radio: number) => {
262 } as EChartsOption; 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 function setGradientInfo(dataSource: DataSource) { 288 function setGradientInfo(dataSource: DataSource) {
266 const componentInfo = dataSource.componentInfo; 289 const componentInfo = dataSource.componentInfo;
267 return instrumentComponent2({ 290 return instrumentComponent2({
@@ -77,7 +77,7 @@ @@ -77,7 +77,7 @@
77 </div> 77 </div>
78 <div class="w-1/2 flex justify-center"> 78 <div class="w-1/2 flex justify-center">
79 <Statistic 79 <Statistic
80 - :value="props.value.value || '123'" 80 + :value="props.value.value || 0"
81 :suffix="getShowUnit ? props.value.unit : ''" 81 :suffix="getShowUnit ? props.value.unit : ''"
82 class="truncate" 82 class="truncate"
83 :value-style="{ 83 :value-style="{
@@ -16,6 +16,7 @@ export interface TextComponentValue { @@ -16,6 +16,7 @@ export interface TextComponentValue {
16 updateTime?: string; 16 updateTime?: string;
17 fontColor?: string; 17 fontColor?: string;
18 iconColor?: string; 18 iconColor?: string;
  19 + deviceName?: string;
19 } 20 }
20 21
21 export type TextComponentType = 22 export type TextComponentType =
@@ -88,6 +89,7 @@ export const transformTextComponentConfig = ( @@ -88,6 +89,7 @@ export const transformTextComponentConfig = (
88 } as TextComponentLayout, 89 } as TextComponentLayout,
89 value: { 90 value: {
90 name: dataSourceRecord.attributeRename || dataSourceRecord.attribute, 91 name: dataSourceRecord.attributeRename || dataSourceRecord.attribute,
  92 + deviceName: dataSourceRecord.deviceRename || dataSourceRecord.deviceId,
91 value: dataSourceRecord.componentInfo.value, 93 value: dataSourceRecord.componentInfo.value,
92 icon: dataSourceRecord.componentInfo.icon, 94 icon: dataSourceRecord.componentInfo.icon,
93 unit: dataSourceRecord.componentInfo.unit, 95 unit: dataSourceRecord.componentInfo.unit,
@@ -72,8 +72,9 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { @@ -72,8 +72,9 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
72 waitSendQueue.length = 0; 72 waitSendQueue.length = 0;
73 } 73 }
74 }, 74 },
75 - onMessage(ws, message) { 75 + onMessage(_ws, message) {
76 try { 76 try {
  77 + // console.log({ dataSource: unref(dataSourceRef), cmdIdMapping });
77 const res: ResponseMessage = JSON.parse(message.data); 78 const res: ResponseMessage = JSON.parse(message.data);
78 const { subscriptionId, data = {} } = res; 79 const { subscriptionId, data = {} } = res;
79 const mappingRecord = cmdIdMapping.get(subscriptionId); 80 const mappingRecord = cmdIdMapping.get(subscriptionId);
@@ -98,12 +99,13 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) { @@ -98,12 +99,13 @@ export function useSocketConnect(dataSourceRef: Ref<DataBoardLayoutInfo[]>) {
98 99
99 const transformSocketMessageItem = () => { 100 const transformSocketMessageItem = () => {
100 const messageList: SocketMessageItem[] = []; 101 const messageList: SocketMessageItem[] = [];
101 - console.log(dataSourceRef); 102 + let index = 0;
102 unref(dataSourceRef).forEach((record, recordIndex) => { 103 unref(dataSourceRef).forEach((record, recordIndex) => {
103 const componentId = record.record.id; 104 const componentId = record.record.id;
104 record.record.dataSource.forEach((dataSource, dataSourceIndex) => { 105 record.record.dataSource.forEach((dataSource, dataSourceIndex) => {
105 const { deviceId, attribute } = dataSource; 106 const { deviceId, attribute } = dataSource;
106 - const cmdId = recordIndex * dataSourceIndex + recordIndex; 107 + const cmdId = index;
  108 + index++;
107 setCmdId(cmdId, { 109 setCmdId(cmdId, {
108 componentId, 110 componentId,
109 deviceId, 111 deviceId,