mpa/langs/currency

This commit is contained in:
2025-06-04 15:59:23 +02:00
parent c9348dc092
commit a7c4ff51ca
11 changed files with 414 additions and 115 deletions

View File

@ -1,5 +1,7 @@
import { usePB } from "~/composables/usePB";
import type {
CountryList,
Currencies,
FooterListResponse,
MenuListResponse,
PBFooterItem,
@ -29,13 +31,19 @@ export const useMenuStore = defineStore("menuStore", () => {
const store = useStore();
const { $i18n } = useNuxtApp();
const router = useRouter();
const route = useRoute();
const openMenu = ref(false);
const openDropDown = ref(false);
const defaultMenu = ref();
const menu = ref<UIMenuItem[]>([]);
const menuItems = ref<MenuListResponse>();
const footerItems = ref<FooterListResponse>();
const countryList = ref<CountryList[]>();
const currencies = ref<Currencies[]>();
const loadMenu = async () => {
try {
@ -73,6 +81,52 @@ export const useMenuStore = defineStore("menuStore", () => {
}
};
const getCountryList = async () => {
try {
const res = await fetch(
`http://127.0.0.1:4000/api/public/country/list`,
{
headers: {
"Content-Type": "application/json",
},
}
);
if (!res.ok) {
throw new Error(`HTTP error: ${res.status}`);
}
const data = await res.json();
countryList.value = data.data
} catch (error) {
console.error("getList error:", error);
}
}
const getCurrencies = async () => {
try {
const res = await fetch(
`http://127.0.0.1:4000/api/public/currencies`,
{
headers: {
"Content-Type": "application/json",
},
}
);
if (!res.ok) {
throw new Error(`HTTP error: ${res.status}`);
}
const data = await res.json();
currencies.value = data.data.items
} catch (error) {
console.error("getList error:", error);
}
}
const navigateToItem = (item?: UIMenuItem) => {
if (item) {
router.push({
@ -91,11 +145,6 @@ export const useMenuStore = defineStore("menuStore", () => {
}
};
watch($i18n.locale, async () => {
await loadMenu();
await loadFooter();
});
const getFirstImage = () => {
const req = useRequestEvent();
const url = useRequestURL();
@ -111,7 +160,6 @@ export const useMenuStore = defineStore("menuStore", () => {
return "";
};
const route = useRoute();
const headMeta = computed(() => {
const item = menuItems.value?.items.find(
(item) => item.id_page === route.params.id
@ -174,16 +222,24 @@ export const useMenuStore = defineStore("menuStore", () => {
});
}
watch($i18n.locale, async () => {
await loadMenu();
await loadFooter();
});
return {
menu,
menuItems,
footerItems,
openMenu,
openDropDown,
countryList,
currencies,
loadMenu,
loadFooter,
getCountryList,
navigateToItem,
redirectToPage,
getCurrencies,
defaultMenu,
headMeta,
};