diff --git a/src/utils/webSocketClient.ts b/src/utils/webSocketClient.ts index a707d801..317ddc7f 100644 --- a/src/utils/webSocketClient.ts +++ b/src/utils/webSocketClient.ts @@ -38,19 +38,23 @@ export default class SocketService { } // 定义连接服务器的方法 - public connect(id: string): void { + public async connect(id: string) { if (!window.WebSocket) { console.log('您的浏览器不支持WebSocket') return } - const url = 'ws://192.168.1.67:10407/api/pushMessage/' + id - this.ws = new WebSocket(url) + const response = await fetch('/') + const mqttUrl = response.headers.get('X-Mqtt-Url') + setTimeout(() => { + const url = (mqttUrl || 'ws://192.168.1.67:10407/api/pushMessage/') + id + this.ws = new WebSocket(url) - this.ws.onopen = () => this.handleOpen() - this.ws.onclose = () => this.handleClose() - this.ws.onerror = () => this.handleError() - this.ws.onmessage = event => this.handleMessage(event) + this.ws.onopen = () => this.handleOpen() + this.ws.onclose = () => this.handleClose() + this.ws.onerror = () => this.handleError() + this.ws.onmessage = event => this.handleMessage(event) + }, 0) } // 处理连接成功事件 diff --git a/src/views/pqs/harmonicMonitoring/monitoringPoint/online/index.vue b/src/views/pqs/harmonicMonitoring/monitoringPoint/online/index.vue index fb9e65fb..93ba14e0 100644 --- a/src/views/pqs/harmonicMonitoring/monitoringPoint/online/index.vue +++ b/src/views/pqs/harmonicMonitoring/monitoringPoint/online/index.vue @@ -73,7 +73,7 @@ import Shishishuju from './shishishuju/index.vue' import router from '@/router' defineOptions({ - name: 'harmonic-boot/monitor/online' + // name: 'harmonic-boot/monitor/online' }) const monitoringPoint = useMonitoringPoint()