diff --git a/frontend/spa/src/stores/SearchStore.js b/frontend/spa/src/stores/SearchStore.js index 98886ea..9cde9e5 100644 --- a/frontend/spa/src/stores/SearchStore.js +++ b/frontend/spa/src/stores/SearchStore.js @@ -17,6 +17,13 @@ export const useSearchStore = defineStore('search', { isLoadingMore: false, isSearchPerformed: false, hasMore: false, + + // Placeholder товары для пустого состояния поиска + placeholderProducts: { + data: [], + total: 0, + }, + isLoadingPlaceholder: false, }), actions: { @@ -91,6 +98,35 @@ export const useSearchStore = defineStore('search', { this.isSearchPerformed = true; } }, + + async loadSearchPlaceholder() { + // Если данные уже есть в store, возвращаем их + if (this.placeholderProducts.data.length > 0) { + return { + data: this.placeholderProducts.data, + meta: { + total: this.placeholderProducts.total, + }, + }; + } + + try { + this.isLoadingPlaceholder = true; + // Иначе загружаем с сервера + const response = await ftch('productsSearchPlaceholder'); + this.placeholderProducts.data = response.data.slice(0, 3); + this.placeholderProducts.total = response?.meta?.total || 0; + + return { + data: this.placeholderProducts.data, + meta: { + total: this.placeholderProducts.total, + }, + }; + } finally { + this.isLoadingPlaceholder = false; + } + }, }, }); diff --git a/frontend/spa/src/views/Search.vue b/frontend/spa/src/views/Search.vue index aa7102c..8d8492b 100644 --- a/frontend/spa/src/views/Search.vue +++ b/frontend/spa/src/views/Search.vue @@ -79,25 +79,38 @@ class="flex flex-col items-center justify-center text-center py-16 px-10" >
-