Browse Source

组网鉴权

dev
wenlele 1 year ago
parent
commit
616516863f
  1. 24
      api/config.js
  2. 2
      web-network/client/src/index.js
  3. 79
      web-network/client/src/sections/auth/containers/login.js
  4. 40
      web-network/client/src/sections/network/actions/network.js
  5. 6
      web-network/client/src/sections/network/components/device-tree/equipment-option.js
  6. 6
      web-network/client/src/sections/network/components/device-tree/index.js
  7. 18
      web-network/client/src/sections/network/components/device-tree/zuwang-main.js
  8. 32
      web-network/client/src/sections/network/containers/device-monitor.js
  9. 28
      web-network/client/src/sections/network/containers/tableShow.js
  10. 4
      web/client/src/sections/analysis/containers/network.jsx

24
api/config.js

@ -240,17 +240,19 @@ const product = {
{ p: '/project/group/:groupId/detail', o: 'GET' },
{ p: '/project/workOrders/repairRank', o: 'GET' },
{ p: '/project/workOrders', o: 'GET' },
{ p: '/organizations/:pepProjectId/struc', o: 'GET' },
{ p: '/things/:iotaThingId/deploys', o: 'GET' },
{ p: '/meta/things/:iotaThingId/devices', o: 'GET' },
{ p: '/metrics/things/:iotaThingId/devices/link_status', o: 'GET' },
{ p: '/things/:iotaThingId/deploy', o: 'GET' },
{ p: '/sensors/last/data', o: 'POST' },
{ p: '/meta/things/:iotaThingId/devices', o: 'GET' },
{ p: '/devices/alarms', o: 'POST' },
{ p: '/devices/cardStatus', o: 'POST' },
{ p: '/metrics/devices/:deviceId/link_status', o: 'GET' },
{ p: '/device/:deviceId/alarms', o: 'GET' },
// { p: '/organizations/:pepProjectId/struc', o: 'GET' },
// { p: '/things/:iotaThingId/deploys', o: 'GET' },
// { p: '/meta/things/:iotaThingId/devices', o: 'GET' },
// { p: '/metrics/things/:iotaThingId/devices/link_status', o: 'GET' },
// { p: '/things/:iotaThingId/deploy', o: 'GET' },
// { p: '/sensors/last/data', o: 'POST' },
// { p: '/meta/things/:iotaThingId/devices', o: 'GET' },
// { p: '/devices/alarms', o: 'POST' },
// { p: '/devices/cardStatus', o: 'POST' },
// { p: '/metrics/devices/:deviceId/link_status', o: 'GET' },
// { p: '/device/:deviceId/alarms', o: 'GET' },
], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由

2
web-network/client/src/index.js

@ -4,4 +4,4 @@ import React from 'react';
import { render } from 'react-dom';
import App from './app';
render((<App projectName="南昌县智慧交通监管系统" />), document.getElementById('App'));
render((<App projectName="运维组网" />), document.getElementById('App'));

79
web-network/client/src/sections/auth/containers/login.js

@ -73,45 +73,48 @@ const Login = props => {
return (
<div className='login'>
{/* <div className='left'></div> */}
<div className='right'>
<div className='loginBox'>
<h1>南昌县智慧交通监管系统</h1>
<Form onKeyDown={enterHandler}>
<FormItem>
<div className='loginFormTit'>用户名</div>
<Input
className='loginInp'
type="text"
value={username}
maxlength={11}
onChange={e => {
//('e.target.value', e.target.value)
setUserName(e.target.value)
setInputChanged(true)
}}
/>
</FormItem>
<div className='loginFormTit'>密码</div>
<FormItem>
<Input
className='loginInp'
type="password"
value={password}
onChange={e => {
//console.log('setPassword', e.target.value)
setPassword(e.target.value)
setInputChanged(true)
}}
/>
</FormItem>
</Form>
<Button type="primary" className='loginBtn' loading={isRequesting} onClick={handleLogin}>登录</Button>
</div>
</div>
<div>
{"{ token : 未生效,请刷新页面}"}
</div>
// <div className='login'>
// {/* <div className='left'></div> */}
// <div className='right'>
// <div className='loginBox'>
// <h1>南昌县智慧交通监管系统</h1>
// <Form onKeyDown={enterHandler}>
// <FormItem>
// <div className='loginFormTit'>用户名</div>
// <Input
// className='loginInp'
// type="text"
// value={username}
// maxlength={11}
// onChange={e => {
// //('e.target.value', e.target.value)
// setUserName(e.target.value)
// setInputChanged(true)
// }}
// />
// </FormItem>
// <div className='loginFormTit'>密码</div>
// <FormItem>
// <Input
// className='loginInp'
// type="password"
// value={password}
// onChange={e => {
// //console.log('setPassword', e.target.value)
// setPassword(e.target.value)
// setInputChanged(true)
// }}
// />
// </FormItem>
// </Form>
// <Button type="primary" className='loginBtn' loading={isRequesting} onClick={handleLogin}>登录</Button>
// </div>
// </div>
// </div>
);
}

