fix: 修复WebSocket连接URL问题

This commit is contained in:
yangzhe 2025-12-05 11:05:39 +08:00
parent a4d4968fc5
commit 0a55354619
1 changed files with 3 additions and 4 deletions

View File

@ -172,15 +172,14 @@ export default {
buildWsUrl() { buildWsUrl() {
const protocol = const protocol =
window.location.protocol.indexOf("https") === 0 ? "wss" : "ws"; window.location.protocol.indexOf("https") === 0 ? "wss" : "ws";
const host = this.$u.http.config.baseUrl; //
const userId = const userId =
(this.vuex_user && (this.vuex_user.id || this.vuex_user.Id)) || ""; (this.vuex_user && (this.vuex_user.id || this.vuex_user.Id)) || "";
return `${protocol}://${host}/api/Dialogue/HandleConnection?Id=${userId}`; // &equipmentType=0 return `${protocol}://120.55.234.65:8082/api/Dialogue/HandleConnection?Id=${userId}`; // &equipmentType=0
}, },
// WebSocket // WebSocket
initWebSocket() { initWebSocket() {
console.log(this.buildWsUrl()); console.log(this.buildWsUrl());
try { try {
this.ws = new WebSocket(this.buildWsUrl()); this.ws = new WebSocket(this.buildWsUrl());
this.ws.onopen = () => this.handleWsOpen(); this.ws.onopen = () => this.handleWsOpen();
@ -319,7 +318,7 @@ export default {
this.vuex_user && (this.vuex_user.id || this.vuex_user.Id); this.vuex_user && (this.vuex_user.id || this.vuex_user.Id);
const hasToken = const hasToken =
!!this.vuex_token || !!window.localStorage.getItem("token"); !!this.vuex_token || !!window.localStorage.getItem("token");
if (hasUser && hasToken) { if (hasUser && hasToken) {
this.initWebSocket(); this.initWebSocket();
} else { } else {
this.lockReconnect = false; this.lockReconnect = false;