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

129
stores/mapStore.ts Normal file
View File

@ -0,0 +1,129 @@
import type { CountryList, PartnersList } from "~/types";
export const useMapStore = defineStore("mapStore", () => {
const partnersList = ref<PartnersList[]>([
{
country_iso: "cz",
total: 9,
country_name: "Czech Republic",
},
{
country_iso: "de",
total: 1,
country_name: "Germany",
},
{
country_iso: "ie",
total: 1,
country_name: "Ireland",
},
{
country_iso: "nl",
total: 1,
country_name: "Netherlands",
},
{
country_iso: "pl",
total: 61,
country_name: "Poland",
},
]);
const customersList = ref([
"be",
"cz",
"de",
"dk",
"gb",
"ie",
"it",
"nl",
"no",
"pl",
"sk",
"at",
"lt",
"is",
"se"
]);
const countryList = ref<CountryList[]>()
const countries = ref<CountryList[]>()
// async function getPartnersList() {
// try {
// const res = await fetch(
// `http://127.0.0.1:4000/api/public/partners/count`,
// {
// headers: {
// "Content-Type": "application/json",
// },
// }
// );
// if (!res.ok) {
// throw new Error(`HTTP error: ${res.status}`);
// }
// const data = await res.json();
// partnersList.value = data.data
// } catch (error) {
// console.error("getList error:", error);
// }
// }
// async function getCustomerList() {
// try {
// const res = await fetch(
// `http://127.0.0.1:4000/api/public/customer/countries`,
// {
// headers: {
// "Content-Type": "application/json",
// },
// }
// );
// if (!res.ok) {
// throw new Error(`HTTP error: ${res.status}`);
// }
// const data = await res.json();
// customersList.value = data.data
// } catch (error) {
// console.error("getList error:", error);
// }
// }
async function getCountries() {
try {
const res = await fetch(
`http://127.0.0.1:4000/api/public/countries`,
{
headers: {
"Content-Type": "application/json",
},
}
);
if (!res.ok) {
throw new Error(`HTTP error: ${res.status}`);
}
const data = await res.json();
countries.value = data.ata
} catch (error) {
console.error("getList error:", error);
}
}
return {
partnersList,
customersList,
// countryList,
countries,
// getPartnersList,
// getCustomerList,
getCountries
};
});

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,
};