wenlele 1 year ago
parent
commit
7f01abb414
  1. 485
      web/client/src/sections/firmwareUpgrade/containers/deviceManagement.jsx

485
web/client/src/sections/firmwareUpgrade/containers/deviceManagement.jsx

@ -1,254 +1,255 @@
import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux';
import { Button, Table, Popconfirm, Pagination, Select, Input, Switch, Notification, Progress } from '@douyinfe/semi-ui';
import { Button, Table, Popconfirm, Pagination,Select,Input,Switch,Notification,Progress } from '@douyinfe/semi-ui';
import moment from 'moment'
import FirmwareListModal from '../components/firmwareListModal';
const DeviceManagement = (props) => {
const { actions, dispatch, pepProjectId, user } = props
const { firmwareUpgrade } = actions
const [updataButtonDisabled, setUpdataButtonDisabled] = useState(true)//
const [firmwareModalVis, setFirmwareModalVis] = useState(false)
const [strucAndDeviceType, setStrucAndDeviceType] = useState([])//
const [struc, setStruc] = useState([])//
const [deviceType, setDeviceType] = useState([])//optionList
const [data, setData] = useState([])//
const [thingIds, setThingIds] = useState([])//id
const [defaultVal, setDefaultVal] = useState('')//id
const [thingId, setThingId] = useState()//id
const [searchVal, setSearchVal] = useState()//
const [recordRow, setRecordRow] = useState()
const [selectedRows, setSelectedRows] = useState([])//key
const [selectdR, setSelectedR] = useState([])//
const [vData, setVData] = useState([])//
const [id, setId] = useState()//
const getData = (data) => {
dispatch(firmwareUpgrade.getThingMessages(data)).then((res) => {
if (res.success) {
setData(res.payload.data)
}
})
}
useEffect(() => {
//
dispatch(firmwareUpgrade.getStruc({ pepProjectId })).then((res) => {
if (res.success) {
setStrucAndDeviceType(res.payload.data)
setStruc(res.payload.data?.map(item => {
return { label: item.strucName, value: item.thingId }
}))
setThingIds(res.payload.data?.map(item => item.thingId)?.join(',') || '')
}
})
// console.log('xxxx111',user)
dispatch(firmwareUpgrade.getFirmware()).then(res => {
if (res.success) setVData(res.payload.data)
})
}, [pepProjectId])
useEffect(() => {
if (thingIds && thingIds.length) {
const data = { thingIds: thingIds.split(',')[0] || '000' }//
setId(thingIds.split(',')[0])
getData(data)
}
}, [thingIds])
const structChange = value => {
setId(value)
clearSelectedRows()
setUpdataButtonDisabled(true)
const deviceTypeList = strucAndDeviceType?.find(item => item.thingId == value)?.deviceType?.map(child => {
return {
label: child.model,
value: child.id
}
}) || []
setDefaultVal('')
// console.log('event',deviceTypeList)
setDeviceType(deviceTypeList)
setThingId(value)
const data = { thingIds: value, device_meta_id: defaultVal }
getData(data)
};
const deviceTypeChange = value => {
setUpdataButtonDisabled(true)
clearSelectedRows()
setDefaultVal(value)
const data = { thingIds: thingId, device_meta_id: value }
getData(data)
// console.log(value,'event')
}
//
const clearHandler = () => {
setUpdataButtonDisabled(true)
clearSelectedRows()
const data = { thingIds }
getData(data)
}
//
const cleartypeHandler = () => {
setUpdataButtonDisabled(true)
clearSelectedRows()
setDefaultVal(null)
const data = { thingIds: thingId }
getData(data)
}
//
const searchHandler = () => {
if (!thingId && !defaultVal) {
const data = { thingIds }
getData(data)
} else {
const data = { thingIds: thingId, device_meta_id: defaultVal, searchVal }
getData(data)
}
}
const clearSelectedRows = () => {
setSelectedRows([]);
};
const rowSelection = {
selectedRowKeys: selectedRows, // keys
getCheckboxProps: record => ({
name: record.name,
}),
// onSelect: (record, selected) => {
// console.log(`select row: ${selected}`, record);
// },
onSelectAll: (selected, selectedRows) => {
setUpdataButtonDisabled(!selectedRows.every(item => selectedRows[0]?.deviceType === item.deviceType && item.switchStatus))
},
onChange: (selectedRowKeys, selectedRows) => {
setSelectedR(selectedRows)
setSelectedRows(selectedRowKeys)
// console.log('xxxx',selectedRows)
//
if (selectedRows && selectedRows.length === 0) {
setUpdataButtonDisabled(true)
}
//
if (selectedRows && selectedRows.length > 0) {
setUpdataButtonDisabled(!selectedRows.every(item => selectedRows[0].deviceType === item.deviceType && item.switchStatus))
}
},
};
let columns = [{
title: '序号',
render: (t, r, i) => {
return i + 1;
}
}, {
title: '设备名称',
dataIndex: 'deviceName'
}, {
title: '设备型号',
dataIndex: 'deviceType'
},
{
title: '固件名称',
dataIndex: 'firmwareName'
},
{
title: '固件版本号',
dataIndex: 'firmwareNo'
},
{
title: '升级状态',
render: (_, record) => {
return record.status !== '未升级' && record.status !== '升级成功' ? <Progress percent={parseFloat(record.updatePercentage || 0)} showInfo></Progress> : record.status
}
},
{
title: '升级开关状态',
dataIndex: 'switchStatus',
render: (_, record) => {
return <Switch disabled defaultChecked={record.switchStatus}></Switch>
}
},
{
title: '操作',
render: (_, record) => {
return <div>
<Button type="secondary" onClick={() => {
if (record.switchStatus) {
setFirmwareModalVis(true)
setRecordRow([record])
} else {
Notification.info({
title: '提示',
content: '请到安心云平台打开升级开关后进行升级。',
duration: 3,
})
}
if (record.status !== '未升级' && record.status !== '升级成功') {
Notification.info({
title: '提示',
content: '该设备仍在升级中,请在完成升级后再操作。',
duration: 3,
})
}
}}>固件升级</Button>
</div>
}
}
]
return <><div style={{ background: '#FFFFFF', margin: '8px 12px', padding: '20px 20px 0px 20px' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<div style={{ display: 'flex', alignItems: 'center', marginRight: 30 }}>
<div style={{ width: 0, height: 20, borderLeft: '3px solid #005ABD', borderTop: '3px solid transparent', borderBottom: '3px solid transparent' }}></div>
<div style={{ fontFamily: "YouSheBiaoTiHei", fontSize: 24, color: '#101531', marginLeft: 8 }}>设备管理</div>
<div style={{ marginLeft: 6, fontSize: 12, color: '#969799', fontFamily: "DINExp", }}>Device Management</div>
</div>
<Select placeholder='请选择结构物' optionList={struc} filter showClear
onChange={structChange}
onClear={clearHandler}
value={id} //
style={{ width: 300, marginRight: 10 }}>
</Select>
<Select placeholder='请选择设备型号' value={defaultVal} optionList={deviceType}
onClear={cleartypeHandler}
onChange={deviceTypeChange}
filter
showClear
style={{ width: 300, marginRight: 10 }}></Select>
<Button style={{ marginRight: 10 }} type="secondary" disabled={updataButtonDisabled} onClick={() => {
setFirmwareModalVis(true);
setRecordRow(selectdR)
}}>固件升级</Button>
<Input placeholder='请输入设备名称' style={{ width: 300, marginRight: 10 }} onChange={(e) => { setSearchVal(e) }}></Input>
<Button style={{ marginRight: 10 }} type="secondary" theme='solid'
onClick={searchHandler}
>查询</Button>
const {actions,dispatch,pepProjectId,user}=props
const {firmwareUpgrade}=actions
const [updataButtonDisabled,setUpdataButtonDisabled]=useState(true)//
const [firmwareModalVis,setFirmwareModalVis]=useState(false)
const [strucAndDeviceType,setStrucAndDeviceType]=useState([])//
const [struc,setStruc]=useState([])//
const [deviceType,setDeviceType]=useState([])//optionList
const [data,setData]=useState([])//
const [thingIds,setThingIds]=useState([])//id
const [defaultVal,setDefaultVal]=useState('')//id
const [thingId,setThingId]=useState()//id
const [searchVal,setSearchVal]=useState()//
const [recordRow,setRecordRow]=useState()
const [selectedRows,setSelectedRows]=useState([])//key
const [selectdR,setSelectedR]=useState([])//
const [vData,setVData]=useState([])//
const [id,setId]=useState()//
const getData=(data)=>{
dispatch(firmwareUpgrade.getThingMessages(data)).then((res)=>{
if(res.success) {
setData(res.payload.data)
}
})
}
useEffect(()=>{
//
dispatch(firmwareUpgrade.getStruc({pepProjectId})).then((res)=>{
if(res.success) {
setStrucAndDeviceType( res.payload.data)
setStruc( res.payload.data?.map(item=>{
return {label:item.strucName,value:item.thingId}
}))
setThingIds(res.payload.data?.map(item=>item.thingId)?.join(',')||'')
}
})
// console.log('xxxx111',user)
dispatch(firmwareUpgrade.getFirmware()).then(res=>{
if(res.success) setVData(res.payload.data)
})
},[pepProjectId])
useEffect(()=>{
setData([])
setId(null)
if(thingIds&&thingIds.length){
const data={thingIds:thingIds.split(',')[0]||'000'}//
setId(thingIds.split(',')[0])
getData(data)
}
},[thingIds])
const structChange =value => {
setId(value)
clearSelectedRows()
setUpdataButtonDisabled(true)
const deviceTypeList= strucAndDeviceType?.find(item=>item.thingId==value)?.deviceType?.map(child=>{
return {
label:child.model,
value:child.id
}
})||[]
setDefaultVal('')
// console.log('event',deviceTypeList)
setDeviceType(deviceTypeList)
setThingId(value)
const data={thingIds:value,device_meta_id:defaultVal}
getData(data)
};
const deviceTypeChange=value=>{
setUpdataButtonDisabled(true)
clearSelectedRows()
setDefaultVal(value)
const data={thingIds:thingId,device_meta_id:value}
getData(data)
// console.log(value,'event')
}
//
const clearHandler=()=>{
setUpdataButtonDisabled(true)
clearSelectedRows()
const data={thingIds}
getData(data)
}
//
const cleartypeHandler=()=>{
setUpdataButtonDisabled(true)
clearSelectedRows()
setDefaultVal(null)
const data={thingIds:thingId}
getData(data)
}
//
const searchHandler=()=>{
if(!thingId&&!defaultVal){
const data={thingIds}
getData(data)
}else{
const data={thingIds:thingId,device_meta_id:defaultVal,searchVal}
getData(data)
}
}
const clearSelectedRows = () => {
setSelectedRows([]);
};
const rowSelection = {
selectedRowKeys: selectedRows, // keys
getCheckboxProps: record => ({
name: record.name,
}),
// onSelect: (record, selected) => {
// console.log(`select row: ${selected}`, record);
// },
onSelectAll: (selected, selectedRows) => {
setUpdataButtonDisabled(!selectedRows.every(item=>selectedRows[0]?.deviceType===item.deviceType&&item.switchStatus))
},
onChange: (selectedRowKeys, selectedRows) => {
setSelectedR(selectedRows)
setSelectedRows(selectedRowKeys)
// console.log('xxxx',selectedRows)
//
if(selectedRows&&selectedRows.length===0){
setUpdataButtonDisabled(true)
}
//
if(selectedRows&&selectedRows.length>0){
setUpdataButtonDisabled(!selectedRows.every(item=>selectedRows[0].deviceType===item.deviceType&&item.switchStatus))
}
},
};
let columns=[{
title: '序号',
render: (t, r, i) => {
return i + 1;
}
},{
title: '设备名称',
dataIndex: 'deviceName'
},{
title: '设备型号',
dataIndex: 'deviceType'
},
{
title: '固件名称',
dataIndex: 'firmwareName'
},
{
title: '固件版本号',
dataIndex: 'firmwareNo'
},
{
title: '升级状态',
render:(_,record)=>{
return record.status!=='未升级'&&record.status!=='升级成功'?<Progress percent={parseFloat(record.updatePercentage||0)} showInfo></Progress>:record.status
}
},
{
title: '升级开关状态',
dataIndex: 'switchStatus' ,
render:(_,record)=>{
return <Switch disabled defaultChecked={record.switchStatus}></Switch>
}
},
{
title: '操作',
render:(_,record)=>{
return <div>
<Button type="secondary" onClick={()=>{
if(record.switchStatus){
setFirmwareModalVis(true)
setRecordRow([record])
}else{
Notification.info({
title: '提示',
content: '请到安心云平台打开升级开关后进行升级。',
duration: 3,
})
}
if(record.status!=='未升级'&&record.status!=='升级成功'){
Notification.info({
title: '提示',
content: '该设备仍在升级中,请在完成升级后再操作。',
duration: 3,
})
}
}}>固件升级</Button>
</div>
}
}
]
return <><div style={{ background: '#FFFFFF', margin: '8px 12px', padding: '20px 20px 0px 20px' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<div style={{ display: 'flex', alignItems: 'center',marginRight:30 }}>
<div style={{ width: 0, height: 20, borderLeft: '3px solid #005ABD', borderTop: '3px solid transparent', borderBottom: '3px solid transparent' }}></div>
<div style={{ fontFamily: "YouSheBiaoTiHei", fontSize: 24, color: '#101531', marginLeft: 8 }}>设备管理</div>
<div style={{ marginLeft: 6, fontSize: 12, color: '#969799', fontFamily: "DINExp", }}>Device Management</div>
</div>
<Select placeholder='请选择结构物' optionList={struc} filter showClear
onChange={structChange}
onClear={clearHandler}
value={id} //
style={{ width:300,marginRight:10}}>
</Select>
<Select placeholder='请选择设备型号' value={defaultVal} optionList={deviceType}
onClear={cleartypeHandler}
onChange={deviceTypeChange}
filter
showClear
style={{ width:300,marginRight:10}}></Select>
<Button style={{marginRight:10}} type="secondary" disabled={updataButtonDisabled} onClick={()=>{
setFirmwareModalVis(true);
setRecordRow(selectdR)
}}>固件升级</Button>
<Input placeholder='请输入设备名称' style={{ width:300,marginRight:10}} onChange={(e)=>{setSearchVal(e)}}></Input>
<Button style={{marginRight:10}} type="secondary" theme='solid'
onClick={searchHandler}
>查询</Button>
</div>
<div style={{ marginTop: 10 }}>
<Table columns={columns} rowSelection={rowSelection} dataSource={data}></Table>
<FirmwareListModal vData={vData} versionData={data} modalVis={firmwareModalVis} recordRow={recordRow} onCancel={() => { setFirmwareModalVis(false); setRecordRow(null) }}></FirmwareListModal>
</div>
</div>
</>
<div style={{marginTop:10}}>
<Table columns={columns} rowSelection={rowSelection} dataSource={data}></Table>
<FirmwareListModal vData={vData} versionData={data} modalVis={firmwareModalVis} recordRow={recordRow} onCancel={()=>{setFirmwareModalVis(false);setRecordRow(null)}}></FirmwareListModal>
</div>
</div>
</>
}
function mapStateToProps (state) {
const { auth, global, getPush } = state;
console.log(222, global);
return {
loading: getPush.isRequesting,
user: auth.user,
actions: global.actions,
pepProjectId: global.pepProjectId
};
}
export default connect(mapStateToProps)(DeviceManagement);
const { auth, global, getPush } = state;
return {
loading: getPush.isRequesting,
user: auth.user,
actions: global.actions,
pepProjectId:global.pepProjectId
};
}
export default connect(mapStateToProps)(DeviceManagement);

Loading…
Cancel
Save