felicity-lims/webapp/App.vue

63 lines
1.4 KiB
Vue
Raw Normal View History

2022-04-01 04:29:09 +08:00
<script setup lang="ts">
2022-04-22 03:33:54 +08:00
import { computed, onMounted, onBeforeMount, watch } from "vue";
import { useRouter } from "vue-router";
import axios from "./axios/no-auth";
import { useStreamStore, useAuthStore } from "./stores";
import { userPreferenceComposable } from "./composables";
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 {
2022-04-22 03:33:54 +08:00
push({ name: "DASHBOARD" });
2022-04-15 16:32:24 +08:00
}
2022-04-01 04:29:09 +08:00
}
2022-04-22 03:33:54 +08:00
);
2022-04-22 03:33:54 +08:00
const streamStore = useStreamStore();
const { loadPreferedTheme } = userPreferenceComposable();
2021-04-09 06:37:58 +08:00
2022-04-22 03:33:54 +08:00
onBeforeMount(() => {
axios.get("setup/installation/").then((resp) => {
if (!resp.data.installed) {
push({ name: "INSTALLATION" });
}
});
});
onMounted(() => {
loadPreferedTheme();
streamStore.subscribeToActivityStream();
});
if (
window.performance
.getEntriesByType("navigation")
.map((nav: any) => nav.type)
.includes("reload")
) {
loadPreferedTheme();
}
const defaultLayout = "default";
const layout = computed(
() => `${currentRoute.value.meta.layout || defaultLayout}-layout`
);
2022-04-04 02:54:31 +08:00
</script>
<template>
<component :is="layout">
<!-- <div class="text-center">Flash Messages will come here.</div> -->
<router-view />
</component>
</template>