200 lines
5.9 KiB
Vue
200 lines
5.9 KiB
Vue
<template>
|
|
<div
|
|
class="app-component"
|
|
@mousemove="setTimeout"
|
|
@mousedown="setTimeout"
|
|
@mouseup="setTimeout"
|
|
@focus="setTimeout"
|
|
@keyup="setTimeout"
|
|
@keydown="setTimeout"
|
|
@touchstart="setTimeout"
|
|
>
|
|
<template v-if="!loading">
|
|
<AppHeader />
|
|
<div class="container-fluid overflow-y-scroll">
|
|
<NuxtPage :page-key="(route: RouteLocation) => route.fullPath" />
|
|
</div>
|
|
<NavigationMenu v-if="showNavigation" />
|
|
<AppFooter />
|
|
<ToastContainer />
|
|
<!-- <RangesShow :data-json="data" @selected="itemClicked($event.item)" />
|
|
<ProductModal
|
|
v-if="selectedItem"
|
|
:id="modalId"
|
|
:item="selectedItem"
|
|
:settings="data.modalSettings"
|
|
@saved="SaveContact"
|
|
/> -->
|
|
<AdministrativeModal :id="adminModalId" :contacts="contacts" />
|
|
</template>
|
|
<template v-else>
|
|
CHARGEMENT
|
|
</template>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import Modal from "bootstrap/js/dist/modal";
|
|
import KonamiCode from "konami-code-js";
|
|
import Swal from "sweetalert2";
|
|
import { defineComponent } from "vue";
|
|
import type { RouteLocationNormalizedLoaded } from "vue-router";
|
|
import data from "data/test.json";
|
|
import { useAppStore } from "~/stores/useAppStore";
|
|
|
|
export default defineComponent({
|
|
name: "IndexPage",
|
|
data(): {
|
|
timeout: NodeJS.Timeout|undefined;
|
|
loading: boolean;
|
|
route: RouteLocationNormalizedLoaded;
|
|
modalId: string;
|
|
adminModalId: string;
|
|
modal: Modal;
|
|
adminModal: Modal;
|
|
data: typeof data;
|
|
selectedItem: Item | null;
|
|
konami: KonamiCode;
|
|
contacts: Array<Contact>;
|
|
} {
|
|
return {
|
|
timeout: undefined,
|
|
loading: true,
|
|
route: useRoute(),
|
|
modalId: "productModal",
|
|
adminModalId: "adminModal",
|
|
data,
|
|
selectedItem: null,
|
|
modal: {} as Modal,
|
|
adminModal: {} as Modal,
|
|
konami: {} as KonamiCode,
|
|
contacts: []
|
|
};
|
|
},
|
|
computed: {
|
|
showNavigation(): boolean {
|
|
return ["ranges-slug"].find(routeName => routeName === this.route.name) !== undefined;
|
|
}
|
|
},
|
|
watch: {
|
|
selectedItem() {
|
|
this.$nextTick(() => {
|
|
if (!Object.entries(this.modal).length) {
|
|
const el = document.getElementById(this.modalId);
|
|
if (!el) {
|
|
throw new Error(`Missing element ${this.modalId}`);
|
|
}
|
|
this.modal = new Modal(el);
|
|
}
|
|
this.modal.show();
|
|
});
|
|
},
|
|
$route() {
|
|
this.setTimeout();
|
|
},
|
|
},
|
|
mounted() {
|
|
// * Make sure array does not start using 0 index
|
|
const items: typeof data.items = [];
|
|
this.data.items.forEach((item, itemIndex) => {
|
|
items[itemIndex + 1] = item;
|
|
});
|
|
this.data.items = items;
|
|
// * Init contacts (Fetch form local storage or new)
|
|
const serializedContacts = window.localStorage.getItem("contacts");
|
|
this.contacts = !serializedContacts ? new Array<Contact>() : JSON.parse(serializedContacts);
|
|
// * Hidden action and modal show
|
|
this.konami = new KonamiCode(() => {
|
|
this.$nextTick(() => {
|
|
if (!Object.entries(this.modal).length) {
|
|
const el = document.getElementById(this.adminModalId);
|
|
if (!el) {
|
|
throw new Error(`Missing element ${this.adminModalId}`);
|
|
}
|
|
this.adminModal = new Modal(el);
|
|
}
|
|
this.adminModal.show();
|
|
});
|
|
});
|
|
|
|
// * INIT STATES
|
|
window.ipcRendererObject.getJsonData().then((dataJson) => {
|
|
useAppStore().setupAppData(dataJson);
|
|
this.loading = false;
|
|
this.setTimeout();
|
|
dataJson.fonts.forEach(font => this.injectFontFace(font.font_name, font.font));
|
|
});
|
|
},
|
|
beforeUnmount() {
|
|
clearTimeout(this.timeout);
|
|
},
|
|
methods: {
|
|
injectFontFace(fontName: string, fontPath: string|null) {
|
|
const newStyle = document.createElement("style");
|
|
if(fontPath) {
|
|
newStyle.appendChild(document.createTextNode(`@font-face { font-family: '${fontName}'; src: url('/data/${fontPath}');}`));
|
|
newStyle.appendChild(document.createTextNode(`.f-${fontName} { font-family: '${fontName}' !important; }`));
|
|
} else {
|
|
newStyle.appendChild(document.createTextNode(`.f-${fontName} { font-family: ${fontName} !important; }`));
|
|
}
|
|
document.head.appendChild(newStyle);
|
|
},
|
|
/** Prolong le timer pour revenir au home screen */
|
|
setTimeout(): void {
|
|
if(this.timeout) {
|
|
clearTimeout(this.timeout);
|
|
}
|
|
this.timeout = setTimeout(() => {
|
|
useAppStore().setActiveRange(null);
|
|
useAppStore().setActiveBrand(null);
|
|
navigateTo(useLocaleRoute()({"name": "index"}));
|
|
}, useAppStore().getSettings().home_timeout * 1000);
|
|
},
|
|
itemClicked(item: Item): void {
|
|
this.selectedItem = item;
|
|
},
|
|
isMultOf(numerator: number, divider: number): boolean {
|
|
return numerator % divider === 0;
|
|
},
|
|
SaveContact(contact: Contact) {
|
|
this.contacts.push(contact);
|
|
window.localStorage.setItem("contacts", JSON.stringify(this.contacts));
|
|
this.modal.hide();
|
|
this.$nextTick(() => this.ShowConfirmedInscription());
|
|
},
|
|
ShowConfirmedInscription(): void {
|
|
Swal.fire({
|
|
// timer: 10000,
|
|
timerProgressBar: true,
|
|
// position: "top",
|
|
title: "Votre inscription est validée",
|
|
text: "Nous avons bien enregistré votre inscription",
|
|
color: getComputedStyle(document.body).getPropertyValue("--bs-body-color"),
|
|
icon: "success",
|
|
confirmButtonText: "OK",
|
|
reverseButtons: true,
|
|
// * Bootstrap Styling
|
|
customClass: {
|
|
confirmButton: "btn btn-primary mx-1",
|
|
cancelButton: "btn btn-danger mx-1",
|
|
},
|
|
buttonsStyling: false,
|
|
background: getComputedStyle(document.body).getPropertyValue("--bs-body-bg")
|
|
});
|
|
},
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.page-enter-active,
|
|
.page-leave-active {
|
|
transition: all 0.2s;
|
|
}
|
|
.page-enter-from,
|
|
.page-leave-to {
|
|
opacity: 0;
|
|
filter: blur(1rem);
|
|
}
|
|
</style>
|