40
web-network/client/src/sections/network/actions/network.js

@ -4,84 +4,84 @@ import { basicAction } from '@peace/utils';
import { ApiTable } from '$utils';
export function getOrganizationsStruc (id) {
export function getOrganizationsStruc (id, token) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_ORGANIZATIONS_STRUC',
url: `${ApiTable.organizationsStruc.replace('{pepProjectId}', id)}`,
url: `${ApiTable.organizationsStruc.replace('{pepProjectId}', id)}?token=${token}`,
msg: { error: '获取项目下的结构物信息失败' },
reducer: { name: 'organizationsStruc' }
})
}
export function getThingsDeploy (id) {
export function getThingsDeploy (id, token) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_THINGS_DEPLOY',
url: `${ApiTable.thingsDeploy.replace('{iotaThingId}', id)}`,
url: `${ApiTable.thingsDeploy.replace('{iotaThingId}', id)}?token=${token}`,
msg: { error: '获取设备部署信息失败' },
reducer: { name: 'deviceList' }
})
}
export function getDeviceMetaDeployed (id) {
export function getDeviceMetaDeployed (id, token) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_DEVIC_META_DEPLOYED',
url: `${ApiTable.deviceMetaDeployed.replace('{iotaThingId}', id)}`,
url: `${ApiTable.deviceMetaDeployed.replace('{iotaThingId}', id)}?token=${token}`,
msg: { error: '获取部署设备原型失败' },
reducer: { name: 'deviceMeta' }
})
}
export function getIotaThingsLlinkStatus (id) {
export function getIotaThingsLlinkStatus (id, token) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_IOTA_ThINGS_LINK_STATUS',
url: `${ApiTable.getIotaThingsLlinkStatus.replace('{iotaThingId}', id)}`,
url: `${ApiTable.getIotaThingsLlinkStatus.replace('{iotaThingId}', id)}?token=${token}`,
msg: { error: '获取设备在线状态/以结构物id集体获取失败' },
reducer: { name: '' }
})
}
export function findDeviceMetaDeployed (id) {
export function findDeviceMetaDeployed (id, token) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'FIND_DEVICE_META_DEPLOYED',
url: `${ApiTable.findDeviceMetaDeployed.replace('{iotaThingId}', id)}`,
url: `${ApiTable.findDeviceMetaDeployed.replace('{iotaThingId}', id)}?token=${token}`,
msg: { error: '获取单个结构物的设备信息失败' },
reducer: { name: 'deviceMetaDeployed', params: { noClear: true } },
})
}
export function findSensorLastData (data) {
export function findSensorLastData (data, token) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'FIND_SENSOR_LAST_DATA',
url: `${ApiTable.findSensorLastData}`,
url: `${ApiTable.findSensorLastData}?token=${token}`,
msg: { error: '原始数据查询失败' },
reducer: { name: 'sensorLastData' }
})
}
export function getDevicesAlarms (deviceIds, query) {
export function getDevicesAlarms (deviceIds, query, token) {
return dispatch => basicAction({
type: 'post',
dispatch: dispatch,
data: deviceIds,
query: query,
actionType: 'REQUEST_POST_DEVICES_ALARMS',
url: `${ApiTable.getDevicesAlarms}?state=new`,
url: `${ApiTable.getDevicesAlarms}?state=new&token=${token}`,
msg: {
error: '获取设备告警信息失败'
},
@ -92,13 +92,13 @@ export function getDevicesAlarms (deviceIds, query) {
}
export function findDevicesCardStatus (deviceIds) {
export function findDevicesCardStatus (deviceIds, token) {
return dispatch => basicAction({
type: 'post',
dispatch: dispatch,
data: deviceIds,
actionType: 'FIND_DEVICES_CARD_STATUS',
url: `${ApiTable.findDevicesCardStatus}`,
url: `${ApiTable.findDevicesCardStatus}?token=${token}`,
msg: {
error: '获取物联网卡信息失败'
},
@ -108,25 +108,25 @@ export function findDevicesCardStatus (deviceIds) {
});
}
export function getDevicesLlinkStatus (id) {
export function getDevicesLlinkStatus (id, token) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_DEVICES_LINK_STATUS',
url: `${ApiTable.getDevicesLlinkStatus.replace('{deviceId}', id)}`,
url: `${ApiTable.getDevicesLlinkStatus.replace('{deviceId}', id)}?token=${token}`,
msg: { error: '获取设备在线状态/以设备id单个获取' },
reducer: { name: '' }
})
}
export function findAlarmsDevice (deviceIds, query) {
export function findAlarmsDevice (deviceIds, query, token) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
query: query,
actionType: 'GET_FIND_ALARM_DEVICES',
url: `device/${deviceIds}/alarms`,
url: `device/${deviceIds}/alarms?token=${token}`,
msg: {
error: '获取设备告警信息失败'
},

6
web-network/client/src/sections/network/components/device-tree/equipment-option.js

@ -13,7 +13,7 @@ import { Request } from '@peace/utils'
const TabPane = Tabs.TabPane;
export default ({ ...props }) => {
const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch, actions } = props;
const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch, actions, token } = props;
const { analysis } = actions
const [linkState, setLinkState] = useSafeState(null);
@ -31,14 +31,14 @@ export default ({ ...props }) => {
if (info?.device?.id && info.device.id != currentDeviceId) {
setCurrentDeviceId(info.device.id);
setActiveKey('1');
dispatch(analysis.getDevicesLlinkStatus(info?.device?.id)).then(res => {
dispatch(analysis.getDevicesLlinkStatus(info?.device?.id, token)).then(res => {
if (res.success) {
setLinkState(res.payload?.data?.status)
}
})
dispatch(analysis.findAlarmsDevice(info?.device?.id, { limit: 5 })).then(res => {
dispatch(analysis.findAlarmsDevice(info?.device?.id, { limit: 5 }, token)).then(res => {
if (res.success) {
setAlarmMsg({ new: res.payload?.data?.new || [], history: res.payload?.data?.history || [] })
}

6
web-network/client/src/sections/network/components/device-tree/index.js

@ -17,7 +17,7 @@ const { ModifyEquipmentNetworking } = AuthorizationCode;
export default function ({ ...props }) {
const {
dispatch,actions, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct,
dispatch, actions, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct, token
} = props;
const [g6TreeDirection, setG6TreeDirection] = useSafeState('TB');
const [devices, setDevices] = useSafeState(null);
@ -279,6 +279,9 @@ export default function ({ ...props }) {
foldAllG6ToCenter={foldAllG6ToCenter}
resetFoldAllG6ToCenter={resetFoldAllG6ToCenter}
g6TreeDirection={g6TreeDirection}
token={token}
dispatch={dispatch}
actions={actions}
/>
)
}
@ -306,6 +309,7 @@ export default function ({ ...props }) {
height={containerHeight}
dispatch={dispatch}
actions={actions}
token={token}
/>
</Drawer>
</div>

18
web-network/client/src/sections/network/components/device-tree/zuwang-main.js

@ -19,7 +19,7 @@ export default function ({ ...props }) {
const {
struct, data, resetFoldAllG6ToCenter, foldAllG6ToCenter, g6TreeDirection, emitChange, emitDataChange_,
width, height, collapseAll, collapsed, expanded, expandAll, changeFinish, targetNode, inputSearching, setInputSearching,
onCollapse, handleNodeEnter, handelNodeClick,
onCollapse, handleNodeEnter, handelNodeClick, token, dispatch, actions
} = props;
const [isGetLinkStateDone, { setTrue, setFalse }] = useBoolean(false);
const [devicesLinkState, setDevicesLinkState] = useSafeState(null);
@ -30,28 +30,28 @@ export default function ({ ...props }) {
const [lastClickNodeKey, setLastClickNodeKey] = useSafeState(null);
const [disCheckedKeys, setDisCheckedKeys] = useSafeState([]);
let intervalLinkStatus = null;
const { analysis } = actions
// const da = useThingsLinkStatus(struct?.iotaThingId);
const getThingsLinkStatus = (isCycle = false) => {
const iotaThingId = struct?.thingId;
if (iotaThingId) {
const url = ApiTable.getIotaThingsLlinkStatus.replace('{iotaThingId}', iotaThingId);
Request.get(url).then((res) => {
if (res.devices.length >= 0) {
setDevicesLinkState(res.devices);
dispatch(analysis.getIotaThingsLlinkStatus(iotaThingId, token)).then((res) => {
if (res.payload?.data?.devices.length >= 0) {
setDevicesLinkState(res.payload?.data?.devices || []);
} else {
intervalLinkStatus && clearInterval(intervalLinkStatus);
}
if (!isCycle) {
setTrue();
setTrue(true);
}
}, (error) => {
if (!isCycle) {
message.warning('设备在线状态获取失败');
setTrue();
message.warning('设备在线状态获取失败')
setTrue(true);
}
});
})
}
};
useEffect(() => {

32
web-network/client/src/sections/network/containers/device-monitor.js

@ -31,41 +31,23 @@ function DeviceMonitor ({ ...props }) {
let strucParam = JSON.parse((qs.parse(props.location?.search.slice(1)) || {})?.strucData)
const token = qs.parse(props.location?.search.slice(1))?.key
useEffect(() => {
if (strucParam?.thingId) {
dispatch(analysis.getThingsDeploy(strucParam?.thingId)).then(res => {
console.log(3213, res);
dispatch(analysis.getThingsDeploy(strucParam?.thingId, token)).then(res => {
if (res.success) {
const instances = res?.payload?.data?.instances;
if (instances) {
const deviceIds = Object.keys(instances).filter((k) => instances[k]?.type == 's.d');
dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }));
dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }, token));
}
}
})
dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId))
dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId, token))
}
}, []);
useEffect(() => {
if (selectStructure && myStructList?.length > 0) {
const curStructure = myStructList.find((v) => v.id === selectStructure);
if (curStructure) {
// dispatch(actions.dataMonitor.getStationList(curStructure?.id));
// dispatch(actions.dataMonitor.getDeviceList(curStructure?.iotaThingId)).then((res) => {
// if (res.success) {
// const instances = res?.payload?.data?.instances;
// if (instances) {
// const deviceIds = Object.keys(instances).filter((k) => instances[k]?.type == 's.d');
// dispatch(actions.dataMonitor.getDevicesAlarms(deviceIds, { limit: 5 }));
// }
// }
// });
// dispatch(actions.dataMonitor.getDimensionsList(curStructure?.iotaThingId));
}
}
}, [selectStructure]);
// 展示切换
const onExtraChange = (e) => {
@ -149,10 +131,12 @@ function DeviceMonitor ({ ...props }) {
struct={strucParam}
clientHeight={clientHeight}
clientWidth={clientWidth}
token={token}
/>
) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
: (
<TableShow thingId={strucParam.thingId} project={strucParam.projectId} />
<TableShow thingId={strucParam.thingId} project={strucParam.projectId} token={token} />
)
}
</ProCard>

28
web-network/client/src/sections/network/containers/tableShow.js

@ -1,11 +1,11 @@
import React, { useEffect, useState, useRef, useMemo } from 'react'
import { connect } from 'react-redux'
import { Spin, Card, CardGroup, Form,Select ,Input, Button, Table, Pagination, Tooltip } from 'antd'
import { Spin, Card, CardGroup, Form, Select, Input, Button, Table, Pagination, Tooltip } from 'antd'
import ExportData from '../components/export-data'
import moment from 'moment'
const Network = props => {
const { dispatch, actions, user, clientHeight, thingId, deviceListAlarms, devicesCardStatusList, project } = props
const { dispatch, actions, user, clientHeight, thingId, deviceListAlarms, devicesCardStatusList, project, token } = props
const { analysis } = actions
const form = useRef() //表单
const [deployData, setDeployData] = useState([])
@ -39,7 +39,7 @@ const Network = props => {
useEffect(() => {
if (thingId) {
let dataList = []
dispatch(analysis.getThingsDeploy(thingId)).then(rs => {
dispatch(analysis.getThingsDeploy(thingId, token)).then(rs => {
if (rs.success) {
setDeployData(rs.payload.data)
dataList = rs.payload.data
@ -62,7 +62,7 @@ const Network = props => {
})
}
dispatch(analysis.findDeviceMetaDeployed(thingId)).then(res => {
dispatch(analysis.findDeviceMetaDeployed(thingId, token)).then(res => {
if (res.success) {
setDeviceMetasDeployed(res.payload.data)
const deviceMetaDeployed = res.payload.data
@ -91,8 +91,8 @@ const Network = props => {
sensorsId.push(id)
}
}
dispatch(analysis.getDevicesAlarms(deviceIds , { limit: 5 }))
dispatch(analysis.findDevicesCardStatus({ deviceIds: alarmSensorId }))
dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }, token))
dispatch(analysis.findDevicesCardStatus({ deviceIds: alarmSensorId }, token))
setSensorsDataItems(sensorsDataItems)
setSensorId(sensorsId)
setDeviceData(da)
@ -105,7 +105,7 @@ const Network = props => {
}, [thingId])
useEffect(async () => {
if (sensorId && sensorId.length && sensorsDataItems) {
const rs = await dispatch(analysis.findSensorLastData(sensorId))
const rs = await dispatch(analysis.findSensorLastData(sensorId, token))
const tableData = []
if (rs.success) {
rs.payload.data.forEach(sd => {
@ -149,7 +149,7 @@ const Network = props => {
}
}, [sensorId])
useEffect(() => {
if (deviceData && deviceData.length ) {
if (deviceData && deviceData.length) {
const dataD = deviceData?.map(p => {
const objRslt = tableData?.find(q => q.sensorId == p.sensorId)
return {
@ -190,15 +190,15 @@ const Network = props => {
// const lastDataCopy=useMemo(()=>{
// return lastData
// },[thingId])
const scroll = useMemo(() => ({ y:clientHeight-600+175+175 }), [])
const scroll = useMemo(() => ({ y: clientHeight - 600 + 175 + 175 }), [])
//名称回调事件
const inputChange = e => {
setSearchName(e.target.value)
}
//选择设备类型下拉框回调
const selectChange = e => {
let rslt=typeList.find(f => f.value == e)
setSearchType(rslt?rslt.label:undefined)
let rslt = typeList.find(f => f.value == e)
setSearchType(rslt ? rslt.label : undefined)
}
//查询事件回调
@ -206,7 +206,7 @@ const Network = props => {
setLastData(
lastDataCopy.filter(f =>
(!searchName || f.sensorName.includes(searchName)) &&
(!searchType|| f.deviceType===searchType)
(!searchType || f.deviceType === searchType)
)
)
}
@ -283,7 +283,7 @@ const Network = props => {
pure
allowClear
style={{ width: 260, marginRight: 12 }}
onChange={inputChange}/>
onChange={inputChange} />
<Select options={typeList} label='设备类型'
pure
allowClear
@ -318,7 +318,7 @@ const Network = props => {
)
}
function mapStateToProps(state) {
function mapStateToProps (state) {
const { auth, global, members, webSocket, deviceListAlarms, devicesCardStatus } = state
return {
user: auth.user,

4
web/client/src/sections/analysis/containers/network.jsx

@ -62,7 +62,6 @@ const Network = ({
useEffect(() => {
// iframe
const iframe = document.getElementById('myIframe');
console.log(4324, iframe);
if (iframe) {
// iframeload
iframe.addEventListener('load', function () {
@ -128,7 +127,6 @@ const Network = ({
<Spin
// style={{ }}
childStyle={{ width: "100%", height: clientHeight - 188 }}
spinning={spinning}>
<div id='show' style={{ width: "100%", height: "100%" }}>
@ -139,7 +137,7 @@ const Network = ({
height: '100%',
zIndex: 7, border: 0
}}
src={`${networkWeb}/network?strucData=${JSON.stringify(organizationsStruc?.find(v => v.thingId == thingId) || {})}`}
src={`${networkWeb}/network?key=${user?.token}&strucData=${JSON.stringify(organizationsStruc?.find(v => v.thingId == thingId) || {})}`}
allowFullScreen
>
<p>你的浏览器不支持 iframe </p>

Loading…
Cancel
Save