feat: 重构signalr,在线人数允许不用登录

This commit is contained in:
陈淳
2024-03-11 17:07:43 +08:00
parent 8857fb24f0
commit 4bb93a947e
8 changed files with 106 additions and 244 deletions

View File

@@ -0,0 +1,22 @@
import signalR from "@/utils/signalR";
import useSocketStore from "@/stores/socket.js";
const receiveMsg=(connection)=> {
connection.on("onlineNum", (data) => {
const socketStore = useSocketStore();
socketStore.setOnlineNum(data);
});
connection.on("forceOut", (msg) => {
useUserStore()
.logOut()
.then(() => {
alert(msg);
location.href = "/index";
});
});
};
export default ()=>{
signalR.start(`main`,receiveMsg);
}

View File

@@ -0,0 +1,28 @@
import signalR from "@/utils/signalR";
const receiveMsg=(connection)=> {
connection.on("receiveNotice", (type, title, content) => {
switch (type) {
case "MerryGoRound":
ElNotification({
title: title,
dangerouslyUseHTMLString: true,
message: content,
})
break;
case "Popup":
ElNotification({
title: title,
dangerouslyUseHTMLString: true,
message: content,
})
break;
}
});
};
export default ()=>{
signalR.start(`notice`,receiveMsg);
}