|
|
@@ -11,6 +11,8 @@ import {
|
|
|
message,
|
|
|
Row,
|
|
|
Steps,
|
|
|
+ Table,
|
|
|
+ Tooltip,
|
|
|
} from 'antd';
|
|
|
import { useEffect, useState } from 'react';
|
|
|
import styles from './index.less';
|
|
|
@@ -22,6 +24,7 @@ import { getMenuPathByCode, MENUS_CODE } from '@/utils/menu';
|
|
|
interface Props {
|
|
|
change: () => void;
|
|
|
data: any;
|
|
|
+ access: any;
|
|
|
}
|
|
|
const Access = (props: Props) => {
|
|
|
const [form] = Form.useForm();
|
|
|
@@ -31,9 +34,10 @@ const Access = (props: Props) => {
|
|
|
const [current, setCurrent] = useState<number>(0);
|
|
|
const [networkList, setNetworkList] = useState<any[]>([]);
|
|
|
const [procotolList, setProcotolList] = useState<any[]>([]);
|
|
|
- const [procotolCurrent, setProcotolCurrent] = useState<string>('');
|
|
|
- const [networkCurrent, setNetworkCurrent] = useState<string>('');
|
|
|
- // const [config, setConfig] = useState<any>();
|
|
|
+ const [procotolCurrent, setProcotolCurrent] = useState<string>(props.access?.protocol || '');
|
|
|
+ const [networkCurrent, setNetworkCurrent] = useState<string>(props.access?.channelId || '');
|
|
|
+ const [config, setConfig] = useState<any>();
|
|
|
+ const [providers, setProviders] = useState<any[]>([]);
|
|
|
|
|
|
const MetworkTypeMapping = new Map();
|
|
|
MetworkTypeMapping.set('websocket-server', 'WEB_SOCKET_SERVER');
|
|
|
@@ -54,17 +58,29 @@ const Access = (props: Props) => {
|
|
|
ProcotoleMapping.set('tcp-server-gateway', 'TCP');
|
|
|
|
|
|
const queryNetworkList = (params?: any) => {
|
|
|
- service.getNetworkList(MetworkTypeMapping.get(props.data?.id), params).then((resp) => {
|
|
|
- if (resp.status === 200) {
|
|
|
- setNetworkList(resp.result);
|
|
|
- }
|
|
|
- });
|
|
|
+ service
|
|
|
+ .getNetworkList(MetworkTypeMapping.get(props.data?.id || props.access?.provider), params)
|
|
|
+ .then((resp) => {
|
|
|
+ if (resp.status === 200) {
|
|
|
+ setNetworkList(resp.result);
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
const queryProcotolList = (params?: any) => {
|
|
|
- service.getProtocolList(ProcotoleMapping.get(props.data?.id), params).then((resp) => {
|
|
|
+ service
|
|
|
+ .getProtocolList(ProcotoleMapping.get(props.data?.id || props.access?.provider), params)
|
|
|
+ .then((resp) => {
|
|
|
+ if (resp.status === 200) {
|
|
|
+ setProcotolList(resp.result);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const queryProviders = () => {
|
|
|
+ service.getProviders().then((resp) => {
|
|
|
if (resp.status === 200) {
|
|
|
- setProcotolList(resp.result);
|
|
|
+ setProviders(resp.result);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
@@ -76,6 +92,14 @@ const Access = (props: Props) => {
|
|
|
}
|
|
|
}, [props.data]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ form.setFieldsValue({
|
|
|
+ name: props.access?.name,
|
|
|
+ description: props.access?.name,
|
|
|
+ });
|
|
|
+ queryProviders();
|
|
|
+ }, [props.access]);
|
|
|
+
|
|
|
const next = () => {
|
|
|
if (current === 0) {
|
|
|
if (!networkCurrent) {
|
|
|
@@ -90,10 +114,13 @@ const Access = (props: Props) => {
|
|
|
message.error('请选择消息协议!');
|
|
|
} else {
|
|
|
service
|
|
|
- .getConfigView(procotolCurrent, ProcotoleMapping.get(props.data?.id))
|
|
|
+ .getConfigView(
|
|
|
+ procotolCurrent,
|
|
|
+ ProcotoleMapping.get(props.data?.id || props.access?.provider),
|
|
|
+ )
|
|
|
.then((resp) => {
|
|
|
if (resp.status === 200) {
|
|
|
- // setConfig(resp.result)
|
|
|
+ setConfig(resp.result);
|
|
|
}
|
|
|
});
|
|
|
setCurrent(current + 1);
|
|
|
@@ -117,53 +144,114 @@ const Access = (props: Props) => {
|
|
|
},
|
|
|
];
|
|
|
|
|
|
- // const columns = [
|
|
|
- // {
|
|
|
- // title: '姓名',
|
|
|
- // dataIndex: 'name',
|
|
|
- // key: 'name',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // title: '年龄',
|
|
|
- // dataIndex: 'age',
|
|
|
- // key: 'age',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // title: '住址',
|
|
|
- // dataIndex: 'address',
|
|
|
- // key: 'address',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // title: '姓名',
|
|
|
- // dataIndex: 'name',
|
|
|
- // key: 'name',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // title: '年龄',
|
|
|
- // dataIndex: 'age',
|
|
|
- // key: 'age',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // title: '住址',
|
|
|
- // dataIndex: 'address',
|
|
|
- // key: 'address',
|
|
|
- // },
|
|
|
- // ];
|
|
|
+ const columnsMQTT: any[] = [
|
|
|
+ {
|
|
|
+ title: '分组',
|
|
|
+ dataIndex: 'group',
|
|
|
+ key: 'group',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: 'qos',
|
|
|
+ dataIndex: 'qos',
|
|
|
+ key: 'qos',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '地址',
|
|
|
+ dataIndex: 'address',
|
|
|
+ key: 'address',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: 'topic',
|
|
|
+ dataIndex: 'topic',
|
|
|
+ key: 'topic',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '说明',
|
|
|
+ dataIndex: 'description',
|
|
|
+ key: 'description',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
|
|
|
- // const dataSource = [
|
|
|
- // {
|
|
|
- // key: '1',
|
|
|
- // name: '胡彦斌',
|
|
|
- // age: 32,
|
|
|
- // address: '西湖区湖底公园1号',
|
|
|
- // },
|
|
|
- // {
|
|
|
- // key: '2',
|
|
|
- // name: '胡彦祖',
|
|
|
- // age: 42,
|
|
|
- // address: '西湖区湖底公园1号',
|
|
|
- // },
|
|
|
- // ];
|
|
|
+ const columnsHTTP: any[] = [
|
|
|
+ {
|
|
|
+ title: '地址',
|
|
|
+ dataIndex: 'address',
|
|
|
+ key: 'address',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '分组',
|
|
|
+ dataIndex: 'group',
|
|
|
+ key: 'group',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '示例',
|
|
|
+ dataIndex: 'example',
|
|
|
+ key: 'example',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '说明',
|
|
|
+ dataIndex: 'description',
|
|
|
+ key: 'description',
|
|
|
+ ellipsis: true,
|
|
|
+ align: 'center',
|
|
|
+ render: (text: any) => (
|
|
|
+ <Tooltip placement="top" title={text}>
|
|
|
+ {text}
|
|
|
+ </Tooltip>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
|
|
|
const renderSteps = (cur: number) => {
|
|
|
switch (cur) {
|
|
|
@@ -210,16 +298,10 @@ const Access = (props: Props) => {
|
|
|
>
|
|
|
<div className={styles.title}>{item.name}</div>
|
|
|
<div className={styles.cardContent}>
|
|
|
- <div style={{ width: '40%' }}>
|
|
|
- <div className={styles.item}>
|
|
|
- {MetworkTypeMapping.get(props.data?.id)}
|
|
|
- </div>
|
|
|
- <div className={styles.item}>共享配置</div>
|
|
|
- </div>
|
|
|
- <div style={{ width: '60%' }}>
|
|
|
+ <div style={{ width: '100%', height: '50px' }}>
|
|
|
{item.addresses.slice(0, 2).map((i: any) => (
|
|
|
<div className={styles.item} key={i.address}>
|
|
|
- 公网: {i.address}
|
|
|
+ <Badge color={i.health === -1 ? 'red' : 'green'} text={i.address} />
|
|
|
</div>
|
|
|
))}
|
|
|
</div>
|
|
|
@@ -296,7 +378,7 @@ const Access = (props: Props) => {
|
|
|
}}
|
|
|
>
|
|
|
<div className={styles.title}>{item.name}</div>
|
|
|
- <div className={styles.desc}>这里是协议包中的协议说明</div>
|
|
|
+ <div className={styles.desc}>{item.description}</div>
|
|
|
</Card>
|
|
|
</Col>
|
|
|
))}
|
|
|
@@ -344,32 +426,41 @@ const Access = (props: Props) => {
|
|
|
<div className={styles.config}>
|
|
|
<div className={styles.title}>配置概览</div>
|
|
|
<Descriptions column={1}>
|
|
|
- <Descriptions.Item label="接入方式">{props.data?.name || ''}</Descriptions.Item>
|
|
|
+ <Descriptions.Item label="接入方式">
|
|
|
+ {props.data?.name || providers.find((i) => i.id === props.access?.provider)?.name}
|
|
|
+ </Descriptions.Item>
|
|
|
<Descriptions.Item>{props.data?.description || ''}</Descriptions.Item>
|
|
|
<Descriptions.Item label="消息协议">
|
|
|
{procotolList.find((i) => i.id === procotolCurrent)?.name || ''}
|
|
|
</Descriptions.Item>
|
|
|
<Descriptions.Item>
|
|
|
- {procotolList.find((i) => i.id === procotolCurrent)?.description ||
|
|
|
- '----缺少描述呀----'}
|
|
|
+ {procotolList.find((i) => i.id === procotolCurrent)?.description || ''}
|
|
|
</Descriptions.Item>
|
|
|
<Descriptions.Item label="网络组件">
|
|
|
{(networkList.find((i) => i.id === networkCurrent)?.addresses || []).map(
|
|
|
(item: any) => (
|
|
|
- <Badge
|
|
|
- key={item.address}
|
|
|
- color={item.health === -1 ? 'red' : 'green'}
|
|
|
- text={item.address}
|
|
|
- style={{ marginLeft: '20px' }}
|
|
|
- />
|
|
|
+ <div key={item.address}>
|
|
|
+ <Badge
|
|
|
+ color={item.health === -1 ? 'red' : 'green'}
|
|
|
+ text={item.address}
|
|
|
+ style={{ marginLeft: '20px' }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
),
|
|
|
)}
|
|
|
</Descriptions.Item>
|
|
|
</Descriptions>
|
|
|
- {/* <div>
|
|
|
- <div>路由信息</div>
|
|
|
- <Table dataSource={dataSource} columns={columns} pagination={false} />
|
|
|
- </div> */}
|
|
|
+ {config?.routes && config?.routes?.length > 0 && (
|
|
|
+ <div>
|
|
|
+ <div>路由信息:</div>
|
|
|
+ <Table
|
|
|
+ dataSource={config?.routes || []}
|
|
|
+ columns={config.id === 'MQTT' ? columnsMQTT : columnsHTTP}
|
|
|
+ pagination={false}
|
|
|
+ scroll={{ x: 500 }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|
|
|
@@ -384,6 +475,8 @@ const Access = (props: Props) => {
|
|
|
type="link"
|
|
|
onClick={() => {
|
|
|
props.change();
|
|
|
+ setNetworkCurrent('');
|
|
|
+ setProcotolCurrent('');
|
|
|
}}
|
|
|
>
|
|
|
返回
|
|
|
@@ -398,6 +491,11 @@ const Access = (props: Props) => {
|
|
|
</div>
|
|
|
<div className={styles.content}>{renderSteps(current)}</div>
|
|
|
<div className={styles.action}>
|
|
|
+ {current > 0 && (
|
|
|
+ <Button style={{ margin: '0 8px' }} onClick={() => prev()}>
|
|
|
+ 上一步
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
{current < steps.length - 1 && (
|
|
|
<Button type="primary" onClick={() => next()}>
|
|
|
下一步
|
|
|
@@ -409,23 +507,41 @@ const Access = (props: Props) => {
|
|
|
onClick={async () => {
|
|
|
try {
|
|
|
const values = await form.validateFields();
|
|
|
- const params = {
|
|
|
- name: values.name,
|
|
|
- description: values.description,
|
|
|
- provider: props.data.id,
|
|
|
- protocol: procotolCurrent,
|
|
|
- transport: ProcotoleMapping.get(props.data.id),
|
|
|
- channel: 'network', // 网络组件
|
|
|
- channelId: networkCurrent,
|
|
|
- };
|
|
|
- service.save(params).then((resp: any) => {
|
|
|
- if (resp.status === 200) {
|
|
|
- message.success('操作成功!');
|
|
|
- setCurrent(0);
|
|
|
- setNetworkCurrent('');
|
|
|
- setProcotolCurrent('');
|
|
|
- }
|
|
|
- });
|
|
|
+ // 编辑还是保存
|
|
|
+ if (!!props.access.id) {
|
|
|
+ const params = {
|
|
|
+ name: values.name,
|
|
|
+ description: values.description,
|
|
|
+ provider: props.data.id,
|
|
|
+ protocol: procotolCurrent,
|
|
|
+ transport: ProcotoleMapping.get(props.data.id),
|
|
|
+ channel: 'network', // 网络组件
|
|
|
+ channelId: networkCurrent,
|
|
|
+ };
|
|
|
+ service.save(params).then((resp: any) => {
|
|
|
+ if (resp.status === 200) {
|
|
|
+ message.success('操作成功!');
|
|
|
+ history.push(`${getMenuPathByCode(MENUS_CODE['link/AccessConfig'])}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ const params = {
|
|
|
+ id: props.access?.id,
|
|
|
+ name: values.name,
|
|
|
+ description: values.description,
|
|
|
+ provider: props.data.id,
|
|
|
+ protocol: procotolCurrent,
|
|
|
+ transport: ProcotoleMapping.get(props.data.id),
|
|
|
+ channel: 'network', // 网络组件
|
|
|
+ channelId: networkCurrent,
|
|
|
+ };
|
|
|
+ service.update(params).then((resp: any) => {
|
|
|
+ if (resp.status === 200) {
|
|
|
+ message.success('操作成功!');
|
|
|
+ history.push(`${getMenuPathByCode(MENUS_CODE['link/AccessConfig'])}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
} catch (errorInfo) {
|
|
|
console.error('Failed:', errorInfo);
|
|
|
}
|
|
|
@@ -434,11 +550,6 @@ const Access = (props: Props) => {
|
|
|
保存
|
|
|
</Button>
|
|
|
)}
|
|
|
- {current > 0 && (
|
|
|
- <Button style={{ margin: '0 8px' }} onClick={() => prev()}>
|
|
|
- 上一步
|
|
|
- </Button>
|
|
|
- )}
|
|
|
</div>
|
|
|
</div>
|
|
|
</Card>
|