Commit 7cdca435498ecf13358287e7e9538a7026a8e0dd

Authored by ww
1 parent bf9d205b

perf: data board component chart component update color not update immediate

@@ -79,15 +79,20 @@ @@ -79,15 +79,20 @@
79 const getUpdateValueFn = (componentType: InstrumentComponentType) => { 79 const getUpdateValueFn = (componentType: InstrumentComponentType) => {
80 if (componentType === 'instrument-component-1') return update_instrument_1_value; 80 if (componentType === 'instrument-component-1') return update_instrument_1_value;
81 if (componentType === 'instrument-component-2') return update_instrument_2_value; 81 if (componentType === 'instrument-component-2') return update_instrument_2_value;
82 - return (_radio: number) => {}; 82 + return (_radio: DashBoardValue) => {};
83 }; 83 };
84 84
85 - const updateChartValue = useThrottleFn((newValue) => { 85 + const updateChartValue = useThrottleFn(() => {
86 const updateFn = getUpdateValueFn(props.layout.componentType); 86 const updateFn = getUpdateValueFn(props.layout.componentType);
87 - unref(chartRef)?.setOption((updateFn(newValue || 0) as unknown as EChartsOption) || {}); 87 + unref(chartRef)?.setOption((updateFn(props.value) as unknown as EChartsOption) || {});
88 }, 500); 88 }, 500);
89 89
90 - watch(() => props.value.value, updateChartValue); 90 + watch(() => props.value, updateChartValue);
  91 +
  92 + // watch(
  93 + // () => [props.value.gradientInfo, props.value.unit, props.value.valueColor, props.value.name],
  94 + // updateChartValue
  95 + // );
91 96
92 const updateChartFont = useThrottleFn(() => { 97 const updateChartFont = useThrottleFn(() => {
93 const option = beforeUpdateFn(props.layout.componentType); 98 const option = beforeUpdateFn(props.layout.componentType);
@@ -110,7 +115,9 @@ @@ -110,7 +115,9 @@
110 function handleRandomValue() { 115 function handleRandomValue() {
111 const newValue = Math.floor(Math.random() * 100); 116 const newValue = Math.floor(Math.random() * 100);
112 const updateFn = getUpdateValueFn(props.layout.componentType); 117 const updateFn = getUpdateValueFn(props.layout.componentType);
113 - unref(chartRef)?.setOption((updateFn(newValue) as unknown as EChartsOption) || {}); 118 + unref(chartRef)?.setOption(
  119 + (updateFn({ ...props.value, value: newValue }) as unknown as EChartsOption) || {}
  120 + );
114 } 121 }
115 122
116 onMounted(() => { 123 onMounted(() => {
@@ -32,7 +32,7 @@ export interface DashBoardValue { @@ -32,7 +32,7 @@ export interface DashBoardValue {
32 name?: string; 32 name?: string;
33 updateTime?: string; 33 updateTime?: string;
34 value?: number; 34 value?: number;
35 - valueColor?: string; 35 + fontColor?: string;
36 gradientInfo?: GradientInfoRecord[]; 36 gradientInfo?: GradientInfoRecord[];
37 } 37 }
38 38
@@ -277,11 +277,16 @@ const handleValue = (value: any) => { @@ -277,11 +277,16 @@ const handleValue = (value: any) => {
277 return Number(value).toFixed(2); 277 return Number(value).toFixed(2);
278 }; 278 };
279 279
280 -export const update_instrument_1_value = (value: number) => { 280 +export const update_instrument_1_value = (params: DashBoardValue) => {
  281 + const { value = 0, unit = '°C', fontColor } = params;
281 return { 282 return {
282 series: [ 283 series: [
283 { 284 {
284 data: [{ value: handleValue(value) }], 285 data: [{ value: handleValue(value) }],
  286 + detail: {
  287 + formatter: `{value} ${unit ?? ''}`,
  288 + color: fontColor || 'inherit',
  289 + },
285 }, 290 },
286 { 291 {
287 data: [{ value: handleValue(value) }], 292 data: [{ value: handleValue(value) }],
@@ -290,11 +295,35 @@ export const update_instrument_1_value = (value: number) => { @@ -290,11 +295,35 @@ export const update_instrument_1_value = (value: number) => {
290 } as EChartsOption; 295 } as EChartsOption;
291 }; 296 };
292 297
293 -export const update_instrument_2_value = (value: number) => { 298 +export const update_instrument_2_value = (params: DashBoardValue) => {
  299 + const { value = 0, unit = 'km/h', fontColor, gradientInfo } = params;
  300 + const firstRecord = getGradient(Gradient.FIRST, gradientInfo);
  301 + const secondRecord = getGradient(Gradient.SECOND, gradientInfo);
  302 + const thirdRecord = getGradient(Gradient.THIRD, gradientInfo);
  303 +
  304 + let max = thirdRecord?.value || secondRecord?.value || firstRecord?.value || 70;
  305 + max = Number(1 + Array(String(max).length).fill(0).join(''));
  306 +
  307 + const firstGradient = firstRecord?.value ? firstRecord.value / max : 0.3;
  308 + const secondGradient = secondRecord?.value ? secondRecord.value / max : 0.7;
294 return { 309 return {
295 series: [ 310 series: [
296 { 311 {
297 data: [{ value: handleValue(value) }], 312 data: [{ value: handleValue(value) }],
  313 + detail: {
  314 + formatter: `{value} ${unit ?? ''}`,
  315 + color: fontColor || 'inherit',
  316 + },
  317 + axisLine: {
  318 + lineStyle: {
  319 + width: 20,
  320 + color: [
  321 + [firstGradient, firstRecord?.color || GradientColor.FIRST],
  322 + [secondGradient, secondRecord?.color || GradientColor.SECOND],
  323 + [1, thirdRecord?.color || GradientColor.THIRD],
  324 + ],
  325 + },
  326 + },
298 }, 327 },
299 ], 328 ],
300 } as EChartsOption; 329 } as EChartsOption;