map.config.ts
1.59 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
import { FrontComponent } from '../../const/const';
import { ComponentConfig } from '../../types/type';
import { DataSource } from '/@/api/dataBoard/model';
export interface MapComponentLayout {
componentType?: FrontComponent;
}
export interface MapComponentValue {
icon?: string;
track?: Record<'ts' | 'value', number>[];
dataSource?: DataSource[];
}
interface Config {
componentType?: FrontComponent;
}
export const MaphistoryTrackConfig: Config = {
componentType: FrontComponent.MAP_COMPONENT_TRACK_HISTORY,
};
export const MapRealTrackConfig: Config = {
componentType: FrontComponent.MAP_COMPONENT_TRACK_REAL,
};
const getTrack = (dataSource: DataSource[], config: Config) => {
if (dataSource.length >= 2) {
const trackRecord = dataSource.slice(0, 2);
if (
!trackRecord.every((item) => item.componentInfo.value) &&
config.componentType === FrontComponent.MAP_COMPONENT_TRACK_REAL
)
return { track: [], dataSource: [] };
const track = trackRecord.map((item) => {
return {
ts: item.componentInfo.updateTime,
value: item.componentInfo.value || 0,
};
});
return { track, dataSource };
}
return { track: [], dataSource: [] };
};
export const transfromMapComponentConfig: ComponentConfig['transformConfig'] = (
componentConfig: Config,
_record,
dataSourceRecord
) => {
const { track, dataSource } = getTrack(dataSourceRecord as DataSource[], componentConfig);
return {
layout: {
...componentConfig,
} as MapComponentLayout,
value: {
track,
dataSource,
} as MapComponentValue,
};
};