Commit 46d5f76b authored by 崔婷婷's avatar 崔婷婷

v2

parent 38039a32
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="alternate icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>工厂生产看板</title> <title>工厂生产看板</title>
</head> </head>
......
This diff is collapsed.
This diff is collapsed.
...@@ -15,12 +15,13 @@ ...@@ -15,12 +15,13 @@
* VITE_WS_URL — WebSocket 地址,默认 ws://127.0.0.1:8080/ws * VITE_WS_URL — WebSocket 地址,默认 ws://127.0.0.1:8080/ws
*/ */
const WS_URL = import.meta.env.VITE_WS_URL || 'ws://127.0.0.1:8080/ws'
const RECONNECT_DELAY = 2000 // 断线重连间隔(ms) const RECONNECT_DELAY = 2000 // 断线重连间隔(ms)
const PING_INTERVAL = 10000 // 心跳间隔(ms) const PING_INTERVAL = 10000 // 心跳间隔(ms)
const MAX_RECONNECTS = 0 // 0 = 无限重连 const MAX_RECONNECTS = 0 // 0 = 无限重连
export function connect() { export function connect(url) {
const wsUrl = url || import.meta.env.VITE_WS_URL || 'ws://127.0.0.1:8080/ws'
const handlers = {} const handlers = {}
const api = { const api = {
...@@ -41,6 +42,7 @@ export function connect() { ...@@ -41,6 +42,7 @@ export function connect() {
}, },
close() { close() {
clearInterval(pingTimer) clearInterval(pingTimer)
clearTimeout(reconnectTimer)
reconnectCount = -1 // 阻止重连 reconnectCount = -1 // 阻止重连
if (socket) socket.close() if (socket) socket.close()
}, },
...@@ -57,7 +59,7 @@ export function connect() { ...@@ -57,7 +59,7 @@ export function connect() {
} }
function createSocket() { function createSocket() {
socket = new WebSocket(WS_URL) socket = new WebSocket(wsUrl)
socket.addEventListener('open', () => { socket.addEventListener('open', () => {
reconnectCount = 0 reconnectCount = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment