增加开发时候的ws连接和打包时候的ws连接
This commit is contained in:
parent
85c6a22c05
commit
6ed99bb6db
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, {useRef, useState, useEffect, useCallback } from 'react';
|
||||||
|
|
||||||
import Home from "@/page/Home"
|
import Home from "@/page/Home"
|
||||||
import { DefaultSpeedDial } from "@/components/DefaultSpeedDial"
|
import { DefaultSpeedDial } from "@/components/DefaultSpeedDial"
|
||||||
|
@ -11,10 +11,11 @@ export default function App() {
|
||||||
const NotFound = () => {
|
const NotFound = () => {
|
||||||
return <div>你来到了没有知识的荒原</div>
|
return <div>你来到了没有知识的荒原</div>
|
||||||
}
|
}
|
||||||
|
const homemodule = useRef(null);
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Home />} />
|
<Route path="/" element={<Home ref={homemodule} />} />
|
||||||
<Route path="/home" element={<Home />} />
|
<Route path="/home" element={<Home />} />
|
||||||
<Route path="/NotFound" element={<NotFound />} />
|
<Route path="/NotFound" element={<NotFound />} />
|
||||||
{/* <Route path="/about" element={<About />} />
|
{/* <Route path="/about" element={<About />} />
|
||||||
|
|
|
@ -7,7 +7,10 @@ class ReactWebsocket {
|
||||||
constructor() {
|
constructor() {
|
||||||
//首次使用构造器实例
|
//首次使用构造器实例
|
||||||
if (!ReactWebsocket.instance) {
|
if (!ReactWebsocket.instance) {
|
||||||
this.ws=new WebSocket("ws://127.0.0.1:1323/ws");
|
let agreement=window.location.protocol=="http:"?"ws://":"wss://"
|
||||||
|
let wsurl=agreement+window.location.host+'/ws'
|
||||||
|
let dev_ws_url="ws://127.0.0.1:1323/ws"
|
||||||
|
this.ws=new WebSocket(dev_ws_url);
|
||||||
this.callbackMap= new Map();
|
this.callbackMap= new Map();
|
||||||
this.noMessageSent= new Queue();
|
this.noMessageSent= new Queue();
|
||||||
this.ws.onmessage=((evt)=>{this.OnMessage(evt)})
|
this.ws.onmessage=((evt)=>{this.OnMessage(evt)})
|
||||||
|
|
|
@ -51,6 +51,8 @@ export function DefaultSpeedDial() {
|
||||||
// socket.sendMessage('add', {name:NameValue,mac:MacValue}, function () { updata() })
|
// socket.sendMessage('add', {name:NameValue,mac:MacValue}, function () { updata() })
|
||||||
socket.sendMessage('add', {name:NameValue,mac:MacValue}, function () { })
|
socket.sendMessage('add', {name:NameValue,mac:MacValue}, function () { })
|
||||||
handleOpen()
|
handleOpen()
|
||||||
|
setNameValue('')
|
||||||
|
setMacValue('')
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -90,7 +92,7 @@ export function DefaultSpeedDial() {
|
||||||
>
|
>
|
||||||
<span>取消</span>
|
<span>取消</span>
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="gradient" color="green" onClick={handleOpen}>
|
<Button variant="gradient" color="green" onClick={AddItemClick}>
|
||||||
<span>确认</span>
|
<span>确认</span>
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|
Loading…
Reference in New Issue