feat: add preloader for product page
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
<template>
|
||||
<div style="z-index: 99999" class="fixed top-0 left-0 w-full h-full bg-base-100">
|
||||
<div class="flex flex-col items-center justify-center h-full">
|
||||
<span class="loading loading-infinity loading-xl"></span>
|
||||
<h1>Загрузка приложения...</h1>
|
||||
</div>
|
||||
</div>
|
||||
<LoadingFullScreen text="Загрузка приложения..."/>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
error: Error,
|
||||
});
|
||||
import LoadingFullScreen from "@/components/LoadingFullScreen.vue";
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
17
spa/src/components/LoadingFullScreen.vue
Normal file
17
spa/src/components/LoadingFullScreen.vue
Normal file
@@ -0,0 +1,17 @@
|
||||
<template>
|
||||
<div style="z-index: 99999" class="fixed top-0 left-0 w-full h-full bg-base-100">
|
||||
<div class="flex flex-col items-center justify-center h-full">
|
||||
<span class="loading loading-infinity loading-xl"></span>
|
||||
<h1>{{ text }}</h1>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
text: {
|
||||
type: String,
|
||||
default: 'Получение данных...',
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -114,6 +114,7 @@
|
||||
@close="closeFullScreen"
|
||||
/>
|
||||
</div>
|
||||
<LoadingFullScreen v-if="isLoading"/>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -124,6 +125,8 @@ import {useCartStore} from "../stores/CartStore.js";
|
||||
import Quantity from "../components/Quantity.vue";
|
||||
import {SUPPORTED_OPTION_TYPES} from "@/constants/options.js";
|
||||
import {apiFetch} from "@/utils/ftch.js";
|
||||
import FullScreenImageViewer from "@/components/FullScreenImageViewer.vue";
|
||||
import LoadingFullScreen from "@/components/LoadingFullScreen.vue";
|
||||
|
||||
const route = useRoute();
|
||||
const productId = computed(() => route.params.id);
|
||||
@@ -132,14 +135,11 @@ const cart = useCartStore();
|
||||
const quantity = ref(1);
|
||||
const error = ref('');
|
||||
const router = useRouter();
|
||||
|
||||
const isInCart = ref(false);
|
||||
const btnText = computed(() => isInCart.value ? 'В корзине' : 'Купить');
|
||||
const isFullScreen = ref(false);
|
||||
const initialFullScreenIndex = ref(0);
|
||||
|
||||
import FullScreenImageViewer from "@/components/FullScreenImageViewer.vue";
|
||||
|
||||
const isLoading = ref(false);
|
||||
|
||||
const canAddToCart = computed(() => {
|
||||
if (!product.value || product.value.options === undefined || product.value.options?.length === 0) {
|
||||
@@ -210,8 +210,16 @@ onUnmounted(() => {
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
const {data} = await apiFetch(`/index.php?route=extension/tgshop/handle&api_action=product_show&id=${productId.value}`);
|
||||
product.value = data;
|
||||
isLoading.value = true;
|
||||
try {
|
||||
const {data} = await apiFetch(`/index.php?route=extension/tgshop/handle&api_action=product_show&id=${productId.value}`);
|
||||
product.value = data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener('popstate', onPopState);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user