|
|
@@ -14,60 +14,66 @@ import {
|
|
|
SearchOutlined,
|
|
|
StopOutlined,
|
|
|
} from '@ant-design/icons';
|
|
|
-import { useRef, useState } from 'react';
|
|
|
+import { useEffect, useRef, useState } from 'react';
|
|
|
import { useIntl } from 'umi';
|
|
|
import ChannelCard from '../channelCard';
|
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
|
import Service from './service';
|
|
|
import SaveChannel from './saveChannel';
|
|
|
import SavePoint from './savePoint';
|
|
|
+// import Import from './import';
|
|
|
+import { onlyMessage } from '@/utils/util';
|
|
|
|
|
|
-export const service = new Service('');
|
|
|
+export const service = new Service('opc/client');
|
|
|
|
|
|
const NewModbus = () => {
|
|
|
- const { minHeight } = useDomFullHeight(`.opc`);
|
|
|
+ const { minHeight } = useDomFullHeight(`.modbus`);
|
|
|
const intl = useIntl();
|
|
|
const actionRef = useRef<ActionType>();
|
|
|
- const { permission } = PermissionButton.usePermission('link/Channel/Opcua');
|
|
|
+ const { permission } = PermissionButton.usePermission('link/Channel/Modbus');
|
|
|
const [param, setParam] = useState({});
|
|
|
const [activeKey, setActiveKey] = useState<any>('');
|
|
|
const [visible, setVisible] = useState<boolean>(false);
|
|
|
const [visiblePoint, setVisiblePoint] = useState<boolean>(false);
|
|
|
const [current, setCurrent] = useState<any>({});
|
|
|
const [pointDetail, setPointDetail] = useState<any>({});
|
|
|
- const data = [
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- status: 'connect',
|
|
|
- state: {
|
|
|
- text: '正常',
|
|
|
- value: 'enabled',
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- status: 'disconnect',
|
|
|
- state: {
|
|
|
- text: '禁用',
|
|
|
- value: 'disabled',
|
|
|
- },
|
|
|
- },
|
|
|
- ];
|
|
|
- const dataSoure = [
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- name: '111',
|
|
|
- number: '0xF831',
|
|
|
- collect: {
|
|
|
- text: '采集失败',
|
|
|
- value: 'collectError',
|
|
|
- },
|
|
|
- state: {
|
|
|
- text: '禁用',
|
|
|
- value: 'disabled',
|
|
|
- },
|
|
|
- },
|
|
|
- ];
|
|
|
+ // const [importVisible, setImportVisible] = useState<boolean>(false);
|
|
|
+ const [masterList, setMasterList] = useState<any>([]);
|
|
|
+ const [filterList, setFilterList] = useState([]);
|
|
|
+ const masterId = useRef<string>('');
|
|
|
+
|
|
|
+ const collectMap = new Map();
|
|
|
+ collectMap.set('running', 'success');
|
|
|
+ collectMap.set('error', 'error');
|
|
|
+ collectMap.set('stopped', 'warning');
|
|
|
+
|
|
|
+ const menu = (
|
|
|
+ <Menu>
|
|
|
+ <Menu.Item key="1">
|
|
|
+ <PermissionButton
|
|
|
+ isPermission={permission.export}
|
|
|
+ icon={<ExportOutlined />}
|
|
|
+ type="default"
|
|
|
+ onClick={() => {
|
|
|
+ // setExportVisible(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 批量导出设备
|
|
|
+ </PermissionButton>
|
|
|
+ </Menu.Item>
|
|
|
+ <Menu.Item key="2">
|
|
|
+ <PermissionButton
|
|
|
+ isPermission={permission.import || true}
|
|
|
+ icon={<ImportOutlined />}
|
|
|
+ onClick={() => {
|
|
|
+ // setImportVisible(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 批量导入设备
|
|
|
+ </PermissionButton>
|
|
|
+ </Menu.Item>
|
|
|
+ </Menu>
|
|
|
+ );
|
|
|
|
|
|
const columns: ProColumns<any>[] = [
|
|
|
{
|
|
|
@@ -78,38 +84,44 @@ const NewModbus = () => {
|
|
|
fixed: 'left',
|
|
|
},
|
|
|
{
|
|
|
- title: '点位ID',
|
|
|
- dataIndex: 'host',
|
|
|
+ title: '点位Id',
|
|
|
+ render: (record: any) => <>{record.function?.text}</>,
|
|
|
},
|
|
|
{
|
|
|
- title: '数据模式',
|
|
|
- dataIndex: 'port',
|
|
|
+ title: '数据类型',
|
|
|
+ dataIndex: 'unitId',
|
|
|
search: false,
|
|
|
- valueType: 'digit',
|
|
|
},
|
|
|
{
|
|
|
title: '当前数据',
|
|
|
- dataIndex: 'port',
|
|
|
search: false,
|
|
|
- valueType: 'digit',
|
|
|
+ render: (record: any) => <>{record.parameter?.quantity}</>,
|
|
|
},
|
|
|
{
|
|
|
title: '采集状态',
|
|
|
- // dataIndex: 'collect',
|
|
|
search: false,
|
|
|
render: (record: any) => (
|
|
|
<>
|
|
|
- {record.collect.text}
|
|
|
- <SearchOutlined
|
|
|
- style={{ color: '#1d39c4', marginLeft: 3 }}
|
|
|
- onClick={() => {
|
|
|
- Modal.error({
|
|
|
- title: '失败原因',
|
|
|
- content: <div>111111</div>,
|
|
|
- onOk() {},
|
|
|
- });
|
|
|
- }}
|
|
|
- />
|
|
|
+ {record.state.value === 'disabled' ? (
|
|
|
+ '-'
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Badge
|
|
|
+ status={collectMap.get(record.collectState?.value)}
|
|
|
+ text={record.collectState?.text}
|
|
|
+ />
|
|
|
+ <SearchOutlined
|
|
|
+ style={{ color: '#1d39c4', marginLeft: 3 }}
|
|
|
+ onClick={() => {
|
|
|
+ Modal.error({
|
|
|
+ title: '失败原因',
|
|
|
+ content: <div>111111</div>,
|
|
|
+ onOk() {},
|
|
|
+ });
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ )}
|
|
|
</>
|
|
|
),
|
|
|
},
|
|
|
@@ -146,8 +158,8 @@ const NewModbus = () => {
|
|
|
isPermission={permission.update}
|
|
|
key="edit"
|
|
|
onClick={() => {
|
|
|
- // setVisible(true);
|
|
|
- // setCurrent(record);
|
|
|
+ setPointDetail(record);
|
|
|
+ setVisiblePoint(true);
|
|
|
}}
|
|
|
type={'link'}
|
|
|
style={{ padding: 0 }}
|
|
|
@@ -172,24 +184,24 @@ const NewModbus = () => {
|
|
|
defaultMessage: '确认禁用?',
|
|
|
}),
|
|
|
onConfirm: async () => {
|
|
|
- // if (record.state.value === 'disabled') {
|
|
|
- // await service.edit({
|
|
|
- // ...record,
|
|
|
- // state: 'enabled',
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // await service.edit({
|
|
|
- // ...record,
|
|
|
- // state: 'disabled',
|
|
|
- // });
|
|
|
- // }
|
|
|
- // onlyMessage(
|
|
|
- // intl.formatMessage({
|
|
|
- // id: 'pages.data.option.success',
|
|
|
- // defaultMessage: '操作成功!',
|
|
|
- // }),
|
|
|
- // );
|
|
|
- // actionRef.current?.reload();
|
|
|
+ if (record.state.value === 'disabled') {
|
|
|
+ await service.editPoint(record.id, {
|
|
|
+ ...record,
|
|
|
+ state: 'enabled',
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ await service.editPoint(record.id, {
|
|
|
+ ...record,
|
|
|
+ state: 'disabled',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ onlyMessage(
|
|
|
+ intl.formatMessage({
|
|
|
+ id: 'pages.data.option.success',
|
|
|
+ defaultMessage: '操作成功!',
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ actionRef.current?.reload();
|
|
|
},
|
|
|
}}
|
|
|
isPermission={permission.action}
|
|
|
@@ -210,16 +222,16 @@ const NewModbus = () => {
|
|
|
title: '确认删除',
|
|
|
disabled: record.state.value === 'enabled',
|
|
|
onConfirm: async () => {
|
|
|
- // const resp: any = await service.remove(record.id);
|
|
|
- // if (resp.status === 200) {
|
|
|
- // onlyMessage(
|
|
|
- // intl.formatMessage({
|
|
|
- // id: 'pages.data.option.success',
|
|
|
- // defaultMessage: '操作成功!',
|
|
|
- // }),
|
|
|
- // );
|
|
|
- // actionRef.current?.reload();
|
|
|
- // }
|
|
|
+ const resp: any = await service.deletePoint(record.id);
|
|
|
+ if (resp.status === 200) {
|
|
|
+ onlyMessage(
|
|
|
+ intl.formatMessage({
|
|
|
+ id: 'pages.data.option.success',
|
|
|
+ defaultMessage: '操作成功!',
|
|
|
+ }),
|
|
|
+ );
|
|
|
+ actionRef.current?.reload();
|
|
|
+ }
|
|
|
},
|
|
|
}}
|
|
|
key="delete"
|
|
|
@@ -231,33 +243,64 @@ const NewModbus = () => {
|
|
|
},
|
|
|
];
|
|
|
|
|
|
- const menu = (
|
|
|
- <Menu>
|
|
|
- <Menu.Item key="1">
|
|
|
- <PermissionButton
|
|
|
- isPermission={permission.export}
|
|
|
- icon={<ExportOutlined />}
|
|
|
- type="default"
|
|
|
- onClick={() => {
|
|
|
- // setExportVisible(true);
|
|
|
- }}
|
|
|
- >
|
|
|
- 批量导出设备
|
|
|
- </PermissionButton>
|
|
|
- </Menu.Item>
|
|
|
- <Menu.Item key="2">
|
|
|
- <PermissionButton
|
|
|
- isPermission={permission.import}
|
|
|
- icon={<ImportOutlined />}
|
|
|
- onClick={() => {
|
|
|
- // setImportVisible(true);
|
|
|
- }}
|
|
|
- >
|
|
|
- 批量导入设备
|
|
|
- </PermissionButton>
|
|
|
- </Menu.Item>
|
|
|
- </Menu>
|
|
|
- );
|
|
|
+ const getOpc = () => {
|
|
|
+ service
|
|
|
+ .noPagingOpcua({
|
|
|
+ paging: false,
|
|
|
+ sorts: [
|
|
|
+ {
|
|
|
+ name: 'createTime',
|
|
|
+ order: 'desc',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ })
|
|
|
+ .then((res: any) => {
|
|
|
+ if (res.status === 200) {
|
|
|
+ setMasterList(res.result);
|
|
|
+ setFilterList(res.result);
|
|
|
+ setActiveKey(res.result?.[0]?.id);
|
|
|
+ masterId.current = res.result?.[0]?.id;
|
|
|
+ console.log(masterId.current);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ //启用
|
|
|
+ const _start = (id: string) => {
|
|
|
+ service.enable(id).then((res) => {
|
|
|
+ if (res.status === 200) {
|
|
|
+ onlyMessage('操作成功');
|
|
|
+ getOpc();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ //禁用
|
|
|
+ const _stop = (id: string) => {
|
|
|
+ service.disable(id).then((res) => {
|
|
|
+ if (res.status === 200) {
|
|
|
+ onlyMessage('操作成功');
|
|
|
+ getOpc();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const removeOpc = (id: string) => {
|
|
|
+ service.remove(id).then((res: any) => {
|
|
|
+ if (res.status === 200) {
|
|
|
+ onlyMessage('删除成功');
|
|
|
+ getOpc();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ masterId.current = activeKey;
|
|
|
+ actionRef.current?.reload();
|
|
|
+ }, [activeKey]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getOpc();
|
|
|
+ }, []);
|
|
|
|
|
|
return (
|
|
|
<PageContainer>
|
|
|
@@ -269,7 +312,14 @@ const NewModbus = () => {
|
|
|
placeholder="请输入名称"
|
|
|
allowClear
|
|
|
onSearch={(value) => {
|
|
|
- console.log(value);
|
|
|
+ const items = masterList.filter((item: any) => item.name.match(value));
|
|
|
+ if (value) {
|
|
|
+ setFilterList(items);
|
|
|
+ setActiveKey(items?.[0].id);
|
|
|
+ } else {
|
|
|
+ setFilterList(masterList);
|
|
|
+ setActiveKey(masterList?.[0].id);
|
|
|
+ }
|
|
|
}}
|
|
|
/>
|
|
|
<PermissionButton
|
|
|
@@ -281,12 +331,12 @@ const NewModbus = () => {
|
|
|
key="add"
|
|
|
icon={<PlusOutlined />}
|
|
|
type="default"
|
|
|
- style={{ width: '100%', marginTop: 16 }}
|
|
|
+ style={{ width: '100%', marginTop: 16, marginBottom: 16 }}
|
|
|
>
|
|
|
新增
|
|
|
</PermissionButton>
|
|
|
<div className="item-left-list">
|
|
|
- {data.map((item) => (
|
|
|
+ {filterList.map((item: any) => (
|
|
|
<ChannelCard
|
|
|
active={activeKey === item.id}
|
|
|
data={item}
|
|
|
@@ -299,8 +349,8 @@ const NewModbus = () => {
|
|
|
isPermission={permission.update}
|
|
|
key="edit"
|
|
|
onClick={() => {
|
|
|
- // setVisible(true);
|
|
|
- // setCurrent(record);
|
|
|
+ setVisible(true);
|
|
|
+ setCurrent(item);
|
|
|
}}
|
|
|
type={'link'}
|
|
|
style={{ padding: 0 }}
|
|
|
@@ -321,7 +371,13 @@ const NewModbus = () => {
|
|
|
}.tips`,
|
|
|
defaultMessage: '确认禁用?',
|
|
|
}),
|
|
|
- onConfirm: async () => {},
|
|
|
+ onConfirm: async () => {
|
|
|
+ if (item.state.value === 'disabled') {
|
|
|
+ _start(item.id);
|
|
|
+ } else {
|
|
|
+ _stop(item.id);
|
|
|
+ }
|
|
|
+ },
|
|
|
}}
|
|
|
>
|
|
|
{item.state.value === 'enabled' ? (
|
|
|
@@ -336,10 +392,15 @@ const NewModbus = () => {
|
|
|
isPermission={permission.delete}
|
|
|
style={{ padding: 0 }}
|
|
|
disabled={item.state.value === 'enabled'}
|
|
|
+ tooltip={{
|
|
|
+ title: item.state.value === 'enabled' ? '请先禁用该通道,再删除。' : '',
|
|
|
+ }}
|
|
|
popConfirm={{
|
|
|
title: '确认删除',
|
|
|
disabled: item.state.value === 'enabled',
|
|
|
- onConfirm: async () => {},
|
|
|
+ onConfirm: async () => {
|
|
|
+ removeOpc(item.id);
|
|
|
+ },
|
|
|
}}
|
|
|
key="delete"
|
|
|
type="link"
|
|
|
@@ -367,7 +428,7 @@ const NewModbus = () => {
|
|
|
params={param}
|
|
|
columns={columns}
|
|
|
rowKey="id"
|
|
|
- dataSource={dataSoure}
|
|
|
+ // dataSource={dataSoure}
|
|
|
// scroll={{ x: 1000 }}
|
|
|
search={false}
|
|
|
headerTitle={
|
|
|
@@ -377,8 +438,7 @@ const NewModbus = () => {
|
|
|
setPointDetail({});
|
|
|
setVisiblePoint(true);
|
|
|
}}
|
|
|
- // isPermission={permission.add}
|
|
|
- isPermission={permission.add || true}
|
|
|
+ isPermission={permission.add}
|
|
|
key="add"
|
|
|
icon={<PlusOutlined />}
|
|
|
type="primary"
|
|
|
@@ -394,8 +454,39 @@ const NewModbus = () => {
|
|
|
</Dropdown>
|
|
|
</>
|
|
|
}
|
|
|
+ // request={async (params) => {
|
|
|
+ // if (masterId.current) {
|
|
|
+ // const res = await service.queryPoint(masterId.current, {
|
|
|
+ // ...params,
|
|
|
+ // sorts: [{ name: 'createTime', order: 'desc' }],
|
|
|
+ // });
|
|
|
+ // return {
|
|
|
+ // code: res.message,
|
|
|
+ // result: {
|
|
|
+ // data: res.result.data,
|
|
|
+ // pageIndex: res.result.pageIndex,
|
|
|
+ // pageSize: res.result.pageSize,
|
|
|
+ // total: res.result.total,
|
|
|
+ // },
|
|
|
+ // status: res.status,
|
|
|
+ // };
|
|
|
+ // } else {
|
|
|
+ // return {
|
|
|
+ // code: 200,
|
|
|
+ // result: {
|
|
|
+ // data: [],
|
|
|
+ // pageIndex: 0,
|
|
|
+ // pageSize: 0,
|
|
|
+ // total: 0,
|
|
|
+ // },
|
|
|
+ // status: 200,
|
|
|
+ // };
|
|
|
+ // }
|
|
|
+ // }}
|
|
|
// request={async (params) =>
|
|
|
- // service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
|
|
|
+ // service.queryPoint(masterId.current,{
|
|
|
+ // ...params,
|
|
|
+ // sorts: [{ name: 'createTime', order: 'desc' }] })
|
|
|
// }
|
|
|
/>
|
|
|
</div>
|
|
|
@@ -406,19 +497,28 @@ const NewModbus = () => {
|
|
|
data={current}
|
|
|
close={() => {
|
|
|
setVisible(false);
|
|
|
- actionRef.current?.reload();
|
|
|
+ getOpc();
|
|
|
}}
|
|
|
/>
|
|
|
)}
|
|
|
{visiblePoint && (
|
|
|
<SavePoint
|
|
|
data={pointDetail}
|
|
|
+ opcId={activeKey}
|
|
|
close={() => {
|
|
|
setVisiblePoint(false);
|
|
|
actionRef.current?.reload();
|
|
|
}}
|
|
|
/>
|
|
|
)}
|
|
|
+ {/* <Import
|
|
|
+ data={current}
|
|
|
+ close={() => {
|
|
|
+ setImportVisible(false);
|
|
|
+ actionRef.current?.reload();
|
|
|
+ }}
|
|
|
+ visible={importVisible}
|
|
|
+ /> */}
|
|
|
</PageContainer>
|
|
|
);
|
|
|
};
|