File size: 4,637 Bytes
8ede856 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | <script setup lang="ts">
import { RouterView, useRoute } from 'vue-router';
import { ref, onMounted, computed } from 'vue';
import axios from 'axios';
import VerticalSidebarVue from './vertical-sidebar/VerticalSidebar.vue';
import VerticalHeaderVue from './vertical-header/VerticalHeader.vue';
import MigrationDialog from '@/components/shared/MigrationDialog.vue';
import ReadmeDialog from '@/components/shared/ReadmeDialog.vue';
import Chat from '@/components/chat/Chat.vue';
import { useCustomizerStore } from '@/stores/customizer';
import { useRouterLoadingStore } from '@/stores/routerLoading';
import { useI18n } from '@/i18n/composables';
const FIRST_NOTICE_SEEN_KEY = 'astrbot:first_notice_seen:v1';
const customizer = useCustomizerStore();
const { locale } = useI18n();
const route = useRoute();
const routerLoadingStore = useRouterLoadingStore();
const isChatPage = computed(() => {
return route.path.startsWith('/chat');
});
const showSidebar = computed(() => {
return customizer.viewMode === 'bot';
});
const showChatPage = computed(() => {
return customizer.viewMode === 'chat';
});
const migrationDialog = ref<InstanceType<typeof MigrationDialog> | null>(null);
const showFirstNoticeDialog = ref(false);
const checkMigration = async (): Promise<boolean> => {
try {
const response = await axios.get('/api/stat/version');
if (response.data.status === 'ok' && response.data.data.need_migration) {
if (migrationDialog.value && typeof migrationDialog.value.open === 'function') {
const result = await migrationDialog.value.open();
if (result.success) {
console.log('Migration completed successfully:', result.message);
window.location.reload();
}
}
return true;
}
} catch (error) {
console.error('Failed to check migration status:', error);
}
return false;
};
const maybeShowFirstNotice = async () => {
if (localStorage.getItem(FIRST_NOTICE_SEEN_KEY) === '1') {
return;
}
try {
const response = await axios.get('/api/stat/first-notice', {
params: { locale: locale.value },
});
if (response.data.status !== 'ok') {
return;
}
const content = response.data?.data?.content;
if (typeof content === 'string' && content.trim().length > 0) {
showFirstNoticeDialog.value = true;
return;
}
localStorage.setItem(FIRST_NOTICE_SEEN_KEY, '1');
} catch (error) {
console.error('Failed to load first notice:', error);
}
};
const onFirstNoticeDialogUpdate = (visible: boolean) => {
showFirstNoticeDialog.value = visible;
if (!visible) {
localStorage.setItem(FIRST_NOTICE_SEEN_KEY, '1');
}
};
onMounted(() => {
setTimeout(async () => {
const migrationPending = await checkMigration();
if (!migrationPending) {
await maybeShowFirstNotice();
}
}, 1000);
});
</script>
<template>
<v-locale-provider>
<v-app :theme="useCustomizerStore().uiTheme"
:class="[customizer.fontTheme, customizer.mini_sidebar ? 'mini-sidebar' : '', customizer.inputBg ? 'inputWithbg' : '']"
>
<v-progress-linear
v-if="routerLoadingStore.isLoading"
:model-value="routerLoadingStore.progress"
color="primary"
height="2"
fixed
top
style="z-index: 9999; position: absolute; opacity: 0.3; "
/>
<VerticalHeaderVue />
<VerticalSidebarVue v-if="showSidebar" />
<v-main :style="{
height: showChatPage ? 'calc(100vh - 55px)' : undefined,
overflow: showChatPage ? 'hidden' : undefined
}">
<v-container
fluid
class="page-wrapper"
:class="{ 'chat-mode-container': showChatPage }"
:style="{
height: showChatPage ? '100%' : 'calc(100% - 8px)',
padding: (isChatPage || showChatPage) ? '0' : undefined,
minHeight: showChatPage ? 'unset' : undefined
}">
<div :style="{ height: '100%', width: '100%', overflow: showChatPage ? 'hidden' : undefined }">
<div v-if="showChatPage" style="height: 100%; width: 100%; overflow: hidden;">
<Chat />
</div>
<RouterView v-else />
</div>
</v-container>
</v-main>
<MigrationDialog ref="migrationDialog" />
<ReadmeDialog
:show="showFirstNoticeDialog"
mode="first-notice"
@update:show="onFirstNoticeDialogUpdate"
/>
</v-app>
</v-locale-provider>
</template>
<style scoped>
.chat-mode-container {
min-height: unset !important;
height: 100% !important;
overflow: hidden !important;
}
</style>
|