|
@@ -116,13 +116,13 @@ import { ArrowLeft, Avatar, Loading, Picture, VideoPlay } from "@element-plus/ic
|
|
|
import { useWebSocketStore } from "@/stores/modules/websocket";
|
|
import { useWebSocketStore } from "@/stores/modules/websocket";
|
|
|
import { getChatRecord, messageRead, socketStatus, uploadChatFile } from "@/api/modules/storeDecoration";
|
|
import { getChatRecord, messageRead, socketStatus, uploadChatFile } from "@/api/modules/storeDecoration";
|
|
|
import { localGet } from "@/utils";
|
|
import { localGet } from "@/utils";
|
|
|
|
|
+import { getWebSocketBase } from "@/utils/wsBase";
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
const route = useRoute();
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
const socketStore = useWebSocketStore();
|
|
const socketStore = useWebSocketStore();
|
|
|
|
|
|
|
|
-// WebSocket 基础地址(与商家端一致)
|
|
|
|
|
-const WS_BASE = (import.meta.env.VITE_WS_BASE || "ws://120.26.186.130:8000/alienStore/socket/").replace(/\/$/, "");
|
|
|
|
|
|
|
+const isWsReady = () => socketStore.isSocketOpen();
|
|
|
|
|
|
|
|
// 会话信息
|
|
// 会话信息
|
|
|
const sendId = ref("");
|
|
const sendId = ref("");
|
|
@@ -176,7 +176,7 @@ const scrollToBottom = () => {
|
|
|
const handleSend = async () => {
|
|
const handleSend = async () => {
|
|
|
const text = inputText.value?.trim();
|
|
const text = inputText.value?.trim();
|
|
|
if (!text || !receiverId.value) return;
|
|
if (!text || !receiverId.value) return;
|
|
|
- if (!socketStore.isConnected) {
|
|
|
|
|
|
|
+ if (!isWsReady()) {
|
|
|
ElMessage.warning("连接已断开,请稍后重试");
|
|
ElMessage.warning("连接已断开,请稍后重试");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -228,7 +228,7 @@ const handleImageSelect = async (e: Event) => {
|
|
|
const file = target.files?.[0];
|
|
const file = target.files?.[0];
|
|
|
target.value = "";
|
|
target.value = "";
|
|
|
if (!file || !receiverId.value) return;
|
|
if (!file || !receiverId.value) return;
|
|
|
- if (!socketStore.isConnected) {
|
|
|
|
|
|
|
+ if (!isWsReady()) {
|
|
|
ElMessage.warning("连接已断开,请稍后重试");
|
|
ElMessage.warning("连接已断开,请稍后重试");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -278,7 +278,7 @@ const handleVideoSelect = async (e: Event) => {
|
|
|
const file = target.files?.[0];
|
|
const file = target.files?.[0];
|
|
|
target.value = "";
|
|
target.value = "";
|
|
|
if (!file || !receiverId.value) return;
|
|
if (!file || !receiverId.value) return;
|
|
|
- if (!socketStore.isConnected) {
|
|
|
|
|
|
|
+ if (!isWsReady()) {
|
|
|
ElMessage.warning("连接已断开,请稍后重试");
|
|
ElMessage.warning("连接已断开,请稍后重试");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -369,13 +369,18 @@ const initWebSocket = async () => {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
sendId.value = `store_${phone}`;
|
|
sendId.value = `store_${phone}`;
|
|
|
|
|
+ // 与打包 mode 无关:HTTPS 走 wss://当前域名/alienStore/socket,避免 .env.production 仍为 ws 导致混合内容拦截
|
|
|
|
|
+ const WS_BASE = getWebSocketBase();
|
|
|
const wsUrl =
|
|
const wsUrl =
|
|
|
WS_BASE.startsWith("wss") || WS_BASE.startsWith("ws")
|
|
WS_BASE.startsWith("wss") || WS_BASE.startsWith("ws")
|
|
|
? `${WS_BASE}/store_${phone}`
|
|
? `${WS_BASE}/store_${phone}`
|
|
|
: WS_BASE.replace("https", "wss").replace("http", "ws") + `/store_${phone}`;
|
|
: WS_BASE.replace("https", "wss").replace("http", "ws") + `/store_${phone}`;
|
|
|
|
|
|
|
|
- if (!socketStore.isConnected || socketStore.lastConnectedUrl !== wsUrl) {
|
|
|
|
|
- await socketStore.connect(wsUrl);
|
|
|
|
|
|
|
+ if (!isWsReady() || socketStore.lastConnectedUrl !== wsUrl) {
|
|
|
|
|
+ const ok = await socketStore.connect(wsUrl);
|
|
|
|
|
+ if (!ok || !isWsReady()) {
|
|
|
|
|
+ ElMessage.error("即时通讯连接失败,请确认 Nginx 已代理 /alienStore/socket/ 后刷新重试");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (cleanMessageFn) {
|
|
if (cleanMessageFn) {
|
|
|
cleanMessageFn();
|
|
cleanMessageFn();
|