|
@@ -3,7 +3,7 @@ |
|
@@ -3,7 +3,7 @@ |
3
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
3
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
4
|
import { formSchema, getHistorySearchParams, SchemaFiled } from './history.config';
|
4
|
import { formSchema, getHistorySearchParams, SchemaFiled } from './history.config';
|
5
|
import { HistoryModalOkEmitParams } from './type';
|
5
|
import { HistoryModalOkEmitParams } from './type';
|
6
|
- import { ref } from 'vue';
|
6
|
+ import { ref, unref } from 'vue';
|
7
|
import { getAllDeviceByOrg } from '/@/api/dataBoard';
|
7
|
import { getAllDeviceByOrg } from '/@/api/dataBoard';
|
8
|
import { getDeviceHistoryInfo } from '/@/api/alarm/position';
|
8
|
import { getDeviceHistoryInfo } from '/@/api/alarm/position';
|
9
|
import { DataSource } from '/@/views/visual/palette/types';
|
9
|
import { DataSource } from '/@/views/visual/palette/types';
|
|
@@ -19,54 +19,149 @@ |
|
@@ -19,54 +19,149 @@ |
19
|
],
|
19
|
],
|
20
|
});
|
20
|
});
|
21
|
|
21
|
|
22
|
- const [registerModal, { closeModal }] = useModalInner(async (dataSource: DataSource[]) => {
|
|
|
23
|
- try {
|
|
|
24
|
- dataSource = cloneDeep(dataSource);
|
|
|
25
|
- if (dataSource.length < 2) return;
|
|
|
26
|
- dataSource = dataSource.splice(0, 2);
|
|
|
27
|
- const deviceRecord = dataSource?.at(0) || ({} as DataSource);
|
|
|
28
|
- if (!deviceRecord.organizationId) return;
|
|
|
29
|
- const deviceList = await getAllDeviceByOrg(
|
|
|
30
|
- deviceRecord.organizationId,
|
|
|
31
|
- deviceRecord.deviceProfileId
|
|
|
32
|
- );
|
|
|
33
|
- const options = deviceList
|
|
|
34
|
- .filter((item) => item.tbDeviceId === deviceRecord.deviceId)
|
|
|
35
|
- .map((item) => ({ ...item, label: item.alias || item.name, value: item.tbDeviceId }));
|
|
|
36
|
-
|
|
|
37
|
- const attKey = dataSource.map((item) => ({
|
|
|
38
|
- ...item,
|
|
|
39
|
- label: item.attribute,
|
|
|
40
|
- value: item.attribute,
|
|
|
41
|
- }));
|
|
|
42
|
- updateSchema([
|
|
|
43
|
- {
|
|
|
44
|
- field: SchemaFiled.DEVICE_ID,
|
|
|
45
|
- componentProps: {
|
|
|
46
|
- options,
|
|
|
47
|
- },
|
22
|
+ const getTwoMap = async (dataSource) => {
|
|
|
23
|
+ if (dataSource.length < 2) return;
|
|
|
24
|
+ dataSource = dataSource.splice(0, 2);
|
|
|
25
|
+ const deviceRecord = dataSource?.at(0) || ({} as DataSource);
|
|
|
26
|
+
|
|
|
27
|
+ if (!deviceRecord.organizationId) return;
|
|
|
28
|
+ const deviceList = await getAllDeviceByOrg(
|
|
|
29
|
+ deviceRecord.organizationId,
|
|
|
30
|
+ deviceRecord.deviceProfileId
|
|
|
31
|
+ );
|
|
|
32
|
+ const options = deviceList
|
|
|
33
|
+ .filter((item) => item.tbDeviceId === deviceRecord.deviceId)
|
|
|
34
|
+ .map((item) => ({ ...item, label: item.alias || item.name, value: item.tbDeviceId }));
|
|
|
35
|
+
|
|
|
36
|
+ const attKey = dataSource.map((item) => ({
|
|
|
37
|
+ ...item,
|
|
|
38
|
+ label: item.attribute,
|
|
|
39
|
+ value: item.attribute,
|
|
|
40
|
+ }));
|
|
|
41
|
+
|
|
|
42
|
+ updateSchemaMap(options, attKey, deviceRecord);
|
|
|
43
|
+ };
|
|
|
44
|
+
|
|
|
45
|
+ const getOneMap = async (dataSource) => {
|
|
|
46
|
+ const deviceRecord = dataSource?.[0];
|
|
|
47
|
+ if (!deviceRecord.organizationId) return;
|
|
|
48
|
+ const deviceList = await getAllDeviceByOrg(
|
|
|
49
|
+ deviceRecord.organizationId,
|
|
|
50
|
+ deviceRecord.deviceProfileId
|
|
|
51
|
+ );
|
|
|
52
|
+ const options = deviceList
|
|
|
53
|
+ .filter((item) => item.tbDeviceId === deviceRecord.deviceId)
|
|
|
54
|
+ .map((item) => ({ ...item, label: item.alias || item.name, value: item.tbDeviceId }));
|
|
|
55
|
+
|
|
|
56
|
+ const attKey = dataSource?.map((item) => ({
|
|
|
57
|
+ ...item,
|
|
|
58
|
+ label: item.attributeName,
|
|
|
59
|
+ value: item.attribute,
|
|
|
60
|
+ }));
|
|
|
61
|
+ updateSchemaMap(options, attKey, deviceRecord);
|
|
|
62
|
+ };
|
|
|
63
|
+
|
|
|
64
|
+ const updateSchemaMap = (options, attKey, deviceRecord) => {
|
|
|
65
|
+ updateSchema([
|
|
|
66
|
+ {
|
|
|
67
|
+ field: SchemaFiled.DEVICE_ID,
|
|
|
68
|
+ componentProps: {
|
|
|
69
|
+ options,
|
48
|
},
|
70
|
},
|
49
|
- {
|
|
|
50
|
- field: SchemaFiled.KEYS,
|
|
|
51
|
- component: 'Select',
|
|
|
52
|
- defaultValue: attKey.map((item) => item.value),
|
|
|
53
|
- componentProps: {
|
|
|
54
|
- options: attKey,
|
|
|
55
|
- mode: 'multiple',
|
|
|
56
|
- disabled: true,
|
|
|
57
|
- },
|
71
|
+ },
|
|
|
72
|
+ {
|
|
|
73
|
+ field: SchemaFiled.KEYS,
|
|
|
74
|
+ component: 'Select',
|
|
|
75
|
+ defaultValue: attKey.map((item) => item.value),
|
|
|
76
|
+ componentProps: {
|
|
|
77
|
+ options: attKey,
|
|
|
78
|
+ mode: 'multiple',
|
|
|
79
|
+ disabled: true,
|
58
|
},
|
80
|
},
|
59
|
- ]);
|
81
|
+ },
|
|
|
82
|
+ ]);
|
60
|
|
83
|
|
61
|
- setFieldsValue({
|
|
|
62
|
- [SchemaFiled.DEVICE_ID]: deviceRecord.deviceId,
|
|
|
63
|
- [SchemaFiled.KEYS]: attKey.map((item) => item.value),
|
|
|
64
|
- });
|
84
|
+ setFieldsValue({
|
|
|
85
|
+ [SchemaFiled.DEVICE_ID]: deviceRecord.deviceId,
|
|
|
86
|
+ [SchemaFiled.KEYS]: attKey.map((item) => item.value),
|
|
|
87
|
+ });
|
|
|
88
|
+ };
|
|
|
89
|
+
|
|
|
90
|
+ const getDesign = ref();
|
|
|
91
|
+
|
|
|
92
|
+ const [registerModal, { closeModal }] = useModalInner(async (dataSource: DataSource[]) => {
|
|
|
93
|
+ try {
|
|
|
94
|
+ getDesign.value = dataSource;
|
|
|
95
|
+ dataSource = cloneDeep(dataSource);
|
|
|
96
|
+ //判断选择是不是结构体
|
|
|
97
|
+ if (dataSource.length == 1 && dataSource?.[0]?.lal) {
|
|
|
98
|
+ getOneMap(dataSource);
|
|
|
99
|
+ return;
|
|
|
100
|
+ }
|
|
|
101
|
+ getTwoMap(dataSource);
|
65
|
} catch (error) {
|
102
|
} catch (error) {
|
66
|
throw error;
|
103
|
throw error;
|
67
|
}
|
104
|
}
|
68
|
});
|
105
|
});
|
69
|
|
106
|
|
|
|
107
|
+ const getMultipleDataSource = async (res) => {
|
|
|
108
|
+ let timespanList = Object.keys(res).reduce((prev, next) => {
|
|
|
109
|
+ const ts = res[next].map((item) => item.ts);
|
|
|
110
|
+ return [...prev, ...ts];
|
|
|
111
|
+ }, [] as number[]);
|
|
|
112
|
+ timespanList = [...new Set(timespanList)];
|
|
|
113
|
+
|
|
|
114
|
+ const track: Record<'lng' | 'lat', number>[] = [];
|
|
|
115
|
+ const keys = Object.keys(res);
|
|
|
116
|
+
|
|
|
117
|
+ for (const ts of timespanList) {
|
|
|
118
|
+ const list: { ts: number; value: number }[] = [];
|
|
|
119
|
+ for (const key of keys) {
|
|
|
120
|
+ const record = res[key].find((item) => ts === item.ts);
|
|
|
121
|
+ if (!validEffective(record?.value)) {
|
|
|
122
|
+ continue;
|
|
|
123
|
+ }
|
|
|
124
|
+ list.push(record as any);
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ if (list.length === 2 && list.every(Boolean)) {
|
|
|
128
|
+ const lng = list.at(0)?.value;
|
|
|
129
|
+ const lat = list.at(1)?.value;
|
|
|
130
|
+ if (lng && lat) track.push({ lng, lat });
|
|
|
131
|
+ }
|
|
|
132
|
+ }
|
|
|
133
|
+ return track;
|
|
|
134
|
+ };
|
|
|
135
|
+
|
|
|
136
|
+ const getSingleDataSource = async (res) => {
|
|
|
137
|
+ const [keys] = Object.keys(res);
|
|
|
138
|
+ const track: Record<'lng' | 'lat', number>[] = [];
|
|
|
139
|
+ const dataSource = res[keys]?.map((item) => {
|
|
|
140
|
+ return {
|
|
|
141
|
+ value: item.value ? JSON.parse(item.value) : {},
|
|
|
142
|
+ };
|
|
|
143
|
+ });
|
|
|
144
|
+ const list: { value: number }[] = [];
|
|
|
145
|
+ dataSource?.forEach((item) => {
|
|
|
146
|
+ if (
|
|
|
147
|
+ //判断结构体得值是不是数字
|
|
|
148
|
+ Object.values(item.value).every((item1) => {
|
|
|
149
|
+ return validEffective(item1 as any);
|
|
|
150
|
+ })
|
|
|
151
|
+ ) {
|
|
|
152
|
+ list.push(item.value);
|
|
|
153
|
+ }
|
|
|
154
|
+ });
|
|
|
155
|
+ const { latitude, longitude } = unref(getDesign)?.[0]; //获取选择得经纬度选项
|
|
|
156
|
+
|
|
|
157
|
+ list.forEach((item) => {
|
|
|
158
|
+ const lng = item[longitude];
|
|
|
159
|
+ const lat = item[latitude];
|
|
|
160
|
+ if (lng && lat) track.push({ lng, lat });
|
|
|
161
|
+ });
|
|
|
162
|
+ return track;
|
|
|
163
|
+ };
|
|
|
164
|
+
|
70
|
const validEffective = (value = '') => {
|
165
|
const validEffective = (value = '') => {
|
71
|
return !!(value && !isNaN(value as unknown as number));
|
166
|
return !!(value && !isNaN(value as unknown as number));
|
72
|
};
|
167
|
};
|
|
@@ -84,33 +179,9 @@ |
|
@@ -84,33 +179,9 @@ |
84
|
...value,
|
179
|
...value,
|
85
|
[SchemaFiled.KEYS]: value[SchemaFiled.KEYS].join(','),
|
180
|
[SchemaFiled.KEYS]: value[SchemaFiled.KEYS].join(','),
|
86
|
});
|
181
|
});
|
|
|
182
|
+ const ifSingle = unref(getDesign).length === 1 && unref(getDesign)?.[0]?.lal;
|
87
|
|
183
|
|
88
|
- let timespanList = Object.keys(res).reduce((prev, next) => {
|
|
|
89
|
- const ts = res[next].map((item) => item.ts);
|
|
|
90
|
- return [...prev, ...ts];
|
|
|
91
|
- }, [] as number[]);
|
|
|
92
|
- timespanList = [...new Set(timespanList)];
|
|
|
93
|
-
|
|
|
94
|
- const track: Record<'lng' | 'lat', number>[] = [];
|
|
|
95
|
- const keys = Object.keys(res);
|
|
|
96
|
-
|
|
|
97
|
- for (const ts of timespanList) {
|
|
|
98
|
- const list: { ts: number; value: number }[] = [];
|
|
|
99
|
- for (const key of keys) {
|
|
|
100
|
- const record = res[key].find((item) => ts === item.ts);
|
|
|
101
|
- if (!validEffective(record?.value)) {
|
|
|
102
|
- continue;
|
|
|
103
|
- }
|
|
|
104
|
- list.push(record as any);
|
|
|
105
|
- }
|
|
|
106
|
-
|
|
|
107
|
- if (list.length === 2 && list.every(Boolean)) {
|
|
|
108
|
- const lng = list.at(0)?.value;
|
|
|
109
|
- const lat = list.at(1)?.value;
|
|
|
110
|
- if (lng && lat) track.push({ lng, lat });
|
|
|
111
|
- }
|
|
|
112
|
- }
|
|
|
113
|
-
|
184
|
+ const track = ifSingle ? await getSingleDataSource(res) : await getMultipleDataSource(res);
|
114
|
emit('ok', { track, value } as HistoryModalOkEmitParams);
|
185
|
emit('ok', { track, value } as HistoryModalOkEmitParams);
|
115
|
closeModal();
|
186
|
closeModal();
|
116
|
} catch (error) {
|
187
|
} catch (error) {
|