171 lines
5.1 KiB
Vue
171 lines
5.1 KiB
Vue
<script setup lang="ts">
|
|
import type { NavigationMenuItem } from '@nuxt/ui';
|
|
import { provideNavbarHeight } from '~/composables/useNavbarHeight';
|
|
|
|
const isHome = computed(() => useRoute().path === '/');
|
|
const items = ref<NavigationMenuItem[]>([
|
|
{
|
|
label: '首页',
|
|
icon: 'i-lucide-home',
|
|
to: '/',
|
|
// 如果使用isHome.value 将失去响应性 但是active只接受boolean 或 undefined
|
|
// 所以需要使用as unknown as boolean 来强制转换定义 (安抚类型检查quq)
|
|
// 但是 ComputedRef 竟然也能用
|
|
// ts, 很神奇吧
|
|
active: isHome as unknown as boolean,
|
|
},
|
|
{
|
|
label: '归档',
|
|
icon: 'i-lucide-paperclip',
|
|
to: '/archive',
|
|
},
|
|
{
|
|
label: '友链',
|
|
icon: 'i-lucide-link',
|
|
to: '/friends',
|
|
},
|
|
{
|
|
label: '关于',
|
|
icon: 'i-lucide-info',
|
|
to: '/about',
|
|
},
|
|
]);
|
|
|
|
useHead({
|
|
link: [
|
|
{
|
|
rel: 'preload',
|
|
as: 'image',
|
|
href: '/79d52228c770808810a310115567e6790380823a.webp',
|
|
type: 'image/webp',
|
|
fetchpriority: 'high',
|
|
},
|
|
{
|
|
rel: 'preload',
|
|
as: 'image',
|
|
href: '/anime-8788959.webp',
|
|
type: 'image/webp',
|
|
fetchpriority: 'high',
|
|
},
|
|
],
|
|
});
|
|
|
|
const collapsed = ref(false);
|
|
let collapseCancel: number | undefined = undefined;
|
|
|
|
function startCollapseCountdown() {
|
|
if (scrollY.value === 0) {
|
|
collapseCancel = setTimeout(() => {
|
|
collapsed.value = false;
|
|
}, 300);
|
|
}
|
|
}
|
|
|
|
function stopCollapseCountDownAndStopCollapse() {
|
|
clearTimeout(collapseCancel);
|
|
collapsed.value = true;
|
|
}
|
|
|
|
onMounted(() => {
|
|
setTimeout(() => {
|
|
collapsed.value = true;
|
|
}, 2000);
|
|
});
|
|
const scrollY = useWindowScroll().y;
|
|
const isScrollDown = ref(false);
|
|
|
|
watch(scrollY, (newY) => {
|
|
if (newY > 0 && !collapsed.value) {
|
|
collapsed.value = true;
|
|
}
|
|
isScrollDown.value = newY > 215;
|
|
});
|
|
|
|
const isLoading = ref(false);
|
|
|
|
useRouter().beforeEach(() => {
|
|
isLoading.value = true;
|
|
});
|
|
|
|
useRouter().afterEach(() => {
|
|
isLoading.value = false;
|
|
});
|
|
|
|
const mounted = ref(false);
|
|
onMounted(() => {
|
|
mounted.value = true;
|
|
});
|
|
|
|
const navbarEl = ref<HTMLDivElement>();
|
|
const { height: navbarHeight } = useElementSize(navbarEl);
|
|
|
|
provideNavbarHeight(navbarHeight);
|
|
</script>
|
|
|
|
<template>
|
|
<div class="bg-old-neutral-50 dark:bg-[#0b0d0d] w-full min-h-screen h-full">
|
|
<UApp>
|
|
<div
|
|
:class="collapsed
|
|
? 'h-[clamp(8rem,11.25vw,27rem)]'
|
|
: 'h-[clamp(12rem,16.6667vw,40rem)]'"
|
|
class="flex flex-col relative transition-[height] duration-500">
|
|
<div
|
|
@mouseenter="startCollapseCountdown()" @mouseleave="stopCollapseCountDownAndStopCollapse()">
|
|
<div
|
|
class="flex bg-top absolute w-full h-full bg-[url('/79d52228c770808810a310115567e6790380823a.webp')] dark:bg-[url('/anime-8788959.webp')] bg-cover bg-no-repeat">
|
|
<slot name="header"/>
|
|
</div>
|
|
<div v-if="isScrollDown">
|
|
<div
|
|
class="opacity-80 dark:opacity-20 max-h-12 flex w-full h-full fixed bg-[url('/79d52228c770808810a310115567e6790380823a.webp')] dark:bg-[url('/anime-8788959.webp')] bg-cover bg-no-repeat bg-top dark:bg-center"/>
|
|
</div>
|
|
</div>
|
|
<!-- navbar -->
|
|
<div
|
|
ref="navbarEl"
|
|
class="fixed z-10 w-full transition-all duration-500 dark:bg-gray-800/60 bg-old-neutral-50/40 backdrop-blur-sm dark:backdrop-blur-md">
|
|
<div class="flex justify-center items-center h-full">
|
|
<div class="flex-1 overflow-hidden">
|
|
<slot name="navbarLeft" :is-scroll-down="isScrollDown"/>
|
|
</div>
|
|
<div
|
|
class="transition-[width] duration-500 flex 2xl:w-310 xl:w-255 lg:w-241 md:w-177 sm:w-145 w-10/12">
|
|
<UNavigationMenu
|
|
:items="items"
|
|
class="w-full
|
|
[--ui-text-muted:var(--color-gray-600)]
|
|
[--ui-text-dimmed:var(--color-gray-600)]
|
|
dark:[--ui-text-muted:var(--color-gray-200)]
|
|
dark:[--ui-text-dimmed:var(--color-gray-200)]"
|
|
/>
|
|
</div>
|
|
<div class="flex-1 overflow-hidden">
|
|
<slot name="navbarRight" :is-scroll-down="isScrollDown"/>
|
|
</div>
|
|
</div>
|
|
<Transition
|
|
enter-active-class="transition-opacity duration-500 ease-in-out"
|
|
enter-from-class="opacity-0"
|
|
enter-to-class="opacity-100"
|
|
leave-active-class="transition-opacity duration-500 ease-in-out"
|
|
leave-from-class="opacity-100"
|
|
leave-to-class="opacity-0">
|
|
<UProgress v-if="isLoading" :size="'sm'" class="fixed z-20"/>
|
|
</Transition>
|
|
</div>
|
|
|
|
</div>
|
|
<!-- content -->
|
|
<div class="flex justify-center items-center bg-white dark:bg-[#16191b] h-full">
|
|
<div
|
|
:class="collapsed ? 'min-h-[80vh]' : 'min-h-[60vh]'"
|
|
class="transition-[width] duration-500 ease-in-out 2xl:w-310 xl:w-255 lg:w-241 md:w-177 sm:w-145 w-11/12">
|
|
<slot name="content"/>
|
|
</div>
|
|
</div>
|
|
<slot name="footer"/>
|
|
</UApp>
|
|
</div>
|
|
</template>
|