107 lines
3.7 KiB
JavaScript
107 lines
3.7 KiB
JavaScript
|
import config from "@/config";
|
|||
|
import storage from "@/utils/storage";
|
|||
|
import constant from "@/utils/constant";
|
|||
|
import { login, logout, getInfo } from "@/api/login";
|
|||
|
import { getToken, setToken, removeToken } from "@/utils/auth";
|
|||
|
import { GetListid } from "@/api/signln/SignTa/SignTa";
|
|||
|
const baseUrl = config.baseUrl;
|
|||
|
const qnDomain = config.qnDomain;
|
|||
|
const chat = {
|
|||
|
state: {
|
|||
|
token: getToken(),
|
|||
|
socket: storage.get(constant.socket),
|
|||
|
sysMessageInfo:storage.get(constant.sysMessageInfo),
|
|||
|
activiInfo:storage.get(constant.activiInfo),
|
|||
|
sysAuditInfo:storage.get(constant.sysAuditInfo),
|
|||
|
userMessageinfo:storage.get(constant.userMessageinfo),
|
|||
|
interactMessage:storage.get(constant.interactMessage),
|
|||
|
},
|
|||
|
|
|||
|
mutations: {
|
|||
|
SET_socket: (state, socket) => {
|
|||
|
state.socket = socket;
|
|||
|
storage.set(constant.socket, socket);
|
|||
|
},
|
|||
|
|
|||
|
// SET_sysMessageInfo: (state, sysMessageInfo) => {
|
|||
|
// state.sysMessageInfo = sysMessageInfo;
|
|||
|
// storage.set(constant.sysMessageInfo, sysMessageInfo);
|
|||
|
// },
|
|||
|
// SET_sysActiviInfo: (state, activiInfo) => {
|
|||
|
|
|||
|
// state.activiInfo = activiInfo;
|
|||
|
// storage.set(constant.activiInfo, activiInfo);
|
|||
|
// },
|
|||
|
// SET_sysAuditInfo: (state, sysAuditInfo) => {
|
|||
|
// state.sysAuditInfo = sysAuditInfo;
|
|||
|
// storage.set(constant.sysAuditInfo, sysAuditInfo);
|
|||
|
// },
|
|||
|
SET_userMessageinfo: (state, userMessageinfo) => {
|
|||
|
state.userMessageinfo = userMessageinfo;
|
|||
|
storage.set(constant.userMessageinfo, userMessageinfo);
|
|||
|
},
|
|||
|
// SET_interactMessage: (state, interactMessage) => {
|
|||
|
// state.interactMessage = interactMessage;
|
|||
|
// storage.set(constant.interactMessage, interactMessage);
|
|||
|
// }
|
|||
|
},
|
|||
|
|
|||
|
actions: {
|
|||
|
// 进行webSocker链接
|
|||
|
webSockerInfo({ commit }) {
|
|||
|
GetListid().then((res) => {
|
|||
|
let socket = null;
|
|||
|
return new Promise((resolve, reject) => {
|
|||
|
const fileWithoutProtocol = baseUrl.replace(
|
|||
|
/^https?:\/\//,
|
|||
|
""
|
|||
|
);
|
|||
|
const url = "ws://" + fileWithoutProtocol + "/text/text?" + res;
|
|||
|
socket = new WebSocket(url);
|
|||
|
|
|||
|
socket.onopen = () => {
|
|||
|
commit("SET_socket",socket)
|
|||
|
resolve();
|
|||
|
console.log("WebSocket连接已打开");
|
|||
|
};
|
|||
|
|
|||
|
socket.onmessage = (event) => {
|
|||
|
console.log("收到WebSocket消息:", event.data);
|
|||
|
const jsonObject = JSON.parse(event.data);
|
|||
|
// if (jsonObject.messageType == 1){
|
|||
|
// console.log("系统通知:",jsonObject);
|
|||
|
// commit("SET_sysMessageInfo",jsonObject.messageText)
|
|||
|
// }
|
|||
|
// else if (jsonObject.messageType == 2){
|
|||
|
// console.log("审核通知111:",jsonObject);
|
|||
|
// commit("SET_sysAuditInfo",jsonObject.messageText)
|
|||
|
// }
|
|||
|
// else if (jsonObject.messageType == 51 || (jsonObject.messageType == 52)) {
|
|||
|
|
|||
|
// commit("SET_userMessageinfo",jsonObject)
|
|||
|
// }else if (jsonObject.messageType == 61 || (jsonObject.messageType == 62)) {
|
|||
|
// commit("SET_interactMessage",jsonObject)
|
|||
|
// }
|
|||
|
if (jsonObject.messageType == 51 || (jsonObject.messageType == 52)) {
|
|||
|
|
|||
|
commit("SET_userMessageinfo",jsonObject)
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
socket.onerror = (error) => {
|
|||
|
console.error("WebSocket发生错误:", error);
|
|||
|
};
|
|||
|
|
|||
|
socket.onclose = () => {
|
|||
|
console.log("WebSocket连接已关闭");
|
|||
|
reject("WebSocket连接已关闭");
|
|||
|
};
|
|||
|
|
|||
|
});
|
|||
|
});
|
|||
|
},
|
|||
|
},
|
|||
|
};
|
|||
|
|
|||
|
export default chat;
|