Skip to content

Commit

Permalink
Merge pull request #435 from sugarforever/feat/topHeader
Browse files Browse the repository at this point in the history
顶部导航栏支持响应式
  • Loading branch information
satrong authored May 9, 2024
2 parents e2a05f4 + 06e607a commit 4f82328
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 21 deletions.
27 changes: 27 additions & 0 deletions components/MobileMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script lang="ts" setup>
const menus = useMenus()
</script>

<template>
<div class="w-full box-border">
<ul class="p-4">
<li v-for="menu in menus" :key="menu.to" class="my-1">
<RouterLink :to="menu.to"
active-class="!text-primary-400"
class="block px-2 py-1 text-gray-500 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100">
<Icon :name="menu.icon" />
<span class="ml-2">{{ menu.label }}</span>
</RouterLink>
</li>
</ul>
<div class="flex items-center p-4 border-t border-gray-200 dark:border-gray-700">
<div class="mr-4">
<ColorMode />
</div>
<ULink to="https://github.com/sugarforever/chat-ollama"
target="_blank"
class="i-mdi-github text-2xl ml-2 mr-4"></ULink>
<Auth class="ml-auto" />
</div>
</div>
</template>
12 changes: 12 additions & 0 deletions composables/useMenus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function useMenus() {
const { t } = useI18n()

return computed(() => [
{ label: t('menu.home'), icon: 'i-heroicons-home', to: '/' },
{ label: t('menu.models'), icon: 'i-heroicons-rectangle-stack', to: '/models' },
{ label: t('menu.instructions'), icon: 'i-iconoir-terminal', to: '/instructions' },
{ label: t('menu.knowledgeBases'), icon: 'i-heroicons-book-open', to: '/knowledgebases' },
{ label: t('menu.chat'), icon: 'i-iconoir-chat-lines', to: '/chat' },
{ label: t('menu.settings'), icon: 'i-heroicons-cog-6-tooth', to: '/settings' }
])
}
46 changes: 25 additions & 21 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
<script setup>
const { t } = useI18n()
<script lang="ts" setup>
const route = useRoute()
const links = useMenus()
const links = computed(() => {
return [
[
{ label: t('menu.home'), icon: 'i-heroicons-home', to: '/' },
{ label: t('menu.models'), icon: 'i-heroicons-rectangle-stack', to: '/models' },
{ label: t('menu.instructions'), icon: 'i-iconoir-terminal', to: '/instructions' },
{ label: t('menu.knowledgeBases'), icon: 'i-heroicons-book-open', to: '/knowledgebases' },
{ label: t('menu.chat'), icon: 'i-iconoir-chat-lines', to: '/chat' },
{ label: t('menu.settings'), icon: 'i-heroicons-cog-6-tooth', to: '/settings' }
],
]
const open = ref(false)
watch(() => route.path, () => {
open.value = false
})
</script>

<template>
<div class="border-b border-gray-200 dark:border-gray-700">
<div class="flex items-center justify-between max-w-6xl mx-auto px-4">
<div class="border-b border-gray-200 dark:border-gray-700" style="--top-height: 48px;">
<div class="flex items-center justify-between max-w-6xl mx-auto px-4 h-[var(--top-height)]">
<h1 class="flex flex-row items-center mr-2">
<TheLogo class="w-[32px] h-[32px] mr-2" />
<span class="text-primary font-semibold text-lg">{{ $config.public.appName }}</span>
</h1>
<div>
<ClientOnly>
<UHorizontalNavigation :links="links" />
</ClientOnly>
<div class="hidden md:block">
<UHorizontalNavigation :links="[links]">
<template #default="{ link }">
<span class="group-hover:text-primary relative hidden lg:inline">{{ link.label }}</span>
</template>
</UHorizontalNavigation>
</div>
<div class="flex items-center">
<div class="hidden md:flex items-center">
<div class="mx-2">
<ColorMode />
</div>
Expand All @@ -35,9 +32,16 @@ const links = computed(() => {
class="i-mdi-github text-2xl ml-2 mr-4"></ULink>
<Auth />
</div>
<div class="md:hidden">
<UPopover v-model:open="open" overlay :ui="{ width: 'w-[100vw] !translate-y-[var(--top-height)]', overlay: { background: '!bg-transparent' } }">
<UButton icon="i-material-symbols-menu-rounded" color="gray" />
<template #panel>
<MobileMenu />
</template>
</UPopover>
</div>
</div>
</div>

<div id="main" class="p-4 box-border overflow-auto" style="height: calc(100% - 61px)">
<slot />
</div>
Expand Down

0 comments on commit 4f82328

Please sign in to comment.