Commit 5f11983c88df11661fc6511d36db554862a36246

Authored by xp.Huang
2 parents 332b01a1 cfc9d9f2

Merge branch 'main_dev' into feat/account-role-manage

# Conflicts:
#	src/views/dataview/config.ts
... ... @@ -20,7 +20,7 @@ export enum ConfigurationPermission {
20 20 // DESIGN = 'api:yt:dataview:center:get_configuration_info:design',
21 21 DESIGN = 'api:yt:dataview:center:get_dataview_info:design',
22 22 PREVIEW = 'api:yt:dataview:center:get_configuration_info:preview',
23   - DATAVIEW_PREVIEW = 'api:yt:dataview:center:get_dataview_info:preview',
  23 + DATAVIEW_PREVIEW = 'api:yt:dataview:center:get_dataview_info:preview', //大屏预览
24 24 PUBLISH = 'api:yt:dataview:center:publish',
25 25 // CANCEL_PUBLISH = 'api:yt:dataview:center:cancel_publish',
26 26 PUBLISH_INTERFACE = 'api:yt:dataview:center:public_interface',
... ...
... ... @@ -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) {
... ...
... ... @@ -117,10 +117,12 @@
117 117 );
118 118 };
119 119
120   - const getChartsOption = (result: ResponsData) => {
  120 + const getChartsOption = (result: ResponsData, thingsModel: Recordable) => {
  121 + const { attribute } = thingsModel;
121 122 const generateInfo = Object.entries(result).map((item) => {
122 123 const [attr, val] = item;
123   - return { attr, val } as { attr: string; val: { ts: number; value: string }[] };
  124 + const findAttrName = attribute.find((attrItem) => attrItem.identifier === attr)?.name;
  125 + return { attr: findAttrName, val } as { attr: string; val: { ts: number; value: string }[] };
124 126 });
125 127 const chartDataConfig =
126 128 generateInfo.map((item) => {
... ... @@ -216,9 +218,13 @@
216 218 },
217 219 };
218 220
  221 + const thingsModel = (await handleDeviceProfileAttributes(device)) as Recordable;
219 222 const result = await exportViewChartApi(device, sendParams);
220 223 item.notFoundData = validateHasData(result);
221   - const { xAxisData, series } = getChartsOption(result as unknown as ResponsData);
  224 + const { xAxisData, series } = getChartsOption(
  225 + result as unknown as ResponsData,
  226 + thingsModel as unknown as Recordable
  227 + );
222 228
223 229 await nextTick();
224 230 chartsInstance[device] = echarts.init(
... ... @@ -320,7 +326,8 @@
320 326 const result = await exportViewChartApi(device, sendParams);
321 327
322 328 item.notFoundData = validateHasData(result);
323   - const { xAxisData, series } = getChartsOption(result as unknown as ResponsData);
  329 + const thingsModel = (await handleDeviceProfileAttributes(device)) as Recordable;
  330 + const { xAxisData, series } = getChartsOption(result as unknown as ResponsData, thingsModel);
324 331
325 332 chartsInstance[device].setOption({
326 333 series,
... ...