ldc-showroom/app.vue

166 lines
5.1 KiB
Vue
Raw Permalink Normal View History

2023-10-13 16:18:44 +02:00
<template>
2024-01-12 18:22:50 +01:00
<div
class="app-component"
@mousemove="setTimeout"
@mousedown="setTimeout"
@mouseup="setTimeout"
@focus="setTimeout"
@keyup="setTimeout"
@keydown="setTimeout"
@touchstart="setTimeout"
>
2024-01-11 15:21:59 +01:00
<template v-if="!loading">
<AppHeader :active-brand="activeBrand" :active-range="activeRange" />
<div class="container-fluid overflow-auto p-0">
2024-01-16 15:43:21 +01:00
<NuxtPage :page-key="(route: RouteLocation) => route.fullPath" />
</div>
2024-01-12 11:50:21 +01:00
<NavigationMenu v-if="showNavigation" />
2024-03-13 12:06:52 +01:00
<AppFooter v-if="showFooter" :active-brand="activeBrand" :active-range="activeRange" />
2024-01-11 15:21:59 +01:00
<ToastContainer />
</template>
<template v-else>
2024-01-17 10:36:44 +01:00
{{ t('loading') }}
2024-01-11 15:21:59 +01:00
</template>
2024-02-02 10:34:55 +01:00
<ChickenRun :run-animation="chickenRun" />
2023-10-13 16:18:44 +02:00
</div>
</template>
<script lang="ts">
2024-01-17 10:07:18 +01:00
// import Modal from "bootstrap/js/dist/modal";
2024-02-02 10:34:55 +01:00
import KonamiCode from "konami-code-js";
2024-01-17 10:07:18 +01:00
// import Swal from "sweetalert2";
import { defineComponent } from "vue";
2024-01-12 11:50:21 +01:00
import type { RouteLocationNormalizedLoaded } from "vue-router";
2024-01-17 10:36:44 +01:00
import ToolboxHelper from "./classes/ToolboxHelper";
import { useAppStore } from "~/stores/useAppStore";
2024-01-17 17:44:12 +01:00
// import data from "data/test.json";
export default defineComponent({
name: "IndexPage",
data(): {
timeout: NodeJS.Timeout|undefined;
2024-01-11 15:21:59 +01:00
loading: boolean;
2024-01-12 11:50:21 +01:00
route: RouteLocationNormalizedLoaded;
activeBrand: TypeBrand|null;
activeRange: TypeRange|null;
2024-02-02 10:34:55 +01:00
chickenRun: boolean;
konami: KonamiCode|null;
} {
return {
timeout: undefined,
2024-01-11 15:21:59 +01:00
loading: true,
2024-01-12 11:50:21 +01:00
route: useRoute(),
activeBrand: null,
2024-02-02 10:34:55 +01:00
activeRange: null,
chickenRun: false,
konami: null,
};
},
2024-01-12 11:50:21 +01:00
computed: {
2024-03-13 12:06:52 +01:00
showFooter(): boolean {
return this.route.name?.toString().startsWith("index") !== true;
},
2024-01-12 11:50:21 +01:00
showNavigation(): boolean {
return ["ranges-slug"].find(routeName => this.route.name?.toString().startsWith(routeName)) !== undefined &&
this.brandWithMultipleRanges;
},
brandWithMultipleRanges(): boolean {
if(!this.activeBrand) {
return false;
}
return this.activeBrand.ranges.length > 1;
2024-01-12 11:50:21 +01:00
}
},
watch: {
2024-01-12 18:22:50 +01:00
$route() {
this.setTimeout();
this.activeBrand = useAppStore().activeBrand;
this.activeRange = useAppStore().activeRange;
2024-01-12 18:22:50 +01:00
},
2023-10-17 15:43:44 +02:00
},
beforeMount() {
2024-01-11 15:21:59 +01:00
// * INIT STATES
window.ipcRendererObject.getJsonData().then((dataJson) => {
2024-01-17 17:44:12 +01:00
useAppStore().setupAppData(dataJson, this.$i18n.locale, String(this.$i18n.fallbackLocale));
2024-01-11 15:21:59 +01:00
this.loading = false;
2024-01-15 10:27:00 +01:00
this.setTimeout();
2024-01-16 10:25:13 +01:00
dataJson.fonts.forEach(font => this.injectFontFace(font.font_name, font.font));
this.redirectIfOneBrand(dataJson.items);
2024-01-11 15:21:59 +01:00
});
2023-10-16 16:35:11 +02:00
},
2024-02-02 10:34:55 +01:00
mounted() {
this.konami = new KonamiCode(() => {
this.$nextTick(() => {
this.chickenRun = true;
setTimeout(() => {this.chickenRun = false;}, 12000);
});
});
},
beforeUnmount() {
clearTimeout(this.timeout);
},
methods: {
2024-01-17 10:36:44 +01:00
t(text: string, params: Record<string,string> = {}, localeToUse: string|null = null): string {
return ToolboxHelper.trans(text, params, localeToUse);
},
transField(model: Typei18nModel, field: Typei18nFieldList) {
return ToolboxHelper.getTranslatableField(model, field);
},
2024-01-16 10:25:13 +01:00
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);
},
/** Redirect to ranges.index if there is only one brand. */
redirectIfOneBrand(brands: Array<TypeBrand>): void {
if (brands.length === 1) {
useAppStore().setActiveBrand(brands[0]);
this.activeBrand = brands[0];
navigateTo(useLocaleRoute()({"name": "brands-slug", "params": {"slug": this.transField(brands[0], "slug")}}));
} else {
useAppStore().setActiveBrand(null);
this.activeBrand = null;
}
},
/** Prolong le timer pour revenir au home screen. */
2024-01-12 18:22:50 +01:00
setTimeout(): void {
if(this.timeout) {
clearTimeout(this.timeout);
}
2024-01-19 11:33:36 +01:00
this.$nextTick(() => {
this.timeout = setTimeout(() => {
useAppStore().setActiveRange(null);
window.ipcRendererObject.getJsonData().then((dataJson) => {
this.redirectIfOneBrand(dataJson.items);
});
2024-01-19 11:33:36 +01:00
navigateTo(useLocaleRoute()({"name": "index"}));
}, useAppStore().getSettings().home_timeout * 1000);
});
2024-01-12 18:22:50 +01:00
},
}
});
</script>
<style lang="postcss">
@import "~/assets/scss/style.scss";
@import "@fortawesome/fontawesome-svg-core/styles.css";
</style>
<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>