-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
使用formily 开发表单 re #203
- Loading branch information
Showing
8 changed files
with
318 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.