felicity-lims/webapp/App.vue

68 lines
1.6 KiB
Vue
Raw Permalink Normal View History

2023-11-10 14:05:15 +08:00
<script setup lang="ts">
import { computed, onMounted, onBeforeMount, watch } from "vue";
import { useRouter } from "vue-router";
import axios from "@/composables/axios";
import { useStreamStore } from "@/stores/stream";
import { useAuthStore } from "@/stores/auth";
import userPreferenceComposable from "@/composables/preferences";
2023-11-10 14:05:15 +08:00
const { currentRoute, push } = useRouter();
const authStore = useAuthStore();
if (!authStore.auth.isAuthenticated) {
push({ name: "LOGIN" });
}
watch(
() => authStore.auth.isAuthenticated,
(newAuth, oldAuth) => {
if (!newAuth) {
push({ name: "LOGIN" });
} else {
push({ name: "DASHBOARD" });
}
}
);
const streamStore = useStreamStore();
const { loadPreferedTheme } = userPreferenceComposable();
onBeforeMount(() => {
axios.get("setup/installation").then((resp) => {
if (!resp.data.installed) {
push({ name: "INSTALLATION" });
}
});
});
onMounted(() => {
loadPreferedTheme();
2023-11-22 17:13:16 +08:00
streamStore.subscribeToActivityStream();
2023-11-10 14:05:15 +08:00
});
if (
window.performance
.getEntriesByType("navigation")
.map((nav: any) => nav.type)
.includes("reload")
) {
loadPreferedTheme();
}
const mobileLayout = "mobile";
const defaultLayout = "default";
let layout = computed(
() => {
const isMobile = (navigator as any)?.userAgentData?.mobile ?? false;
return `${isMobile ? mobileLayout : (currentRoute.value.meta.layout || defaultLayout)}-layout`;
}
);
</script>
<template>
<component :is="layout">
2024-11-23 14:15:51 +08:00
<notifications position="bottom right" /> <!-- @kyvg/vue3-notification -->
2023-11-10 14:05:15 +08:00
<router-view />
</component>
</template>