DevicePreviewModal.vue
3.27 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
100
101
102
103
104
105
106
<template>
<div>
<BasicModal
style="min-height: auto"
v-bind="$attrs"
width="55rem"
@register="register"
:title="t('report.config.modalTitle')"
:showOkBtn="false"
>
<div>
<BasicTable @register="registerTable" :dataSource="tableData" />
</div>
</BasicModal>
</div>
</template>
<script setup lang="ts">
import { ref, nextTick } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import { viewDeviceColumn } from '../config';
import { reportEditDetailPage } from '/@/api/report/reportManager';
import { useI18n } from '/@/hooks/web/useI18n';
import { getDeviceDetail } from '/@/api/device/deviceManager';
import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
const tableData = ref([]);
const { t } = useI18n();
const [registerTable, { setLoading }] = useTable({
columns: viewDeviceColumn,
showIndexColumn: false,
clickToRowSelect: false,
showTableSetting: false,
bordered: true,
});
const [register] = useModalInner((data) => {
setLoading(true);
tableData.value = [];
const getTableData = async () => {
const res = (await reportEditDetailPage(data.record?.id)) as any;
const deviceInfo = res?.data?.executeAttributes || [];
let attributesList: Recordable[] = [];
// 处理为物模型里的标识符名
const reflectDeviceList = deviceInfo.map(async (item) => {
const { device, attributes } = item as Recordable;
if (!device) return;
const thingsModel = (await handleDeviceProfileAttributes(item.device)) as Recordable;
const { tbDeviceId, attribute } = thingsModel as Recordable;
if (!tbDeviceId) return;
if (device === tbDeviceId) {
attributesList = attributes.reduce((acc, curr) => {
attribute.forEach((item: Recordable) => {
if (item.identifier === curr) {
acc.push({
label: item.name,
value: item.identifier,
});
}
});
return [...acc];
}, []);
}
return {
device: item.name,
attribute: attributesList.map((item: Recordable) => item.label).join(','),
};
});
tableData.value = (await Promise.all(reflectDeviceList)) as any;
if (tableData.value) {
setLoading(false);
}
};
nextTick(() => {
getTableData();
});
});
const handleDeviceProfileAttributes = async (entityId: string) => {
const deviceDetailRes = await getDeviceDetail(entityId);
const { deviceProfileId } = deviceDetailRes;
if (!deviceProfileId) return;
const attributeRes = await getAttribute(deviceProfileId);
return handleDataFormat(deviceDetailRes, attributeRes);
};
const handleDataFormat = (deviceDetail: any, attributes: any) => {
const { name, tbDeviceId } = deviceDetail;
const attribute = attributes.map((item: any) => ({
identifier: item.identifier,
name: item.name,
detail: item.detail,
}));
return {
name,
tbDeviceId,
attribute,
};
};
</script>
<style lang="less" scoped>
:deep(.ant-table-body) {
height: 470px !important;
}
</style>