translations
This commit is contained in:
@ -30,13 +30,21 @@ import { useMyFetch } from "#imports";
|
||||
// }));
|
||||
// }
|
||||
|
||||
function buildTreeRecursive(data: (FrontMenu | UIFrontMenu)[], parentId: number): UIFrontMenu[] {
|
||||
const children = data.filter((item): item is UIFrontMenu => item.id_parent === parentId && !item.is_default);
|
||||
function buildTreeRecursive(
|
||||
data: (FrontMenu | UIFrontMenu)[],
|
||||
parentId: number
|
||||
): UIFrontMenu[] {
|
||||
const children = data.filter(
|
||||
(item): item is UIFrontMenu =>
|
||||
item.id_parent === parentId && !item.is_default
|
||||
);
|
||||
|
||||
return children.map((item) => ({ ...item, children: buildTreeRecursive(data, item.id) }));
|
||||
return children.map((item) => ({
|
||||
...item,
|
||||
children: buildTreeRecursive(data, item.id),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
export const useMenuStore = defineStore("menuStore", () => {
|
||||
const pb = usePB();
|
||||
const store = useStore();
|
||||
@ -72,15 +80,20 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
// sort: "position_id",
|
||||
// })) as MenuListResponse;
|
||||
|
||||
const { data } = await useMyFetch<GenericResponse<FrontMenu[]>>(`/api/public/front/menu`, {
|
||||
onErrorOccured: (err, status) => {
|
||||
console.log(err, status);
|
||||
},
|
||||
// onSuccess(data) {
|
||||
// console.log(data.data, "data");
|
||||
const { data } = await useMyFetch<GenericResponse<FrontMenu[]>>(
|
||||
`/api/public/front/menu`,
|
||||
{
|
||||
onErrorOccured: (err, status) => {
|
||||
console.log(err, status);
|
||||
},
|
||||
// onSuccess(data) {
|
||||
// console.log(data.data, "data");
|
||||
|
||||
// },
|
||||
})
|
||||
// },
|
||||
}
|
||||
);
|
||||
|
||||
menuItems.value = data;
|
||||
|
||||
const root = data.find((item) => item.is_root) as UIFrontMenu;
|
||||
defaultMenu.value = data.find((item) => item.is_default);
|
||||
@ -92,7 +105,6 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
menu.value = [];
|
||||
}
|
||||
|
||||
|
||||
// const root = menuItems.value.items.find((item) => item.is_root);
|
||||
// defaultMenu.value = menuItems.value.items.find((item) => item.is_default);
|
||||
|
||||
@ -108,18 +120,6 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadFooter = async () => {
|
||||
try {
|
||||
footerItems.value = (await pb
|
||||
.collection("footer_view")
|
||||
.getList<PBFooterItem>(1, 50, {
|
||||
filter: `id_lang="${$i18n.locale.value}"`,
|
||||
})) as FooterListResponse;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
const getCountryList = async () => {
|
||||
try {
|
||||
const { data } = await useMyFetch<GenericResponse<Country[]>>(
|
||||
@ -136,14 +136,12 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
// }
|
||||
|
||||
// const data = await res.json();
|
||||
countryList.value = data
|
||||
if (countryList.value)
|
||||
selectedPhoneCountry.value = countryList.value[0]
|
||||
|
||||
countryList.value = data;
|
||||
if (countryList.value) selectedPhoneCountry.value = countryList.value[0];
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getCurrencies = async () => {
|
||||
try {
|
||||
@ -153,7 +151,9 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
|
||||
onErrorOccured: (_, status) => {
|
||||
throw new Error(`HTTP error: ${status}`);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@ -162,14 +162,13 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
// }
|
||||
|
||||
// const data = await res.json();
|
||||
currencies.value = data.items
|
||||
currencies.value = data.items;
|
||||
|
||||
// console.log(data.items, "data");
|
||||
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const navigateToItem = (item?: UIFrontMenu) => {
|
||||
if (item) {
|
||||
@ -178,12 +177,11 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
name: `id-slug___${$i18n.locale.value}`,
|
||||
});
|
||||
openDropDown.value = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
router.push({
|
||||
params: {
|
||||
slug: defaultMenu.value.link_rewrite,
|
||||
id: defaultMenu.value.id_page,
|
||||
slug: defaultMenu.value.front_menu_lang[0].link_rewrite,
|
||||
id: defaultMenu.value.id,
|
||||
},
|
||||
name: `id-slug___${$i18n.locale.value}`,
|
||||
});
|
||||
@ -191,7 +189,9 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
};
|
||||
|
||||
function navigateToShop() {
|
||||
navigateToItem(menuItems.value?.items.find(item => item.page_name === 'shop'))
|
||||
console.log(menuItems.value);
|
||||
|
||||
navigateToItem(menuItems.value?.find((item) => item.id === 5));
|
||||
}
|
||||
|
||||
// function redirectToPage(link_rewrite: string) {
|
||||
@ -218,9 +218,11 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
let img = "";
|
||||
for (const s in store.components) {
|
||||
store.components[s].section_img.map((item) => {
|
||||
img = `${req?.headers.get("x-forwarded-proto") || url.protocol}://${req?.headers.get("x-forwarded-host") || req?.headers.get("host")
|
||||
}/api/files/${store.components[s].image_collection}/${store.components[s].section_id
|
||||
}/${item}?thumb=400x0`;
|
||||
img = `${req?.headers.get("x-forwarded-proto") || url.protocol}://${
|
||||
req?.headers.get("x-forwarded-host") || req?.headers.get("host")
|
||||
}/api/files/${store.components[s].image_collection}/${
|
||||
store.components[s].section_id
|
||||
}/${item}?thumb=400x0`;
|
||||
});
|
||||
if (img.length > 0) return img;
|
||||
}
|
||||
@ -273,12 +275,11 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
|
||||
watch($i18n.locale, async () => {
|
||||
await loadMenu();
|
||||
await loadFooter();
|
||||
});
|
||||
|
||||
watch(selectedCurrency, () => {
|
||||
store.getCalculator()
|
||||
})
|
||||
store.getCalculator();
|
||||
});
|
||||
return {
|
||||
menu,
|
||||
menuItems,
|
||||
@ -294,10 +295,9 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
headMeta,
|
||||
navigateToShop,
|
||||
loadMenu,
|
||||
loadFooter,
|
||||
getCountryList,
|
||||
navigateToItem,
|
||||
// redirectToPage,
|
||||
getCurrencies
|
||||
getCurrencies,
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user