diff --git a/web/client/src/sections/firmwareUpgrade/containers/deviceManagement.jsx b/web/client/src/sections/firmwareUpgrade/containers/deviceManagement.jsx index a9b6091..05fcd9a 100644 --- a/web/client/src/sections/firmwareUpgrade/containers/deviceManagement.jsx +++ b/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 !== '升级成功' ? : record.status - } - }, - { - title: '升级开关状态', - dataIndex: 'switchStatus', - render: (_, record) => { - return - } - }, - { - title: '操作', - render: (_, record) => { - return
- -
- } - } - ] - return <>
-
-
-
-
设备管理
-
Device Management
-
- - - - { setSearchVal(e) }}> - + 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!=='升级成功'?:record.status + } + }, + { + title: '升级开关状态', + dataIndex: 'switchStatus' , + render:(_,record)=>{ + return + } + }, + { + title: '操作', + render:(_,record)=>{ + return
+ +
+ } + } + ] +return <>
+
+
+
+
设备管理
+
Device Management
+
+ + + + {setSearchVal(e)}}> + -
-
-
- { setFirmwareModalVis(false); setRecordRow(null) }}> -
- +
+
+ {setFirmwareModalVis(false);setRecordRow(null)}}> +
+
+ } 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); \ No newline at end of file + const { auth, global, getPush } = state; + return { + loading: getPush.isRequesting, + user: auth.user, + actions: global.actions, + pepProjectId:global.pepProjectId + }; + } + + export default connect(mapStateToProps)(DeviceManagement);