Files
fe_service_ebtp_frontend/src/pages/ElecEvaluation/Device/index.tsx

269 lines
7.6 KiB
TypeScript
Raw Normal View History

2022-08-23 18:02:47 +08:00
import React, { useState, useRef, useEffect } from 'react';
2022-08-25 15:08:48 +08:00
import { Button, Spin, Tabs, Tree} from 'antd';
2022-08-23 18:02:47 +08:00
import ProTable, { ActionType } from '@ant-design/pro-table';
2022-08-24 15:14:09 +08:00
import { deviceList, getplaceareaList, roomList } from './service';
2022-08-23 18:02:47 +08:00
import '@/assets/ld_style.less';
import { getURLInformation, isNotEmpty } from '@/utils/CommonUtils';
2022-08-24 15:14:09 +08:00
import ProCard from "@ant-design/pro-card";
2022-08-25 15:08:48 +08:00
import DeviceForm from './DeviceForm';
2022-08-23 18:02:47 +08:00
2022-08-24 15:14:09 +08:00
const deviceTypeEnum = {
'resource_door': { text: '门禁点' },
'resource_camera': { text: '监控点' },
'resource_nvr': { text: 'nvr' },
'resource_encodeDevice': { text: '编码设备' },
'resource_oneMachine': { text: '门禁一体机' },
}
const deviceStatusEnum = {
'online_0': { text: '离线' },
'online_1': { text: '在线' },
'online_9': { text: '无此设备' },
}
2022-08-23 18:02:47 +08:00
const Index: React.FC<{}> = () => {
const checkRelationRef = useRef<ActionType>(); //操作数据后刷新列表
2022-08-24 15:14:09 +08:00
const [treeData, setTreeData] = useState<any>();
const [treeId, setTreeId] = useState<any>();
2022-08-25 15:08:48 +08:00
const [updateVisible, setUpdateVisible] = useState<boolean>(false)
const [type, setType] = useState<any>();// 状态 编辑or 查看
const [deviceId, setDeviceId] = useState<any>("");//设备id
const [spin, spinSet] = useState<boolean>(false);//加载遮罩
const [updateChange, setUpdateChange] = useState<string>('')
2022-08-23 18:02:47 +08:00
/*拉取数据*/
useEffect(() => {
2022-08-24 15:14:09 +08:00
getplaceareaList().then((res: { code: number; data: any[] | undefined; }) => {
if (res.code == 200) {
let data: any = [];
if (res.data != undefined) {
res.data.map((item: any, index: any) => {
const title1 = item.placeName;
const key1 = item.id;
let children1: any = [];
if (item.roomList != undefined) {
const children = item.roomList.map((item: any, index: any) => {
const title2 = item.areaName;
const key2 = item.id;
return { title: title2, key: key2}
});
children1 = children;
}
const first = { title: title1, key: key1, children: children1 }
data.push(first);
});
}
setTreeData(data);
2022-08-23 18:02:47 +08:00
}
})
2022-08-24 15:14:09 +08:00
}, []);
2022-08-25 15:08:48 +08:00
const toAdd = async (props?: any) => {
spinSet(true);
setUpdateChange('新增设备');
setType("new");
setUpdateVisible(true);
}
2022-08-26 11:12:11 +08:00
const toEdit = (dId: String) => {
2022-08-25 15:08:48 +08:00
setUpdateChange('修改设备');
2022-08-26 11:12:11 +08:00
console.log(dId)
setDeviceId(dId)
2022-08-25 15:08:48 +08:00
setType("edit");
setUpdateVisible(true);
}
const toRead = (props: any) => {
setUpdateChange('查看设备');
setDeviceId(props.id)
setType("read");
setUpdateVisible(true);
}
2022-08-23 18:02:47 +08:00
/**
2022-08-24 15:14:09 +08:00
*
2022-08-23 18:02:47 +08:00
* @param record
*/
2022-08-25 15:08:48 +08:00
2022-08-23 18:02:47 +08:00
const current = getURLInformation('current');
2022-08-24 15:14:09 +08:00
//列表页loading
const [spinLoading, setSpinLoading] = useState<boolean>(false);
2022-08-25 15:08:48 +08:00
2022-08-24 15:14:09 +08:00
const onSelect = (selectedKeys: any, info: any) => {
selectedKeys.length == 0 ? setTreeId(null) : setTreeId(selectedKeys[0])
2022-08-23 18:02:47 +08:00
2022-08-24 15:14:09 +08:00
console.log(selectedKeys)
}
2022-08-23 18:02:47 +08:00
const columns: any[] = [
2022-08-24 15:14:09 +08:00
//设备管理
2022-08-23 18:02:47 +08:00
{
title: '序号',
dataIndex: 'index',
valueType: 'index',
search: false,
width: '3%',
},
{
title: '评标场所名称',
2022-08-24 15:14:09 +08:00
dataIndex: 'placeName',
2022-08-23 18:02:47 +08:00
width: '10%',
search: false,
},
{
title: '评标区域名称',
2022-08-24 15:14:09 +08:00
dataIndex: 'areaName',
2022-08-23 18:02:47 +08:00
width: '10%',
search: false,
},
{
title: '设备类型',
2022-08-24 15:14:09 +08:00
dataIndex: 'deviceType',
2022-08-23 18:02:47 +08:00
width: '10%',
2022-08-24 15:14:09 +08:00
valueType: 'select',
valueEnum: deviceTypeEnum,
2022-08-23 18:02:47 +08:00
search: false,
},
{
title: '设备名称',
2022-08-24 15:14:09 +08:00
dataIndex: 'deviceName',
2022-08-23 18:02:47 +08:00
search: true,
width: '10%',
},
{
title: '设备标识',
2022-08-24 15:14:09 +08:00
dataIndex: 'deviceCode',
2022-08-23 18:02:47 +08:00
search: true,
width: '10%',
},
2022-08-24 15:14:09 +08:00
2022-08-23 18:02:47 +08:00
{
title: '网络IP',
2022-08-24 15:14:09 +08:00
dataIndex: 'deviceManagementIp',
2022-08-23 18:02:47 +08:00
search: true,
width: '10%',
},
{
title: '设备状态',
2022-08-24 15:14:09 +08:00
dataIndex: 'deviceStatus',
2022-08-23 18:02:47 +08:00
width: '10%',
2022-08-24 15:14:09 +08:00
valueType: 'select',
valueEnum: deviceStatusEnum,
2022-08-23 18:02:47 +08:00
search: true,
},
2022-08-24 15:14:09 +08:00
2022-08-26 11:12:11 +08:00
// {
// title: '操作',
// width: '7%',
// search: false,
// render: (text: any, record: any) => {
// return (
// <>
// <Button type="text" onClick={() => {toEdit(record.id)}} danger>
// 编辑
// </Button>
// <Button type="text" onClick={() => {}} danger>
// 删除
// </Button>
// </>
// );
// },
// },
2022-08-23 18:02:47 +08:00
];
2022-08-24 15:14:09 +08:00
2022-08-23 18:02:47 +08:00
return (
2022-08-25 15:08:48 +08:00
<div style={{ padding: '0px 24px' }}>
<Spin spinning={spin}>
2022-08-24 15:14:09 +08:00
<ProCard split="vertical" bordered headerBordered>
<ProCard colSpan="300px">
{treeData == undefined ? null : (
<Tree
defaultExpandAll
onSelect={onSelect}
treeData={treeData}
/>
)}
</ProCard>
2022-08-23 18:02:47 +08:00
2022-08-24 15:14:09 +08:00
<ProCard bodyStyle={{ width: "100%" }} >
<ProTable
actionRef={checkRelationRef}
className="proSearch"
columns={columns}
params={{ treeId: treeId }}
size="small"
request={async (params) =>
await deviceList(params).then((res) => {
if (res.code == 200) {
let data = res.data;
return Promise.resolve({
data: data.records,
success: res.success,
total: res.data.total,
current: res.data.current,
2022-08-23 18:02:47 +08:00
});
2022-08-24 15:14:09 +08:00
}
return Promise.resolve({
data: [],
success: false,
total: 0,
current: 1,
});
})
2022-08-23 18:02:47 +08:00
}
2022-08-24 15:14:09 +08:00
search={{
filterType: 'query',
optionRender: (searchConfig: any, { form }) => {
return [
<Button
key="resetText"
onClick={() => {
form?.setFieldsValue({
current: 1,
});
form?.submit();
}}
>
{searchConfig?.resetText}
</Button>,
<Button
key="searchText"
type="primary"
onClick={() => {
form?.submit();
}}
>
{searchConfig?.searchText}
</Button>,
2022-08-26 11:12:11 +08:00
// <Button key="toCreate" onClick={() => toAdd()}>
// 新建
// </Button>,
2022-08-24 15:14:09 +08:00
];
},
}}
pagination={{
defaultCurrent: isNotEmpty(current) ? Number(current) : 1,
defaultPageSize: 10,
showSizeChanger: false,
}} //默认显示条数
toolBarRender={false}
/>
</ProCard>
</ProCard>
2022-08-26 11:12:11 +08:00
{/* {updateVisible ? (
2022-08-25 15:08:48 +08:00
<DeviceForm key={Math.random()} titleName={updateChange}
2022-08-26 11:12:11 +08:00
type={type} deviceId={deviceId} status={'2'} onCancel={() => setUpdateVisible(false)}
2022-08-25 15:08:48 +08:00
modalVisible={updateVisible} tpId={''} />
2022-08-26 11:12:11 +08:00
) : null} */}
2022-08-25 15:08:48 +08:00
</Spin>
</div>
2022-08-23 18:02:47 +08:00
);
};
export default Index