...
|
...
|
@@ -20,10 +20,12 @@ |
20
|
20
|
import { BasicTable, useTable } from '/@/components/Table';
|
21
|
21
|
import { viewDeviceColumn } from '../config';
|
22
|
22
|
import { reportEditDetailPage } from '/@/api/report/reportManager';
|
|
23
|
+ import { getDeviceDetail } from '/@/api/device/deviceManager';
|
|
24
|
+ import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
|
23
|
25
|
|
24
|
26
|
const tableData = ref([]);
|
25
|
27
|
|
26
|
|
- const [registerTable] = useTable({
|
|
28
|
+ const [registerTable, { setLoading }] = useTable({
|
27
|
29
|
columns: viewDeviceColumn,
|
28
|
30
|
showIndexColumn: false,
|
29
|
31
|
clickToRowSelect: false,
|
...
|
...
|
@@ -32,18 +34,68 @@ |
32
|
34
|
});
|
33
|
35
|
|
34
|
36
|
const [register] = useModalInner((data) => {
|
|
37
|
+ setLoading(true);
|
|
38
|
+ tableData.value = [];
|
35
|
39
|
const getTableData = async () => {
|
36
|
40
|
const res = (await reportEditDetailPage(data.record?.id)) as any;
|
37
|
|
- const resMap = res?.data?.executeAttributes?.map((item) => ({
|
38
|
|
- device: item.name,
|
39
|
|
- attribute: item.attributes.join(','),
|
40
|
|
- }));
|
41
|
|
- tableData.value = resMap;
|
|
41
|
+ const deviceInfo = res?.data?.executeAttributes || [];
|
|
42
|
+ let attributesList: Recordable[] = [];
|
|
43
|
+ // 处理为物模型里的标识符名
|
|
44
|
+ const reflectDeviceList = deviceInfo.map(async (item) => {
|
|
45
|
+ const { device, attributes } = item as Recordable;
|
|
46
|
+ if (!device) return;
|
|
47
|
+ const thingsModel = (await handleDeviceProfileAttributes(item.device)) as Recordable;
|
|
48
|
+ const { tbDeviceId, attribute } = thingsModel as Recordable;
|
|
49
|
+ if (!tbDeviceId) return;
|
|
50
|
+ if (device === tbDeviceId) {
|
|
51
|
+ attributesList = attributes.reduce((acc, curr) => {
|
|
52
|
+ attribute.forEach((item: Recordable) => {
|
|
53
|
+ if (item.identifier === curr) {
|
|
54
|
+ acc.push({
|
|
55
|
+ label: item.name,
|
|
56
|
+ value: item.identifier,
|
|
57
|
+ });
|
|
58
|
+ }
|
|
59
|
+ });
|
|
60
|
+ return [...acc];
|
|
61
|
+ }, []);
|
|
62
|
+ }
|
|
63
|
+ return {
|
|
64
|
+ device: item.name,
|
|
65
|
+ attribute: attributesList.map((item: Recordable) => item.label).join(','),
|
|
66
|
+ };
|
|
67
|
+ });
|
|
68
|
+ tableData.value = (await Promise.all(reflectDeviceList)) as any;
|
|
69
|
+ if (tableData.value) {
|
|
70
|
+ setLoading(false);
|
|
71
|
+ }
|
42
|
72
|
};
|
43
|
73
|
nextTick(() => {
|
44
|
74
|
getTableData();
|
45
|
75
|
});
|
46
|
76
|
});
|
|
77
|
+
|
|
78
|
+ const handleDeviceProfileAttributes = async (entityId: string) => {
|
|
79
|
+ const deviceDetailRes = await getDeviceDetail(entityId);
|
|
80
|
+ const { deviceProfileId } = deviceDetailRes;
|
|
81
|
+ if (!deviceProfileId) return;
|
|
82
|
+ const attributeRes = await getAttribute(deviceProfileId);
|
|
83
|
+ return handleDataFormat(deviceDetailRes, attributeRes);
|
|
84
|
+ };
|
|
85
|
+
|
|
86
|
+ const handleDataFormat = (deviceDetail: any, attributes: any) => {
|
|
87
|
+ const { name, tbDeviceId } = deviceDetail;
|
|
88
|
+ const attribute = attributes.map((item: any) => ({
|
|
89
|
+ identifier: item.identifier,
|
|
90
|
+ name: item.name,
|
|
91
|
+ detail: item.detail,
|
|
92
|
+ }));
|
|
93
|
+ return {
|
|
94
|
+ name,
|
|
95
|
+ tbDeviceId,
|
|
96
|
+ attribute,
|
|
97
|
+ };
|
|
98
|
+ };
|
47
|
99
|
</script>
|
48
|
100
|
<style lang="less" scoped>
|
49
|
101
|
:deep(.ant-table-body) {
|
...
|
...
|
|