Commit 619fd606 authored by 李纪文's avatar 李纪文

fix: 组态增加源数据

parent bc5ac076
......@@ -146,7 +146,6 @@
},
"dependencies": {
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@wisdom-components/VmsVideo": "1.1.13",
"@wisdom-components/basictable": "^1.5.14",
"@wisdom-components/ec_historyview": "^1.4.3",
"@wisdom-components/empty": "^1.3.9",
......@@ -154,8 +153,10 @@
"@wisdom-components/loadbox": "1.1.4",
"@wisdom-components/timerangepicker": "^1.3.4",
"@wisdom-components/videoslidermodal": "1.1.2",
"@wisdom-components/VmsVideo": "1.1.13",
"@wisdom-utils/utils": "0.0.46",
"antd-mobile": "5.10.4",
"axios": "^1.4.0",
"classnames": "^2.2.6",
"cross-spawn": "^7.0.3",
"echarts": "^5.4.0",
......
......@@ -2,6 +2,7 @@
import React, { useState, useEffect, useRef, useContext } from 'react';
import classNames from 'classnames';
import moment from 'moment';
import axios from 'axios';
import sha1 from 'sha1';
import Empty from '@wisdom-components/empty';
import LoadBox from '@wisdom-components/loadbox';
......@@ -913,6 +914,67 @@ const ConfigurationView = (props) => {
);
};
/** ************************************数据源模型获取******************************* */
const getDataModel = () => {
const json = JSON.parse(myDiagram.model.toJson());
const jsonCopy = JSON.parse(JSON.stringify(json));
const nodeDataArray = jsonCopy.nodeDataArray;
const dataCaseArr = nodeDataArray.filter((item) => {
return item.category === 'dataSource' && item.url;
});
try {
dataCaseArr.forEach((item, index) => {
const time = new Date().getTime() + index;
const params =
item && item.parameters
? (isJson(item.parameters) && JSON.parse(item.parameters)) || {}
: {};
const data = item && item.body ? (isJson(item.body) && JSON.parse(item.body)) || {} : {};
axios({
method: item.method,
url: item.url,
params: {
...params,
time: time,
},
data: data,
})
.then((res) => {
realValueHandle(nodeDataArray, item, getDataFilter(item, res?.data || {}));
})
.catch((err) => {
realValueHandle(nodeDataArray, item, null);
});
});
} catch (err) {}
};
/** ************************************数据源过滤器******************************* */
const getDataFilter = (item, data) => {
try {
const script = item && item.filter ? item.filter : '';
if (!script) return data;
const list = new Function('data', script)(data);
return list;
} catch (err) {
return null;
}
};
/** ************************************源数据模型处理******************************* */
const realValueHandle = (nodeDataArray, list, data) => {
nodeDataArray.forEach((item) => {
if (item.category !== 'dataCase' || item.dataSource !== list.sname || !item.shType)
return false;
try {
const script = item && item.filter ? item.filter : '';
const value = new Function('data', script)(data);
const node = myDiagram.model.findNodeDataForKey(item.key);
myDiagram.model.setDataProperty(node, 'showVal', value || '--');
} catch (err) {}
});
};
/** ************************************图表数据处理******************************* */
const chartDataRender = (mqttData) => {
const json = JSON.parse(myDiagram.model.toJson());
......@@ -1020,7 +1082,7 @@ const ConfigurationView = (props) => {
/** **************************************历史模态渲染****************************************** */
const historyModalRender = (data, list) => {
if(!data.shName) return false;
if (!data.shName) return false;
historyInfoParams = [
{
deviceCode: list.code,
......@@ -1946,6 +2008,81 @@ const ConfigurationView = (props) => {
),
);
// 源数据模型
myDiagram.nodeTemplateMap.add(
'dataCase',
goJS(
go.Node,
'Auto',
nodeStyle(),
'Spot',
{ locationSpot: go.Spot.Center, zOrder: 3, cursor: 'default' },
new go.Binding('zOrder', 'zOrder').makeTwoWay(),
new go.Binding('cursor', 'cursor').makeTwoWay(),
new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify),
new go.Binding('angle').makeTwoWay(),
roleVisibleBinding(), // 绑定角色可见
goJS(
go.Shape,
'RoundedRectanglePlus',
{ name: 'SHAPE', strokeWidth: 10, stroke: '#000000', parameter1: 0 },
new go.Binding('fill', 'fillColor').makeTwoWay(),
new go.Binding('stroke').makeTwoWay(),
new go.Binding('strokeWidth').makeTwoWay(),
new go.Binding('parameter1', 'radius').makeTwoWay(),
new go.Binding('desiredSize', 'size', go.Size.parse).makeTwoWay(go.Size.stringify),
),
goJS(
go.TextBlock,
textStyle(),
{
// margin: 5,
maxSize: new go.Size(NaN, NaN),
minSize: new go.Size(NaN, 1),
wrap: go.TextBlock.WrapFit,
textAlign: 'center',
editable: true,
font: 'bold 12px Helvetica, Arial, sans-serif',
stroke: '#454545',
},
new go.Binding('text', 'showVal').makeTwoWay(),
new go.Binding('font', 'fontStyle'),
new go.Binding('stroke', 'fontStroke').makeTwoWay(),
new go.Binding('textAlign', 'fontAlign'),
new go.Binding('maxSize', 'textSize'),
new go.Binding('minSize', 'textSize'),
),
{
click(e, node) {
if (navigatorAgent) return false;
const { data } = node;
nodeData = data;
const list = bindData.find((item) => {
return item.name === data.stationName;
});
if (!list) return false;
switch (data.opType) {
case '画板跳转': // 图片模型
drawBoardMethod(data);
break;
case '功能跳转': // 功能模型
menuJumpMethod(data);
break;
case '视频查看': // 视频查看
videoScanMethod(data);
break;
case '自定义交互': // 自定义交互
customBack(data);
interactiveScript(data);
break;
default:
break;
}
},
},
),
);
// 名称定义
myDiagram.nodeTemplateMap.add(
'nameCase',
......@@ -2709,6 +2846,7 @@ const ConfigurationView = (props) => {
if (item.category === 'valCase') item.shType = '值显示';
});
myDiagram.model = go.Model.fromJson(json);
getDataModel();
};
return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment