fix(spa): handle empty category and products in carousel block
Render the products carousel block gracefully when category_id is missing or when the selected category has no products, instead of throwing Vue Router's "Missing required param 'category_id'" error.
This commit is contained in:
@@ -2,10 +2,23 @@
|
|||||||
<BaseBlock
|
<BaseBlock
|
||||||
:title="block.title"
|
:title="block.title"
|
||||||
:description="block.description"
|
:description="block.description"
|
||||||
:moreLink="{name: 'product.categories.show', params: { category_id: block.data.category_id }}"
|
:moreLink="hasCategory ? {name: 'product.categories.show', params: { category_id: block.data.category_id }} : null"
|
||||||
:moreText="block.data.all_text"
|
:moreText="block.data.all_text"
|
||||||
>
|
>
|
||||||
|
<div v-if="!hasCategory" role="alert" class="alert alert-warning alert-soft">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 shrink-0 stroke-current" fill="none" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||||
|
</svg>
|
||||||
|
<span>Для блока не выбрана категория.</span>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="!hasProducts" role="alert" class="alert alert-soft">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 shrink-0 stroke-current" fill="none" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<span>В этой категории пока нет товаров.</span>
|
||||||
|
</div>
|
||||||
<Swiper
|
<Swiper
|
||||||
|
v-else
|
||||||
class="select-none block-products-carousel"
|
class="select-none block-products-carousel"
|
||||||
:slides-per-view="block.data?.carousel?.slides_per_view || 2.5"
|
:slides-per-view="block.data?.carousel?.slides_per_view || 2.5"
|
||||||
:space-between="block.data?.carousel?.space_between || 20"
|
:space-between="block.data?.carousel?.space_between || 20"
|
||||||
@@ -36,6 +49,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import {computed} from "vue";
|
||||||
import {useYaMetrikaStore} from "@/stores/yaMetrikaStore.js";
|
import {useYaMetrikaStore} from "@/stores/yaMetrikaStore.js";
|
||||||
import {Swiper, SwiperSlide} from "swiper/vue";
|
import {Swiper, SwiperSlide} from "swiper/vue";
|
||||||
import {useHapticScroll} from "@/composables/useHapticScroll.js";
|
import {useHapticScroll} from "@/composables/useHapticScroll.js";
|
||||||
@@ -52,6 +66,9 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const hasCategory = computed(() => Boolean(props.block.data?.category_id));
|
||||||
|
const hasProducts = computed(() => (props.block.data?.products?.data?.length ?? 0) > 0);
|
||||||
|
|
||||||
const freeModeSettings = {
|
const freeModeSettings = {
|
||||||
enabled: props.block.data?.carousel?.freemode?.enabled || false,
|
enabled: props.block.data?.carousel?.freemode?.enabled || false,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user