Commit c2c1d423 authored by 李纪文's avatar 李纪文

feat: mqttView增加报警推送、组态增加报警解析

parent 6029774a
......@@ -13,7 +13,9 @@ class MqttView {
this.devices = props.devices;
this.callback = props.callback;
this.controlback = props.controlback;
this.alarmback = props.alarmback;
this.params = props.params || {};
this.isAlarm = props.isAlarm || false;
this.flag = false;
}
......@@ -83,6 +85,13 @@ class MqttView {
);
}
});
this.isAlarm &&
this.devices.forEach((item) => {
if (item) {
var saveWaTopic = this.siteCode + '/' + item.replace(/[#+]/g, '@') + '/alarm' + '/#';
this.saveWaClient.subscribe(saveWaTopic);
}
});
}
//主题断开连接
......@@ -119,6 +128,11 @@ class MqttView {
this.controlback(message.payloadString, code, topic);
return false;
}
if (topic.indexOf('alarm') > -1) {
var alarmCode = topic.split('/')[1];
this.alarmback(message.payloadString, alarmCode, topic);
return false;
}
this.callback(message.payloadString, code, topic);
}
......@@ -178,8 +192,10 @@ MqttView.propTypes = {
siteCode: PropTypes.string,
devices: PropTypes.array,
params: PropTypes.object,
isAlarm: PropTypes.bool,
callback: PropTypes.func,
controlback: PropTypes.func,
alarmback: PropTypes.func,
};
MqttView.defaultProps = {
......@@ -191,8 +207,10 @@ MqttView.defaultProps = {
siteCode: '',
devices: [],
params: {},
isAlarm: false,
callback: () => {},
controlback: () => {},
alarmback: () => {},
};
// 解密
......
......@@ -53,6 +53,7 @@ import {
loginauthen,
encipher,
} from './js/utils';
import svgIcons from './js/icons';
import './index.less';
const goJS = go.GraphObject.make;
......@@ -616,6 +617,32 @@ const ConfigurationView = (props) => {
}
};
/** **************************************MQTT报警数据获取****************************************** */
const alarmData = (mqttDatas, code) => {
if (isClose || !myDiagram) return false;
const bindList = bindData.find((item) => {
return item.code === code;
});
const mqttData = JSON.parse(mqttDatas);
if (!mqttData) return false;
const json = JSON.parse(myDiagram.model.toJson());
const jsonCopy = JSON.parse(JSON.stringify(json));
try {
jsonCopy.nodeDataArray.forEach((item) => {
if (item.category !== 'valCase' || !item?.alarmSwitch) return false;
const node = myDiagram.model.findNodeDataForKey(item.key);
if (bindList?.code !== mqttData?.Code || bindList?.name !== item.stationName) return false;
if (mqttData?.SensorName !== item.shName) return false;
const { RemoveAlertTime, AlarmContent, StationName } = mqttData;
const alarmInfo = `${StationName}${AlarmContent}`;
myDiagram.model.setDataProperty(node, 'alarmType', RemoveAlertTime ? '正常' : '报警');
myDiagram.model.setDataProperty(node, 'alarmInfo', RemoveAlertTime ? '' : alarmInfo);
});
} catch (e) {
// 节点展示
}
};
/** **************************************是否在线数据获取****************************************** */
const onLineDataMethod = (data) => {
const onlineList = data.find((list) => {
......@@ -1067,8 +1094,10 @@ const ConfigurationView = (props) => {
mqttSsl: globalConfig.mqtt_IsSSL,
siteCode: globalConfig?.mqtt_mess?.site_code || '',
devices: devicesCode,
isAlarm: true,
callback: refreshData,
controlback: controlData,
alarmback: alarmData,
})
: null;
const diagramJson = typeof fromJson === 'string' ? fromJson : JSON.stringify(fromJson);
......@@ -1857,6 +1886,7 @@ const ConfigurationView = (props) => {
// LinkReshaped: (e) => {
// e.subject.routing = go.Link.Orthogonal;
// },
'toolManager.hoverDelay': 100,
'linkingTool.direction': go.LinkingTool.ForwardsOnly,
},
);
......@@ -2708,6 +2738,80 @@ const ConfigurationView = (props) => {
),
);
const nodeHoverAdornment = goJS(
go.Adornment,
'Spot',
{
background: 'transparent',
mouseLeave: function (e, obj) {
const ad = obj.part;
ad.adornedPart.removeAdornment('mouseHover');
},
},
new go.Binding('cursor', 'cursor').makeTwoWay(),
new go.Binding('visible', '', function (data) {
const { alarmType, realType } = data;
return realType === '在线' && alarmType === '报警';
}),
goJS(go.Placeholder, {
// background: 'transparent',
isActionable: true,
}),
goJS(
go.Panel,
'Auto',
{ alignment: go.Spot.Left, alignmentFocus: go.Spot.Right }, // 左边
// { alignment: go.Spot.Right, alignmentFocus: go.Spot.Left }, // 右边
{ padding: new go.Margin(0, 5, 0, 0), cursor: 'pointer' },
goJS(
go.Shape,
{ fill: '#ff2929', strokeWidth: 0, width: 16, height: 16 },
new go.Binding('fill', '', function (data) {
return data?.alarmStroke || '#ff2929';
}),
new go.Binding('width', '', function (data) {
return data?.alarmSize || 16;
}),
new go.Binding('height', '', function (data) {
return data?.alarmSize || 16;
}),
new go.Binding('geometry', '', function (data) {
let geo = svgIcons['warning'];
if (geo === undefined) geo = null; // use this for an unknown icon name
if (typeof geo === 'string') {
geo = svgIcons['warning'] = go.Geometry.parse(geo, true); // fill each geometry
}
return geo;
}),
),
goJS(
go.Shape,
'Circle',
{ fill: 'transparent', strokeWidth: 0, width: 16 },
new go.Binding('width', '', function (data) {
return data?.alarmSize || 16;
}),
),
{
toolTip: goJS(
'ToolTip',
goJS(
go.TextBlock,
{ margin: 2 },
new go.Binding('text', '', function (data) {
const { alarmType, realType } = data;
if (realType === '在线' && alarmType === '报警') {
return data?.alarmInfo || '';
} else {
return '';
}
}),
),
),
},
),
);
// 值定义
myDiagram.nodeTemplateMap.add(
'valCase',
......@@ -2754,12 +2858,31 @@ const ConfigurationView = (props) => {
},
new go.Binding('text', 'showVal'),
new go.Binding('font', 'fontStyle'),
new go.Binding('stroke', 'fontStroke'),
// new go.Binding('stroke', 'fontStroke'),
new go.Binding('stroke', '', function (data) {
const { alarmType, realType } = data;
if (realType === '在线' && alarmType === '报警') {
return data?.alarmStroke || '#ff2929';
} else {
return data?.fontStroke;
}
}),
new go.Binding('textAlign', 'fontAlign'),
new go.Binding('maxSize', 'textSize'),
new go.Binding('minSize', 'textSize'),
new go.Binding('flip', 'flip'),
),
{
mouseHover: function (e, obj) {
const node = obj.part;
const data = node?.data || {};
const { alarmType, realType } = data;
if (realType === '在线' && alarmType === '报警') {
nodeHoverAdornment.adornedObject = node;
node.addAdornment('mouseHover', nodeHoverAdornment);
}
},
},
),
goJS(
go.TextBlock,
......@@ -3361,6 +3484,7 @@ const ConfigurationView = (props) => {
if (item.category === 'valCase') {
if (item.shType === '') item.showVal = item.text;
item.dtStroke = item.fontStroke;
item.alarmType = '正常';
}
if (item.category === 'nameCase') {
item.dtFillColor = item.fillColor;
......
......@@ -9,8 +9,8 @@ import { Button } from 'antd';
import PandaConfiguration from '../index';
// import PandaConfigurationView from '../../es/index';
const Demo = () => {
const [name, setName] = useState('水厂工艺流程段');
const [devices, setDevices] = useState('EQZT00000008');
const [name, setName] = useState('泵房报警展示');
const [devices, setDevices] = useState('EGBF00000039');
const [messaged, setMessaged] = useState({
age: '运行监控1',
});
......@@ -59,18 +59,18 @@ export default Demo;
const globalConfig = {
token: 'a1372ef0ce7b4e4884d31cfd99fe92f6',
mqtt_iotIP: 'emqttd10.panda-water.cn:443',
mqtt_iotIP: '192.168.10.174:8083',
mqtt_path: '/mqtt',
mqtt_IsSSL: true,
mqtt_site_code: 'site_dc8302ni',
mqtt_IsSSL: false,
mqtt_site_code: 'site_dv4034ma',
mqtt_mess: {
MessageLevel: '1.0',
TcpIP: 'emqttd10.panda-water.cn',
TcpPort: 443,
site_code: 'site_dc8302ni',
TcpIP: '192.168.10.174',
TcpPort: 8083,
site_code: 'site_dv4034ma',
},
userInfo: {
LocalSite: 'site_dc8302ni',
LocalSite: 'site_dv4034ma',
site: '',
},
};
/*
* @Author: ljiwen
* @Date: 2025-01-10 16:10:26
* @Description:
* @FilePath: \wisdom-components\packages\extend-components\EC_ConfigurationView\src\js\icons.js
*/
const svgIcons = {
warning:
'M21.171 15.398l-5.912-9.854c-0.776-1.293-1.963-2.033-3.259-2.033s-2.483 0.74-3.259 2.031l-5.912 9.856c-0.786 1.309-0.872 2.705-0.235 3.83 0.636 1.126 1.878 1.772 3.406 1.772h12c1.528 0 2.77-0.646 3.406-1.771 0.637-1.125 0.551-2.521-0.235-3.831zM12 17.549c-0.854 0-1.55-0.695-1.55-1.549s0.695-1.551 1.55-1.551 1.55 0.696 1.55 1.551c0 0.854-0.696 1.549-1.55 1.549zM13.633 10.125c-0.011 0.031-1.401 3.468-1.401 3.468-0.038 0.094-0.13 0.156-0.231 0.156s-0.193-0.062-0.231-0.156l-1.391-3.438c-0.090-0.233-0.129-0.443-0.129-0.655 0-0.965 0.785-1.75 1.75-1.75s1.75 0.785 1.75 1.75c0 0.212-0.039 0.422-0.117 0.625z',
'warning-outline':
'M12 5.511c0.561 0 1.119 0.354 1.544 1.062l5.912 9.854c0.851 1.415 0.194 2.573-1.456 2.573h-12c-1.65 0-2.307-1.159-1.456-2.573l5.912-9.854c0.425-0.708 0.983-1.062 1.544-1.062M12 3.511c-1.296 0-2.482 0.74-3.259 2.031l-5.912 9.856c-0.786 1.309-0.872 2.705-0.235 3.83s1.879 1.772 3.406 1.772h12c1.527 0 2.77-0.646 3.406-1.771s0.551-2.521-0.235-3.83l-5.912-9.854c-0.777-1.294-1.963-2.034-3.259-2.034z' +
'M13.3 16c0 0.718-0.582 1.3-1.3 1.3s-1.3-0.582-1.3-1.3c0-0.718 0.582-1.3 1.3-1.3s1.3 0.582 1.3 1.3z' +
'M13.5 10c0-0.83-0.671-1.5-1.5-1.5s-1.5 0.67-1.5 1.5c0 0.199 0.041 0.389 0.111 0.562 0.554 1.376 1.389 3.438 1.389 3.438s0.835-2.062 1.391-3.438c0.068-0.173 0.109-0.363 0.109-0.562z',
};
export default svgIcons;
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