feat: add breadcrumbs

This commit is contained in:
Константин Уколов 2024-08-06 10:47:36 +03:00
parent d9b694e76a
commit 1fd9fd292d
7 changed files with 84 additions and 14 deletions

View File

@ -0,0 +1 @@
export { Breadcrumbs } from './ui'

View File

@ -0,0 +1,41 @@
<script setup lang="ts">
import { useCRMGetBreadcrumbs, useCRMGetCatalog } from '~/src/shared/api/crm/crm'
const route = useRoute()
const { data: catalogData } = useCRMGetCatalog()
const { data: breadcrumbsData } = useCRMGetBreadcrumbs(route.params.id as string)
const links = computed(() => {
const breadcrumbs = [{
label: 'Каталог',
to: '/catalog',
}]
if (!catalogData.value?.data.categories?.length) {
return breadcrumbs
}
if (route.name === 'catalog-positions-id') {
const category = catalogData.value.data.categories[0].children?.find(category => category.id === route.params.id)
breadcrumbs.push({
label: category?.name || 'Категория',
to: `/catalog/${category?.uri}`,
})
}
if (route.name === 'products-id') {
breadcrumbs.push({
label: breadcrumbsData.value?.data.categories?.[0].name || 'Продукт',
to: route.path,
})
}
return breadcrumbs
})
</script>
<template>
<UBreadcrumb :links />
</template>

View File

@ -0,0 +1 @@
export { Breadcrumbs } from './Breadcrumbs.vue'

View File

@ -5,6 +5,7 @@ import { Sidebar } from '~/src/widgets/sidebar'
import { StandardLayout } from '~/src/shared/ui' import { StandardLayout } from '~/src/shared/ui'
import { Header } from '~/src/widgets/header' import { Header } from '~/src/widgets/header'
import { Footer } from '~/src/widgets/footer' import { Footer } from '~/src/widgets/footer'
import Breadcrumbs from '~/src/features/breadcrumbs/ui/Breadcrumbs.vue'
const { data: positions } = useCRMGetPositions('0') const { data: positions } = useCRMGetPositions('0')
</script> </script>
@ -14,6 +15,14 @@ const { data: positions } = useCRMGetPositions('0')
<template #header> <template #header>
<Header /> <Header />
</template> </template>
<div class="flex flex-col gap-8">
<div class="flex flex-col gap-4">
<Breadcrumbs />
<h1 class="text-4xl font-black">
Все товары
</h1>
</div>
<div class="flex gap-12"> <div class="flex gap-12">
<Sidebar /> <Sidebar />
<div class="flex flex-col gap-8 pb-34"> <div class="flex flex-col gap-8 pb-34">
@ -22,6 +31,8 @@ const { data: positions } = useCRMGetPositions('0')
</div> </div>
</div> </div>
</div> </div>
</div>
<template #footer> <template #footer>
<Footer /> <Footer />
</template> </template>

View File

@ -1,14 +1,18 @@
<script setup lang="ts"> <script setup lang="ts">
import { ProductCard } from '~/src/entities/product' import { ProductCard } from '~/src/entities/product'
import { useCRMGetPositions } from '~/src/shared/api/crm/crm' import { useCRMGetCatalog, useCRMGetPositions } from '~/src/shared/api/crm/crm'
import { Sidebar } from '~/src/widgets/sidebar' import { Sidebar } from '~/src/widgets/sidebar'
import { StandardLayout } from '~/src/shared/ui' import { StandardLayout } from '~/src/shared/ui'
import { Header } from '~/src/widgets/header' import { Header } from '~/src/widgets/header'
import { Footer } from '~/src/widgets/footer' import { Footer } from '~/src/widgets/footer'
import Breadcrumbs from '~/src/features/breadcrumbs/ui/Breadcrumbs.vue'
const route = useRoute() const route = useRoute()
const { data: positions } = useCRMGetPositions(route.params.id as string) const { data: positions } = useCRMGetPositions(route.params.id as string)
const { data: catalog } = useCRMGetCatalog()
const pageName = computed(() => catalog.value?.data?.categories?.[0]?.children?.find(category => category.id === route.params.id)?.name)
</script> </script>
<template> <template>
@ -16,6 +20,13 @@ const { data: positions } = useCRMGetPositions(route.params.id as string)
<template #header> <template #header>
<Header /> <Header />
</template> </template>
<div class="flex flex-col gap-8">
<div class="flex flex-col gap-4">
<Breadcrumbs />
<h1 class="text-4xl font-black">
{{ pageName }}
</h1>
</div>
<div class="flex gap-12"> <div class="flex gap-12">
<Sidebar /> <Sidebar />
<div class="flex flex-col gap-8 pb-34"> <div class="flex flex-col gap-8 pb-34">
@ -24,6 +35,7 @@ const { data: positions } = useCRMGetPositions(route.params.id as string)
</div> </div>
</div> </div>
</div> </div>
</div>
<template #footer> <template #footer>
<Footer /> <Footer />
</template> </template>

View File

@ -3,7 +3,7 @@
</script> </script>
<template> <template>
<div class="flex flex-col w-full h-full ma "> <div class="flex flex-col w-full h-full justify-between">
<div class="border-b border-gray-200 px-31 sticky top-0 z-50 bg-white flex-shrink-0"> <div class="border-b border-gray-200 px-31 sticky top-0 z-50 bg-white flex-shrink-0">
<slot name="header" /> <slot name="header" />
</div> </div>

View File

@ -1,5 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
function goToCatalogPage() {
navigateTo({
path: '/catalog',
})
}
</script> </script>
<template> <template>
@ -9,7 +13,7 @@
alt="svg" alt="svg"
> >
<div class="flex gap-5 w-full"> <div class="flex gap-5 w-full">
<UButton size="xl" icon="heroicons-bars-3"> <UButton size="xl" icon="heroicons-bars-3" @click="goToCatalogPage">
Каталог Каталог
</UButton> </UButton>
<UInputMenu placeholder="Поиск по каталогу" size="xl" class="w-full" leading-icon="heroicons-magnifying-glass" /> <UInputMenu placeholder="Поиск по каталогу" size="xl" class="w-full" leading-icon="heroicons-magnifying-glass" />