config.ts
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { ComponentInfo, DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
export interface TextComponentLayout {
  id: string;
  base?: boolean;
  showUpdate?: boolean;
  showIcon?: boolean;
  showUnit?: boolean;
}
export interface TextComponentValue {
  name: string;
  value: number;
  icon?: string;
  unit?: string;
  updateTime?: string;
  fontColor?: string;
  iconColor?: string;
  deviceName?: string;
}
type TextComponentDefault = TextComponentLayout;
export const TextComponent1Config: TextComponentDefault = {
  id: 'text-component-1',
  base: true,
};
export const TextComponent3Config: TextComponentDefault = {
  id: 'text-component-3',
  base: false,
  showUpdate: true,
};
export const TextComponent4Config: TextComponentDefault = {
  id: 'text-component-4',
  base: false,
  showIcon: true,
  showUpdate: true,
  showUnit: true,
};
export const TextComponent5Config: TextComponentDefault = {
  id: 'text-component-5',
  base: false,
  showIcon: true,
  showUnit: true,
};
export const TextComponentDefaultConfig: Partial<ComponentInfo> = {
  fontColor: '#000',
  unit: '℃',
  iconColor: '#367BFF',
  icon: 'shuiwen',
};
export const transformTextComponentConfig = (
  config: TextComponentDefault,
  _record: DataComponentRecord,
  dataSourceRecord: DataSource
) => {
  return {
    layout: {
      ...config,
    } as TextComponentLayout,
    value: {
      name: dataSourceRecord.attributeRename || dataSourceRecord.attribute,
      deviceName: dataSourceRecord.deviceRename || dataSourceRecord.deviceId,
      value: dataSourceRecord.componentInfo.value,
      icon: dataSourceRecord.componentInfo.icon,
      unit: dataSourceRecord.componentInfo.unit,
      updateTime: dataSourceRecord.componentInfo.updateTime,
      fontColor: dataSourceRecord.componentInfo.fontColor,
      iconColor: dataSourceRecord.componentInfo.iconColor,
    } as TextComponentValue,
  };
};