config.ts
2.5 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { formatToDateTime } from '/@/utils/dateUtil';
import { 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;
}
export type TextComponentType =
| 'text-component-1'
| 'text-component-2'
| 'text-component-3'
| 'text-component-4'
| 'text-component-5';
type TextComponentDefault = TextComponentLayout & { value: TextComponentValue };
export const TextComponent1Config: TextComponentDefault = {
id: 'text-component-1',
base: true,
value: { value: 123, name: '温度' },
};
export const TextComponent2Config: TextComponentDefault = {
id: 'text-component-2',
base: false,
value: { value: 123, name: '温度' },
};
export const TextComponent3Config: TextComponentDefault = {
id: 'text-component-3',
base: false,
showUpdate: true,
value: {
value: 123,
name: '温度',
updateTime: formatToDateTime(new Date(), 'YYYY-MM-DD HH:mm:ss'),
},
};
export const TextComponent4Config: TextComponentDefault = {
id: 'text-component-4',
base: false,
showIcon: true,
showUpdate: true,
showUnit: true,
value: {
value: 123,
name: '温度',
updateTime: formatToDateTime(new Date(), 'YYYY-MM-DD HH:mm:ss'),
unit: '℃',
},
};
export const TextComponent5Config: TextComponentDefault = {
id: 'text-component-5',
base: false,
showIcon: true,
showUnit: true,
value: { value: 123, name: '温度', unit: '℃' },
};
export const textComponentConfig: TextComponentDefault[] = [
TextComponent1Config,
TextComponent2Config,
TextComponent3Config,
TextComponent4Config,
TextComponent5Config,
];
export const transformTextComponentConfig = (
config: TextComponentDefault,
record: DataComponentRecord,
dataSourceRecord: DataSource
) => {
return {
layout: {
...config,
} as TextComponentLayout,
value: {
name: dataSourceRecord.attributeRename || dataSourceRecord.attribute,
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,
};
};