-
-
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.
设备调试
- Loading branch information
Showing
7 changed files
with
224 additions
and
254 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Input, Tabs } from "antd"; | ||
import React, { useEffect, useState } from "react"; | ||
import Service from "../../service"; | ||
import Session from "./session"; | ||
|
||
interface Props { | ||
data: any | ||
} | ||
const Debugger: React.FC<Props> = props => { | ||
const { data } = props; | ||
const service = new Service('network/simulator'); | ||
const [sessions, setSessions] = useState<any[]>([]); | ||
const [key, setkey] = useState<string>(''); | ||
|
||
useEffect(() => { | ||
service.sessions(data.id, 1000, 0) | ||
.subscribe(data => { | ||
setSessions(data); | ||
}) | ||
setkey(sessions.length > 0 ? sessions[0].id : ''); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (sessions && sessions[0]) { | ||
setkey(sessions[0].id); | ||
} | ||
}, [sessions[0]]) | ||
|
||
|
||
return ( | ||
<> | ||
<Tabs | ||
tabBarExtraContent={( | ||
<div > | ||
<Input.Search /> | ||
</div> | ||
)} | ||
style={{ height: 500 }} | ||
tabPosition={"left"} | ||
defaultActiveKey={sessions.length > 0 ? sessions[0].id : ''} | ||
onChange={(key => setkey(key))}> | ||
{ | ||
sessions.map((item, index) => | ||
<Tabs.TabPane key={item.id} tab={item.id}> | ||
{(key === item.id) && <Session item={item} data={data} />} | ||
</Tabs.TabPane>) | ||
} | ||
</Tabs> | ||
</> | ||
) | ||
} | ||
export default Debugger; |
58 changes: 58 additions & 0 deletions
58
src/pages/simulator/device/detail/debugger/session/index.tsx
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,58 @@ | ||
import { getWebsocket } from "@/layouts/GlobalWebSocket"; | ||
import { Input, Divider, Button, Row, Col, message } from "antd"; | ||
import React, { useEffect, useState } from "react"; | ||
import Service from "../../../service"; | ||
|
||
interface Props { | ||
data: any; | ||
item: any | ||
} | ||
const Session: React.FC<Props> = props => { | ||
const { data, item } = props; | ||
const [subMsg, setSubMsg] = useState<any>(''); | ||
const service = new Service('network/simulator'); | ||
|
||
const [msg, setMsg] = useState<string>(''); | ||
useEffect(() => { | ||
console.log(`获取${item.id},${data.id}消息`); | ||
let simulator = getWebsocket( | ||
`network-simulator-session`, | ||
`/network/simulator/${data.id}/${item.id}`, | ||
{}, | ||
).subscribe( | ||
(resp: any) => { | ||
setSubMsg(resp); | ||
}, | ||
); | ||
return () => { | ||
console.log('取消订阅,' + item.id); | ||
simulator.unsubscribe(); | ||
} | ||
}, [item]); | ||
const sendMsg = (msg: string) => { | ||
service.sendMessage(data.id, item.id, msg).subscribe( | ||
() => { | ||
message.success('发送成功!') | ||
}, | ||
() => message.error('保存失败!')) | ||
} | ||
|
||
return ( | ||
<div> | ||
<Input.TextArea rows={17} value={subMsg.payload} /> | ||
<Divider /> | ||
<Row gutter={10}> | ||
<Col span={20}> | ||
<Input.TextArea rows={3} onChange={e => setMsg(e.target.value)} /> | ||
</Col> | ||
<Col span={3}> | ||
<Button | ||
onClick={() => { sendMsg(msg) }} | ||
style={{ width: 100, height: 75 }} | ||
type="primary">发送</Button> | ||
</Col> | ||
</Row> | ||
</div> | ||
) | ||
} | ||
export default Session; |
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 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
Oops, something went wrong.