Trim admin runtime imports
This commit is contained in:
@@ -9,7 +9,6 @@ import type { WatchStopHandle } from 'vue';
|
||||
import {
|
||||
computed,
|
||||
defineAsyncComponent,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
ref,
|
||||
watch,
|
||||
@@ -61,14 +60,11 @@ const { destroyWatermark, updateWatermark } = useWatermark();
|
||||
const router = useRouter();
|
||||
let notificationApi: any = null;
|
||||
let chatApi: any = null;
|
||||
let layoutActive = false;
|
||||
let layoutActive = true;
|
||||
let realtimeInitializing: Promise<void> | null = null;
|
||||
let realtimeInitialized = false;
|
||||
let stopRealtimeWatches: WatchStopHandle[] = [];
|
||||
|
||||
onMounted(() => {
|
||||
layoutActive = true;
|
||||
initRealtimeFeatures();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
layoutActive = false;
|
||||
stopRealtimeWatches.forEach((stop) => stop());
|
||||
@@ -78,6 +74,16 @@ onUnmounted(() => {
|
||||
});
|
||||
|
||||
async function initRealtimeFeatures() {
|
||||
if (realtimeInitialized) return;
|
||||
if (realtimeInitializing) return realtimeInitializing;
|
||||
|
||||
realtimeInitializing = doInitRealtimeFeatures().finally(() => {
|
||||
realtimeInitializing = null;
|
||||
});
|
||||
await realtimeInitializing;
|
||||
}
|
||||
|
||||
async function doInitRealtimeFeatures() {
|
||||
const [notificationModule, chatModule] = await Promise.all([
|
||||
import('#/composables/useNotification'),
|
||||
import('#/views/_core/chat/composables/useChat'),
|
||||
@@ -144,6 +150,7 @@ async function initRealtimeFeatures() {
|
||||
chatApi.connectChat();
|
||||
chatApi.loadConversations();
|
||||
chatApi.loadUnreadChatMessages();
|
||||
realtimeInitialized = true;
|
||||
}
|
||||
|
||||
const menus = computed(() => [
|
||||
@@ -228,6 +235,10 @@ function handleTabChange(tab: 'announcement' | 'chat' | 'message') {
|
||||
}
|
||||
}
|
||||
|
||||
function handleNotificationOpen() {
|
||||
void initRealtimeFeatures();
|
||||
}
|
||||
|
||||
function handleChatClick(msg: ChatMessage) {
|
||||
// 新开tab跳转到聊天页面,带上会话ID
|
||||
const url = router.resolve(
|
||||
@@ -290,6 +301,7 @@ watch(
|
||||
@clear="handleNoticeClear"
|
||||
@click-chat="handleChatClick"
|
||||
@make-all="handleMakeAll"
|
||||
@open="handleNotificationOpen"
|
||||
@read-message="handleNoticeRead"
|
||||
@read-announcement="handleAnnouncementRead"
|
||||
@view-all="handleViewAll"
|
||||
|
||||
Reference in New Issue
Block a user