Trim locale and notification payload
This commit is contained in:
@@ -1,19 +1,11 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ChatMessage } from '#/api/core/chat';
|
||||
import type {
|
||||
AnnouncementItem,
|
||||
NotificationItem,
|
||||
} from '#/composables/useNotification';
|
||||
import type { WatchStopHandle } from 'vue';
|
||||
|
||||
import {
|
||||
computed,
|
||||
defineAsyncComponent,
|
||||
onUnmounted,
|
||||
ref,
|
||||
watch,
|
||||
} from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { computed, defineAsyncComponent, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
import { useWatermark } from '@vben/hooks';
|
||||
import { BasicLayout } from '@vben/layouts';
|
||||
@@ -27,11 +19,13 @@ import { useAuthStore } from '#/store';
|
||||
const LoginForm = defineAsyncComponent(
|
||||
() => import('#/views/_core/authentication/login.vue'),
|
||||
);
|
||||
const AuthenticationLoginExpiredModal = defineAsyncComponent(() =>
|
||||
import('@vben/common-ui/es/login-expired-modal'),
|
||||
const AuthenticationLoginExpiredModal = defineAsyncComponent(
|
||||
() => import('@vben/common-ui/es/login-expired-modal'),
|
||||
);
|
||||
const UserDropdown = defineAsyncComponent(() =>
|
||||
import('@vben/layouts/es/user-dropdown').then((module) => module.UserDropdown),
|
||||
import('@vben/layouts/es/user-dropdown').then(
|
||||
(module) => module.UserDropdown,
|
||||
),
|
||||
);
|
||||
const NotificationPopup = defineAsyncComponent(
|
||||
() => import('#/components/notification/NotificationPopup.vue'),
|
||||
@@ -41,12 +35,10 @@ const notifications = ref<NotificationItem[]>([]);
|
||||
const messageUnreadCount = ref(0);
|
||||
const announcements = ref<AnnouncementItem[]>([]);
|
||||
const announcementUnreadCount = ref(0);
|
||||
const activeTab = ref<'announcement' | 'chat' | 'message'>('message');
|
||||
const activeTab = ref<'announcement' | 'message'>('message');
|
||||
const showDot = computed(
|
||||
() => messageUnreadCount.value + announcementUnreadCount.value > 0,
|
||||
);
|
||||
const unreadChatMessages = ref<ChatMessage[]>([]);
|
||||
const chatTotalUnread = ref(0);
|
||||
|
||||
const userStore = useUserStore();
|
||||
const authStore = useAuthStore();
|
||||
@@ -54,9 +46,7 @@ const accessStore = useAccessStore();
|
||||
const { destroyWatermark, updateWatermark } = useWatermark();
|
||||
|
||||
// 初始化消息通知
|
||||
const router = useRouter();
|
||||
let notificationApi: any = null;
|
||||
let chatApi: any = null;
|
||||
let layoutActive = true;
|
||||
let realtimeInitializing: Promise<void> | null = null;
|
||||
let realtimeInitialized = false;
|
||||
@@ -67,7 +57,6 @@ onUnmounted(() => {
|
||||
stopRealtimeWatches.forEach((stop) => stop());
|
||||
stopRealtimeWatches = [];
|
||||
notificationApi?.cleanup();
|
||||
chatApi?.disconnectChat();
|
||||
});
|
||||
|
||||
async function initRealtimeFeatures() {
|
||||
@@ -81,15 +70,11 @@ async function initRealtimeFeatures() {
|
||||
}
|
||||
|
||||
async function doInitRealtimeFeatures() {
|
||||
const [notificationModule, chatModule] = await Promise.all([
|
||||
import('#/composables/useNotification'),
|
||||
import('#/views/_core/chat/composables/useChat'),
|
||||
]);
|
||||
const notificationModule = await import('#/composables/useNotification');
|
||||
|
||||
if (!layoutActive) return;
|
||||
|
||||
notificationApi = notificationModule.useNotification();
|
||||
chatApi = chatModule.useChat();
|
||||
|
||||
stopRealtimeWatches = [
|
||||
watch(
|
||||
@@ -123,30 +108,13 @@ async function doInitRealtimeFeatures() {
|
||||
watch(
|
||||
notificationApi.activeTab,
|
||||
(value) => {
|
||||
activeTab.value = value;
|
||||
},
|
||||
{ immediate: true },
|
||||
),
|
||||
watch(
|
||||
chatApi.unreadChatMessages,
|
||||
(value) => {
|
||||
unreadChatMessages.value = value;
|
||||
},
|
||||
{ immediate: true },
|
||||
),
|
||||
watch(
|
||||
chatApi.totalUnread,
|
||||
(value) => {
|
||||
chatTotalUnread.value = value;
|
||||
activeTab.value = value === 'announcement' ? value : 'message';
|
||||
},
|
||||
{ immediate: true },
|
||||
),
|
||||
];
|
||||
|
||||
notificationApi.init();
|
||||
chatApi.connectChat();
|
||||
chatApi.loadConversations();
|
||||
chatApi.loadUnreadChatMessages();
|
||||
realtimeInitialized = true;
|
||||
}
|
||||
|
||||
@@ -225,7 +193,7 @@ function handleViewAll() {
|
||||
notificationApi?.viewAllMessages();
|
||||
}
|
||||
|
||||
function handleTabChange(tab: 'announcement' | 'chat' | 'message') {
|
||||
function handleTabChange(tab: 'announcement' | 'message') {
|
||||
activeTab.value = tab;
|
||||
if (notificationApi) {
|
||||
notificationApi.activeTab.value = tab;
|
||||
@@ -236,19 +204,6 @@ function handleNotificationOpen() {
|
||||
void initRealtimeFeatures();
|
||||
}
|
||||
|
||||
function handleChatClick(msg: ChatMessage) {
|
||||
// 新开tab跳转到聊天页面,带上会话ID
|
||||
const url = router.resolve(
|
||||
`/chat?conversationId=${msg.conversation_id}`,
|
||||
).href;
|
||||
window.open(url, '_blank');
|
||||
|
||||
// 从未读聊天列表中移除
|
||||
const index = unreadChatMessages.value.findIndex((m) => m.id === msg.id);
|
||||
if (index !== -1) {
|
||||
unreadChatMessages.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => ({
|
||||
enable: preferences.app.watermark,
|
||||
@@ -287,16 +242,13 @@ watch(
|
||||
</template>
|
||||
<template #notification>
|
||||
<NotificationPopup
|
||||
:dot="showDot || chatTotalUnread > 0"
|
||||
:dot="showDot"
|
||||
:notifications="notifications"
|
||||
:message-unread-count="messageUnreadCount"
|
||||
:announcements="announcements"
|
||||
:announcement-unread-count="announcementUnreadCount"
|
||||
:unread-chats="unreadChatMessages"
|
||||
:chat-unread-count="chatTotalUnread"
|
||||
:active-tab="activeTab"
|
||||
@clear="handleNoticeClear"
|
||||
@click-chat="handleChatClick"
|
||||
@make-all="handleMakeAll"
|
||||
@open="handleNotificationOpen"
|
||||
@read-message="handleNoticeRead"
|
||||
@@ -322,7 +274,8 @@ watch(
|
||||
sidebarFooterProps?.compact
|
||||
? PRODUCT_BRAND_SHORT
|
||||
: $t('ui.layout.poweredBy')
|
||||
}}</span>
|
||||
}}</span
|
||||
>
|
||||
</button>
|
||||
</template>
|
||||
<template #extra>
|
||||
|
||||
Reference in New Issue
Block a user