|
|
@@ -351,7 +351,7 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { Icon } from "@iconify/vue";
|
|
|
-import { ref, computed, onMounted } from "vue";
|
|
|
+import { ref, computed, onMounted, onBeforeUnmount } from "vue";
|
|
|
import { useRouter } from "vue-router";
|
|
|
import logo from "@/assets/images/logo.png";
|
|
|
import person from "@/assets/images/person.png";
|
|
|
@@ -375,6 +375,7 @@ import {
|
|
|
} from "@utils/auth";
|
|
|
|
|
|
import { deleteUserCache } from "@hooks/useCache";
|
|
|
+import { manualLogoutKey, reloginCancelKey } from "@/config/axios/service";
|
|
|
|
|
|
// 新增消息中心状态
|
|
|
const activeTab = ref("messages");
|
|
|
@@ -408,13 +409,19 @@ const oaMessagesList = ref([]);
|
|
|
|
|
|
const unreadCount = ref(0); // 未读消息数量
|
|
|
const getUnreadCount = async () => {
|
|
|
- getUnreadNotifyMessageCount().then((data) => {
|
|
|
- unreadCount.value = data;
|
|
|
- });
|
|
|
+ if (!getAccessToken()) {
|
|
|
+ unreadCount.value = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const data = await getUnreadNotifyMessageCount();
|
|
|
+ unreadCount.value = data;
|
|
|
};
|
|
|
+let messageTimer: ReturnType<typeof setInterval> | undefined;
|
|
|
+let unreadTimer: ReturnType<typeof setInterval> | undefined;
|
|
|
onMounted(async () => {
|
|
|
- getUnreadCount();
|
|
|
if (isLoggedIn.value) {
|
|
|
+ getUnreadCount();
|
|
|
await getNotifyMessages(userStore.getUser.username);
|
|
|
const messageList = await getNotifyMessageList(userStore.getUser.username);
|
|
|
messages.value = messageList.filter((msg: any) => msg.status === "0");
|
|
|
@@ -427,7 +434,7 @@ onMounted(async () => {
|
|
|
oaMessagesList.value = oaMessageList.filter((msg) => msg.status === "0");
|
|
|
}
|
|
|
|
|
|
- setInterval(
|
|
|
+ messageTimer = setInterval(
|
|
|
async () => {
|
|
|
if (isLoggedIn.value) {
|
|
|
await getNotifyMessages(userStore.getUser.username);
|
|
|
@@ -449,9 +456,9 @@ onMounted(async () => {
|
|
|
1000 * 60 * 5,
|
|
|
);
|
|
|
|
|
|
- setInterval(
|
|
|
+ unreadTimer = setInterval(
|
|
|
() => {
|
|
|
- if (userStore.getIsSetUser) {
|
|
|
+ if (userStore.getIsSetUser && getAccessToken()) {
|
|
|
console.log("轮询刷新小红点");
|
|
|
getUnreadCount();
|
|
|
} else {
|
|
|
@@ -462,6 +469,15 @@ onMounted(async () => {
|
|
|
);
|
|
|
});
|
|
|
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ if (messageTimer) {
|
|
|
+ clearInterval(messageTimer);
|
|
|
+ }
|
|
|
+ if (unreadTimer) {
|
|
|
+ clearInterval(unreadTimer);
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
function timestampToDateTime(timestamp) {
|
|
|
// 兼容 10位(秒) / 13位(毫秒)
|
|
|
const len = String(timestamp).length;
|
|
|
@@ -521,8 +537,10 @@ const onUserCommand = async (command: string) => {
|
|
|
// await userStore.loginOut();
|
|
|
|
|
|
deleteUserCache(); // 删除用户缓存
|
|
|
+ sessionStorage.setItem(manualLogoutKey, "true");
|
|
|
+ sessionStorage.removeItem(reloginCancelKey);
|
|
|
removeToken();
|
|
|
- window.location.reload();
|
|
|
+ window.location.href = "/login";
|
|
|
}
|
|
|
};
|
|
|
</script>
|