refactor: ♻️ 重构首页ws获取在线人数的代码
重构首页ws获取在线人数的代码
This commit is contained in:
@@ -69,7 +69,7 @@ export const useUserStore = defineStore("user", () => {
|
|||||||
// remove token
|
// remove token
|
||||||
function resetToken() {
|
function resetToken() {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
localStorage.setItem(TOKEN_KEY, "");
|
removeToken();
|
||||||
resetRouter();
|
resetRouter();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -188,7 +188,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import WebSocketManager from "@/api/socket";
|
import WebSocketManager from "@/utils/socket";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "Dashboard",
|
name: "Dashboard",
|
||||||
@@ -390,7 +390,7 @@ const getNoticeLevelTag = (type: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function connectWebSocket() {
|
function connectWebSocket() {
|
||||||
WebSocketManager.getWebSocketClient("/topic/onlineUserCount", (message) => {
|
WebSocketManager.getOrCreateClient("/topic/onlineUserCount", (message) => {
|
||||||
onlineUserCount.value = JSON.parse(message);
|
onlineUserCount.value = JSON.parse(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user