Skip to content

Commit

Permalink
fix(模拟测试): 添加模拟器
Browse files Browse the repository at this point in the history
使用formily 开发表单

re #203
  • Loading branch information
Lind-pro committed Sep 18, 2020
1 parent 2114c3d commit 11a94f8
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 68 deletions.
6 changes: 3 additions & 3 deletions config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,15 @@ export const routes = [
]
},
{
path: 'mock',
path: 'simulator',
name: '模拟测试',
icon: 'bug',
routes: [
{
path: '/mock/device',
path: '/simulator/device',
name: '设备模拟器',
icon: 'paper-clip',
component: './mock/device',
component: './simulator/device',
}
]
},
Expand Down
22 changes: 0 additions & 22 deletions src/pages/mock/device/data.d.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/pages/mock/device/index.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/pages/mock/device/service.ts

This file was deleted.

74 changes: 74 additions & 0 deletions src/pages/simulator/device/data.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
declare namespace SIMULATOR {
interface Device {
id: string,
name: string,
description: string,
networkType: string,
networkConfiguration: MqttConfig | TcpConfig,
state: {
id: string,
text: string,
},
runner: {
binds: any[],
total: number,
startWith: string | number,
batch: number
},
listeners: {
id: string,
type: string,
configuration: any
}[]
}

interface MqttConfig {
host: string,
port: string,
clientId: string,
username: string,
password: string,
keepAliveTimeSeconds: string,
tls: boolean,
certId: string,
}

interface TcpConfig {
host: string,
port: string,
tls: boolean,
certId: string,
}

interface SimulatorState {
complete: boolean,
total: string | number,
current: string,
failed: string | number,
aggTime: {
max: string | number,
min: string | number,
avg: string | number,
},
distTime: {
[string]: string,
},
failedTypeCounts: {
[string]: string,
},
runtime: {
totalUpstream: string | number,
totalUpstreamBytes: string | number,
totalDownstream: string | number,
totalDownstreamBytes: string | number,
}
}

interface Session {
id: string,
index: string,
connected: boolean,
connectTime: number | string,
}

}
31 changes: 31 additions & 0 deletions src/pages/simulator/device/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PageHeaderWrapper } from "@ant-design/pro-layout";
import { Button } from "antd";
import React, { useEffect, useState } from "react";
import Save from "./save";
import Service from "./service";

interface Props {

}

const Simulator: React.FC<Props> = props => {

const service = new Service('network/simulator');

const [saveVisible, setSaveVisible] = useState<boolean>(false);

useEffect(() => {
service.query({}).subscribe(data => {
console.log(data, 'ddd');
})
});


return (
<PageHeaderWrapper title="模拟测试">
<Button onClick={() => setSaveVisible(true)}> 新建模拟器</Button>
{saveVisible && <Save close={() => setSaveVisible(false)} />}
</PageHeaderWrapper>
)
}
export default Simulator;
153 changes: 153 additions & 0 deletions src/pages/simulator/device/save/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { message, Modal } from "antd";
import React from "react";
import Service from "../service";
import { createFormActions, FormEffectHooks, SchemaForm } from "@formily/antd";
import { ArrayCards, ArrayTable, Input, DatePicker, Select } from '@formily/antd-components'

interface Props {
close: Function
}
const actions = createFormActions();

const Save: React.FC<Props> = props => {
const service = new Service('network/simulator');

const { onFieldValueChange$ } = FormEffectHooks;
const changeNetworkTypeEffects = () => {
const { setFieldState } = actions;

onFieldValueChange$('networkType').subscribe(({ value }) => {
setFieldState('*(certId,host,port,clientId,username,password,keepAliveTimeSeconds)', state => {
state.visible = value === 'mqtt' ? true : false;
});
});
}

const save = (data: any) => {
service.save(data).subscribe(() => {
message.success('保存成功');
props.close();
})
}
return (
<Modal
title="新建模拟器"
onOk={() => actions.submit()}
visible
width={900}
>
<SchemaForm
effects={() => {
changeNetworkTypeEffects()
}}
actions={actions}
onSubmit={v => save(v)}
components={{ DatePicker, Input, ArrayTable, ArrayCards, Select }}
schema={{
"type": "object",
"properties": {
"NO_NAME_FIELD_$0": {
"type": "object",
"x-component": "mega-layout",
"x-component-props": {
"grid": true,
"autoRow": true,
"columns": 2,
"labelCol": 2,
},
"properties": {
"name": {
"title": "名称",
"x-component": "input",
"x-mega-props": {
"span": 2,
}
},
"networkType": {
"title": "接入方式",
"x-component": "select",
"type": "string",
"enum": [
{
"value": "mqtt",
"label": "MQTT"
},
{
"value": "tcp",
"label": "TCP"
}
],
"x-mega-props": {
"span": 1,
"labelCol": 4
},
},
"certId": {
"title": "证书",
"visible": false,
"x-component": "input",
"x-mega-props": {
"span": 1,
"labelCol": 4
},
},
"host": {
"title": "服务地址",
"visible": false,
"x-component": "input",
"x-mega-props": {
"span": 1,
"labelCol": 4
},
},
"port": {
"title": "端口",
"x-component": "input",
"visible": false,
"x-mega-props": {
"span": 1,
"labelCol": 4
},
},
"clientId": {
"title": "ClientId",
"visible": false,
"x-component": "input",
"x-mega-props": {
"span": 2
},
},
"username": {
"title": "用户名",
"visible": false,
"x-component": "input",
"x-mega-props": {
"span": 2
},
},
"password": {
"title": "密码",
"visible": false,
"x-component": "input",
"x-mega-props": {
"span": 2
},
},
"keepAliveTimeSeconds": {
"title": "心跳间隔",
"visible": false,
"x-component": "input",
"x-mega-props": {
"span": 1,
"labelCol": 4
},
},
}
}
}
}} />
</Modal>
)

};
export default Save;

0 comments on commit 11a94f8

Please sign in to comment.