Commit 819a78e5 authored by 李纪文's avatar 李纪文

feat: mqtt订阅增加账户信息

parent 0f55a0f4
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
}, },
"dependencies": { "dependencies": {
"@babel/plugin-proposal-private-methods": "^7.18.6", "@babel/plugin-proposal-private-methods": "^7.18.6",
"@wisdom-components/VmsVideo": "1.2.27",
"@wisdom-components/basictable": "1.5.29", "@wisdom-components/basictable": "1.5.29",
"@wisdom-components/ec_historyview": "^1.4.3", "@wisdom-components/ec_historyview": "^1.4.3",
"@wisdom-components/empty": "^1.3.9", "@wisdom-components/empty": "^1.3.9",
...@@ -153,12 +154,12 @@ ...@@ -153,12 +154,12 @@
"@wisdom-components/loadbox": "1.1.4", "@wisdom-components/loadbox": "1.1.4",
"@wisdom-components/timerangepicker": "^1.3.4", "@wisdom-components/timerangepicker": "^1.3.4",
"@wisdom-components/videoslidermodal": "1.1.2", "@wisdom-components/videoslidermodal": "1.1.2",
"@wisdom-components/VmsVideo": "1.2.27",
"@wisdom-utils/utils": "0.0.46", "@wisdom-utils/utils": "0.0.46",
"antd-mobile": "5.10.4", "antd-mobile": "5.10.4",
"axios": "^1.4.0", "axios": "^1.4.0",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"crypto-js": "^4.2.0",
"echarts": "^5.4.0", "echarts": "^5.4.0",
"echarts-for-react": "^3.0.2", "echarts-for-react": "^3.0.2",
"ezuikit-js": "^7.6.3", "ezuikit-js": "^7.6.3",
......
...@@ -9,6 +9,8 @@ class MqttDemo extends React.Component { ...@@ -9,6 +9,8 @@ class MqttDemo extends React.Component {
flag: true, flag: true,
}; };
this.mqttView = new PandaMqttView({ this.mqttView = new PandaMqttView({
userName: 'panda',
password: '6FC08E462A0C87953CD3DB4706462E4B',
mqttIP: 'emqttd10.panda-water.cn:443', mqttIP: 'emqttd10.panda-water.cn:443',
mqttPath: '/mqtt', mqttPath: '/mqtt',
mqttSsl: true, mqttSsl: true,
......
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import MqttClient from 'mqtt-client'; import MqttClient from 'mqtt-client';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import CryptoJS from 'crypto-js';
class MqttView { class MqttView {
constructor(props) { constructor(props) {
this.userName = props.userName;
this.password = props.password;
this.mqttIP = props.mqttIP; this.mqttIP = props.mqttIP;
this.mqttPath = props.mqttPath; this.mqttPath = props.mqttPath;
this.mqttSsl = props.mqttSsl; this.mqttSsl = props.mqttSsl;
...@@ -24,8 +27,8 @@ class MqttView { ...@@ -24,8 +27,8 @@ class MqttView {
cleanSession = true, cleanSession = true,
ssl = this.mqttSsl, ssl = this.mqttSsl,
path = this.mqttPath, path = this.mqttPath,
userName = 'admin', userName = this.userName || 'admin',
password = 'public'; password = this.password ? getDecryptedValue(this.password) : 'public';
const queryStr = this.toQueryString(this.params); const queryStr = this.toQueryString(this.params);
this.saveWaCount = 0; this.saveWaCount = 0;
this.saveWaClient = new MqttClient.Client( this.saveWaClient = new MqttClient.Client(
...@@ -167,6 +170,8 @@ class MqttView { ...@@ -167,6 +170,8 @@ class MqttView {
} }
MqttView.propTypes = { MqttView.propTypes = {
userName: PropTypes.string,
password: PropTypes.string,
mqttIP: PropTypes.string, mqttIP: PropTypes.string,
mqttPath: PropTypes.string, mqttPath: PropTypes.string,
mqttSsl: PropTypes.bool, mqttSsl: PropTypes.bool,
...@@ -178,6 +183,8 @@ MqttView.propTypes = { ...@@ -178,6 +183,8 @@ MqttView.propTypes = {
}; };
MqttView.defaultProps = { MqttView.defaultProps = {
userName: 'admin',
password: 'public',
mqttIP: '', mqttIP: '',
mqttPath: '/mqtt', mqttPath: '/mqtt',
mqttSsl: false, mqttSsl: false,
...@@ -188,4 +195,38 @@ MqttView.defaultProps = { ...@@ -188,4 +195,38 @@ MqttView.defaultProps = {
controlback: () => {}, controlback: () => {},
}; };
// 解密
export const getDecryptedValue = (encryptedText) => {
const AESKey = '1p2a3n4d5a6o7m8s9a10n1e2t3c4o5re'; //32位
const AES_IV = '1234567890000000'; //16位
const key = CryptoJS.enc.Utf8.parse(AESKey);
const iv = CryptoJS.enc.Utf8.parse(AES_IV);
// 解密
const decrypted = CryptoJS.AES.decrypt(
{ ciphertext: CryptoJS.enc.Hex.parse(encryptedText) },
key,
{ iv: iv },
);
// 转换为明文
const plaintext = decrypted.toString(CryptoJS.enc.Utf8);
return plaintext;
};
// 加密
export const getEncryptedValue = (password) => {
const AESKey = '1p2a3n4d5a6o7m8s9a10n1e2t3c4o5re'; //32位
const AES_IV = '1234567890000000'; //16位
const key = CryptoJS.enc.Utf8.parse(AESKey);
const iv = CryptoJS.enc.Utf8.parse(AES_IV);
const psd = CryptoJS.AES.encrypt(password, key, { iv: iv })
.ciphertext.toString(CryptoJS.enc.Hex)
.toUpperCase();
return psd;
};
export default MqttView; export default MqttView;
...@@ -995,6 +995,8 @@ const ConfigurationView = (props) => { ...@@ -995,6 +995,8 @@ const ConfigurationView = (props) => {
if ((DomRef && !DomRef.current) || !twoDom) return setNoInitial(true); if ((DomRef && !DomRef.current) || !twoDom) return setNoInitial(true);
mqttView = devicesCode.length mqttView = devicesCode.length
? new MqttView({ ? new MqttView({
userName: globalConfig?.mqtt_account || '',
password: globalConfig?.mqtt_password || '',
mqttIP: globalConfig.mqtt_iotIP, mqttIP: globalConfig.mqtt_iotIP,
mqttPath: globalConfig.mqtt_path, mqttPath: globalConfig.mqtt_path,
mqttSsl: globalConfig.mqtt_IsSSL, mqttSsl: globalConfig.mqtt_IsSSL,
......
...@@ -999,6 +999,8 @@ const ConfigurationView = (props) => { ...@@ -999,6 +999,8 @@ const ConfigurationView = (props) => {
if ((DomRef && !DomRef.current) || !twoDom) return setNoInitial(true); if ((DomRef && !DomRef.current) || !twoDom) return setNoInitial(true);
mqttView = devicesCode.length mqttView = devicesCode.length
? new MqttView({ ? new MqttView({
userName: globalConfig?.mqtt_account || '',
password: globalConfig?.mqtt_password || '',
mqttIP: globalConfig.mqtt_iotIP, mqttIP: globalConfig.mqtt_iotIP,
mqttPath: globalConfig.mqtt_path, mqttPath: globalConfig.mqtt_path,
mqttSsl: globalConfig.mqtt_IsSSL, mqttSsl: globalConfig.mqtt_IsSSL,
......
...@@ -3,7 +3,7 @@ import { Button } from 'antd'; ...@@ -3,7 +3,7 @@ import { Button } from 'antd';
import PandaConfiguration from '../index'; import PandaConfiguration from '../index';
// import PandaConfigurationView from '../../es/index'; // import PandaConfigurationView from '../../es/index';
const Demo = () => { const Demo = () => {
const [name, setName] = useState('cs0320'); const [name, setName] = useState('水厂工艺流程段');
const [devices, setDevices] = useState('EQZT00000008'); const [devices, setDevices] = useState('EQZT00000008');
const [messaged, setMessaged] = useState({ const [messaged, setMessaged] = useState({
age: '运行监控1', age: '运行监控1',
...@@ -12,12 +12,12 @@ const Demo = () => { ...@@ -12,12 +12,12 @@ const Demo = () => {
<> <>
<div style={{ width: '100%', height: '600px', background: '#242835' }}> <div style={{ width: '100%', height: '600px', background: '#242835' }}>
<PandaConfiguration <PandaConfiguration
// name={name} name={name}
// devices={devices.split(',')} devices={devices.split(',')}
name={'崇左丽江水厂原水泵房'} // name={'崇左丽江水厂原水泵房'}
devices={'EQZT00000007,CPBA00000001,CPAA00000001,EQZT00000008,CPDA00000001,CPAD00000001,LJSC00000002,EQZT00000005,EQZT00000004,EQZT00000002,EQZT00000003'.split( // devices={'EQZT00000007,CPBA00000001,CPAA00000001,EQZT00000008,CPDA00000001,CPAD00000001,LJSC00000002,EQZT00000005,EQZT00000004,EQZT00000002,EQZT00000003'.split(
',', // ',',
)} // )}
// name={'丽江水厂原水提升泵D单元'} // name={'丽江水厂原水提升泵D单元'}
// devices={'CPAA00000001, CPAD00000001, LJSC00000002'.split(',')} // devices={'CPAA00000001, CPAD00000001, LJSC00000002'.split(',')}
config={globalConfig} config={globalConfig}
...@@ -52,6 +52,8 @@ const Demo = () => { ...@@ -52,6 +52,8 @@ const Demo = () => {
export default Demo; export default Demo;
const globalConfig = { const globalConfig = {
mqtt_account: 'panda',
mqtt_password: '6FC08E462A0C87953CD3DB4706462E4B',
token: 'a1372ef0ce7b4e4884d31cfd99fe92f6', token: 'a1372ef0ce7b4e4884d31cfd99fe92f6',
mqtt_iotIP: 'emqttd10.panda-water.cn:443', mqtt_iotIP: 'emqttd10.panda-water.cn:443',
mqtt_path: '/mqtt', mqtt_path: '/mqtt',
......
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