web / layouts /default.vue
hanbinsite's picture
feat: implement all web pages with player, search, favorites, auth, useApi composable
dfa6264
Raw History Blame Contribute Delete
2.66 kB
<template>
<div class="min-h-screen flex flex-col bg-gray-950 text-white">
<header class="sticky top-0 z-50 bg-gray-900/95 backdrop-blur border-b border-gray-800">
<div class="max-w-7xl mx-auto px-4 h-14 flex items-center justify-between">
<div class="flex items-center gap-6">
<NuxtLink to="/" class="text-lg font-bold text-emerald-400">BinV</NuxtLink>
<nav class="hidden sm:flex gap-1">
<NuxtLink
v-for="cat in topCategories"
:key="cat.id"
:to="`/category/${cat.id}`"
class="px-3 py-1.5 rounded-md text-sm text-gray-400 hover:text-white hover:bg-gray-800 transition"
>
{{ cat.name }}
</NuxtLink>
</nav>
</div>
<div class="flex items-center gap-3">
<NuxtLink to="/search" class="text-gray-400 hover:text-white">
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>
</NuxtLink>
<NuxtLink v-if="!userStore.isLoggedIn" to="/login" class="text-sm text-gray-400 hover:text-white">登录</NuxtLink>
<NDropdown v-else :options="userMenuOptions" @select="onUserMenuSelect">
<NButton quaternary size="small" class="text-sm text-gray-300">{{ userStore.userInfo?.nickname || '用户' }}</NButton>
</NDropdown>
</div>
</div>
</header>
<main class="flex-1">
<slot />
</main>
<footer class="py-6 text-center text-gray-600 text-sm border-t border-gray-800">
&copy; {{ new Date().getFullYear() }} BinV
</footer>
</div>
</template>
<script setup lang="ts">
import type { CategoryUserNode } from '~/types/category'
const userStore = useUserStore()
const { get } = useApi()
const topCategories = ref<CategoryUserNode[]>([])
const { data: catData } = await useAsyncData('categories', () => get<CategoryUserNode[]>('/user/category'))
topCategories.value = catData.value ?? []
const userMenuOptions = [
{ label: '我的收藏', key: 'favorite' },
{ label: '播放历史', key: 'history' },
{ label: '退出登录', key: 'logout' },
]
function onUserMenuSelect(key: string) {
if (key === 'logout') {
userStore.logout()
navigateTo('/')
} else if (key === 'favorite') {
navigateTo('/favorite')
} else if (key === 'history') {
navigateTo('/history')
}
}
onMounted(() => {
if (userStore.isLoggedIn && !userStore.userInfo) {
userStore.fetchProfile()
}
})
</script>