update 云坐席弹窗WebSocket
This commit is contained in:
+4
-2
@@ -1,9 +1,11 @@
|
||||
export function getAppEnvConfig() {
|
||||
const ENV = import.meta.env;
|
||||
const { VITE_GLOB_API_URL, VITE_GLOB_API_YIN_JI, VITE_GLOB_API_JIAN_CE } = ENV;
|
||||
const { VITE_GLOB_API_URL, VITE_GLOB_API_YIN_JI, VITE_GLOB_API_JIAN_CE, VITE_GLOB_API_XIAN_YUN, VITE_GLOB_API_YIN_CHUAN } = ENV;
|
||||
return {
|
||||
VITE_GLOB_API_URL,
|
||||
VITE_GLOB_API_YIN_JI,
|
||||
VITE_GLOB_API_JIAN_CE,
|
||||
VITE_GLOB_API_XIAN_YUN,
|
||||
VITE_GLOB_API_YIN_CHUAN,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+12
-6
@@ -8,11 +8,15 @@ import { useRouter } from 'vue-router';
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const { token } = userStore;
|
||||
const { VITE_GLOB_API_YIN_JI, VITE_GLOB_API_JIAN_CE } = getAppEnvConfig();
|
||||
//健康监测工具报警
|
||||
export const basicPath = VITE_GLOB_API_YIN_JI;
|
||||
const { VITE_GLOB_API_YIN_JI, VITE_GLOB_API_JIAN_CE, VITE_GLOB_API_XIAN_YUN, VITE_GLOB_API_YIN_CHUAN } = getAppEnvConfig();
|
||||
//应急求助
|
||||
export const basicPath = VITE_GLOB_API_YIN_JI;
|
||||
//健康监测工具报警
|
||||
export const emergencyPath = VITE_GLOB_API_JIAN_CE;
|
||||
//西安云坐席
|
||||
export const xianYunPath = VITE_GLOB_API_XIAN_YUN;
|
||||
//银川
|
||||
export const yinChuanPath = VITE_GLOB_API_YIN_CHUAN;
|
||||
let t = token || getAuthCache(TOKEN_KEY);
|
||||
|
||||
export function useSocket(p = basicPath) {
|
||||
@@ -69,6 +73,7 @@ export function useSocket(p = basicPath) {
|
||||
if (typeof WebSocket === 'undefined') {
|
||||
alert('您的浏览器不支持socket');
|
||||
} else {
|
||||
closeSocket();
|
||||
// 实例化socket
|
||||
socket.value = new WebSocket(path.value + Date.now(), [t]);
|
||||
|
||||
@@ -87,10 +92,11 @@ export function useSocket(p = basicPath) {
|
||||
socket.value.onmessage = function (event) {
|
||||
//如果获取到消息,心跳检测重置
|
||||
heartCheck.reset().start(); //拿到任何消息都说明当前连接是正常的
|
||||
//console.log('收到消息:', event.data);
|
||||
console.log('收到消息:', event.data);
|
||||
if (event.data != 'pong') {
|
||||
let data = JSON.parse(event.data);
|
||||
socketData.value = data;
|
||||
// socketData.value = data;
|
||||
setSocketData(data);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -103,7 +109,7 @@ export function useSocket(p = basicPath) {
|
||||
init();
|
||||
|
||||
function closeSocket() {
|
||||
socket.value && socket.value.close;
|
||||
socket.value && socket.value.hasOwnProperty('close') && socket.value.close();
|
||||
}
|
||||
|
||||
return { socket, socketData, setSocketData, closeSocket };
|
||||
|
||||
Reference in New Issue
Block a user