first commit
This commit is contained in:
20
app/plugins/01.fetch_setting.ts
Normal file
20
app/plugins/01.fetch_setting.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type {Setting} from "~~/types/setting";
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
|
||||
|
||||
const { useSettingStore } = await import('@/stores/setting')
|
||||
const settingStore = useSettingStore()
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const apiUrl = config.public.BASE_API_URL;
|
||||
|
||||
try {
|
||||
const data = await $fetch<Setting>(`${apiUrl}/api/v1/setting`)
|
||||
if (data) {
|
||||
settingStore.setSettings(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch settings:', error)
|
||||
}
|
||||
})
|
||||
20
app/plugins/02.fetch_banner.ts
Normal file
20
app/plugins/02.fetch_banner.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { Banner } from "~~/types/banner";
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
|
||||
|
||||
const { useBannerStore } = await import('@/stores/banner')
|
||||
const bannerStore = useBannerStore()
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const apiUrl = config.public.BASE_API_URL;
|
||||
|
||||
try {
|
||||
const data = await $fetch<Banner[]>(`${apiUrl}/api/v1/hero`)
|
||||
if (data) {
|
||||
bannerStore.setBanner(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch banners:', error)
|
||||
}
|
||||
})
|
||||
20
app/plugins/03.fetch_product_tree.ts
Normal file
20
app/plugins/03.fetch_product_tree.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type {ProductTree} from "~~/types/banner";
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
|
||||
|
||||
const { useProductTreeStore } = await import('@/stores/productTree')
|
||||
const productTreeStore = useProductTreeStore()
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const apiUrl = config.public.BASE_API_URL;
|
||||
|
||||
try {
|
||||
const data = await $fetch<ProductTree[]>(`${apiUrl}/api/v1/products-tree/`)
|
||||
if (data) {
|
||||
productTreeStore.setProductTree(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch product tree:', error)
|
||||
}
|
||||
})
|
||||
15
app/plugins/04.cart-persist.client.ts
Normal file
15
app/plugins/04.cart-persist.client.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useCartStore } from '~/stores/cart';
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const cartStore = useCartStore();
|
||||
const storageKey = cartStore.getStorageKey();
|
||||
|
||||
cartStore.hydrateFromStorage(localStorage.getItem(storageKey));
|
||||
|
||||
cartStore.$subscribe(
|
||||
() => {
|
||||
localStorage.setItem(storageKey, cartStore.toStoragePayload());
|
||||
},
|
||||
{ detached: true }
|
||||
);
|
||||
});
|
||||
9
app/plugins/body-class.client.ts
Normal file
9
app/plugins/body-class.client.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Canvas theme requires body.stretched for full-width layout.
|
||||
* Ensures body has the class on client (useHead bodyAttrs may not apply in all cases).
|
||||
*/
|
||||
export default defineNuxtPlugin(() => {
|
||||
if (import.meta.client && document?.body) {
|
||||
document.body.classList.add('stretched')
|
||||
}
|
||||
})
|
||||
5
app/plugins/sweetalert2.client.ts
Normal file
5
app/plugins/sweetalert2.client.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import Swal from 'sweetalert2'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.provide('swal', Swal)
|
||||
})
|
||||
Reference in New Issue
Block a user