|
@@ -1,4 +1,4 @@
|
|
-<script setup lang="ts">
|
|
|
|
|
|
+<script lang="ts">
|
|
import { appName } from "@/env";
|
|
import { appName } from "@/env";
|
|
import { reactive } from "vue";
|
|
import { reactive } from "vue";
|
|
import type { RouteLocationNormalized, NavigationGuardNext } from "vue-router";
|
|
import type { RouteLocationNormalized, NavigationGuardNext } from "vue-router";
|
|
@@ -7,14 +7,17 @@ import { useMainStore } from "@/stores/main";
|
|
import { storeToRefs } from "pinia";
|
|
import { storeToRefs } from "pinia";
|
|
import { useI18n } from "vue-i18n";
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
|
|
-
|
|
|
|
|
|
+export default {
|
|
|
|
+ setup() {
|
|
|
|
+ onBeforeRouteUpdate((to, from, next) => {
|
|
|
|
+ routeGuardAdmin(to, from, next);
|
|
|
|
+ });
|
|
|
|
|
|
const { t, locale } = useI18n();
|
|
const { t, locale } = useI18n();
|
|
const mainStore = useMainStore();
|
|
const mainStore = useMainStore();
|
|
const mainStoreRef = storeToRefs(mainStore);
|
|
const mainStoreRef = storeToRefs(mainStore);
|
|
|
|
|
|
const hasAdminAccess = mainStoreRef.readhasAdminAccess;
|
|
const hasAdminAccess = mainStoreRef.readhasAdminAccess;
|
|
-
|
|
|
|
const miniDrawer = mainStoreRef.readDashboardMiniDrawer;
|
|
const miniDrawer = mainStoreRef.readDashboardMiniDrawer;
|
|
const showDrawer = mainStoreRef.readDashboardShowDrawer;
|
|
const showDrawer = mainStoreRef.readDashboardShowDrawer;
|
|
|
|
|
|
@@ -34,33 +37,43 @@ import { useI18n } from "vue-i18n";
|
|
mainStore.logOut();
|
|
mainStore.logOut();
|
|
}
|
|
}
|
|
|
|
|
|
- onBeforeRouteUpdate((to, from, next) => {
|
|
|
|
- routeGuardMain(to, from, next);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
const lang = reactive([
|
|
const lang = reactive([
|
|
- { title: "English", text: "en" },
|
|
|
|
- { title: "中文", text: "zh" },
|
|
|
|
-]);
|
|
|
|
-
|
|
|
|
-function setLang(lang: String) {
|
|
|
|
- locale.value = `${lang}`;
|
|
|
|
- localStorage.setItem("lang", `${lang}`);
|
|
|
|
-}
|
|
|
|
|
|
+ { title: "English", text: "en" },
|
|
|
|
+ { title: "中文", text: "zh" },
|
|
|
|
+ ]);
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // beforeRouteEnter((to, from, next) =>{
|
|
|
|
- // routeGuardMain(to, from, next);
|
|
|
|
- // })
|
|
|
|
|
|
+ function setLang(lang: String) {
|
|
|
|
+ locale.value = `${lang}`;
|
|
|
|
+ localStorage.setItem("lang", `${lang}`);
|
|
|
|
+ }
|
|
|
|
|
|
-const routeGuardMain = async (
|
|
|
|
|
|
+ return {
|
|
|
|
+ t,
|
|
|
|
+ locale,
|
|
|
|
+ hasAdminAccess,
|
|
|
|
+ miniDrawer,
|
|
|
|
+ showDrawer,
|
|
|
|
+ switchMiniDrawer,
|
|
|
|
+ switchShowDrawer,
|
|
|
|
+ logout,
|
|
|
|
+ lang,
|
|
|
|
+ setLang,
|
|
|
|
+ appName
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ beforeRouteEnter(to, from, next) {
|
|
|
|
+ routeGuardAdmin(to, from, next);
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+const routeGuardAdmin = async (
|
|
to: RouteLocationNormalized,
|
|
to: RouteLocationNormalized,
|
|
from: RouteLocationNormalized,
|
|
from: RouteLocationNormalized,
|
|
next: NavigationGuardNext
|
|
next: NavigationGuardNext
|
|
) => {
|
|
) => {
|
|
- if (to.path === "/main") {
|
|
|
|
- next("/main/dashboard");
|
|
|
|
|
|
+ const mainStore = useMainStore();
|
|
|
|
+ const mainStoreRef = storeToRefs(mainStore);
|
|
|
|
+ if (!mainStoreRef.readhasAdminAccess) {
|
|
|
|
+ next("/main");
|
|
} else {
|
|
} else {
|
|
next();
|
|
next();
|
|
}
|
|
}
|
|
@@ -71,7 +84,10 @@ const routeGuardMain = async (
|
|
<div>
|
|
<div>
|
|
<v-navigation-drawer persistent :rail="miniDrawer" v-model="showDrawer">
|
|
<v-navigation-drawer persistent :rail="miniDrawer" v-model="showDrawer">
|
|
<v-sheet class="d-flex flex-column fill-height">
|
|
<v-sheet class="d-flex flex-column fill-height">
|
|
- <v-sheet class="">
|
|
|
|
|
|
+ <v-sheet>
|
|
|
|
+ <a class="d-flex justify-center mt-3">
|
|
|
|
+ <img src="@/assets/img/Choozmo-logo.png" alt="" class="logo-img" />
|
|
|
|
+ </a>
|
|
<v-list>
|
|
<v-list>
|
|
<!-- <v-list-subheader><span v-show="!miniDrawer">Main menu</span></v-list-subheader> -->
|
|
<!-- <v-list-subheader><span v-show="!miniDrawer">Main menu</span></v-list-subheader> -->
|
|
<v-list-item to="/main/dashboard" prepend-icon="dashboard">
|
|
<v-list-item to="/main/dashboard" prepend-icon="dashboard">
|
|
@@ -144,9 +160,10 @@ const routeGuardMain = async (
|
|
<v-btn icon="more_vert" v-bind="props" />
|
|
<v-btn icon="more_vert" v-bind="props" />
|
|
</template>
|
|
</template>
|
|
<v-list>
|
|
<v-list>
|
|
- <v-list-item to="/main/profile" append-icon="person">
|
|
|
|
|
|
+ <!-- <v-list-item to="/main/profile" append-icon="person">
|
|
<v-list-item-title>{{ t("userProfile") }}</v-list-item-title>
|
|
<v-list-item-title>{{ t("userProfile") }}</v-list-item-title>
|
|
- </v-list-item>
|
|
|
|
|
|
+ </v-list-item> -->
|
|
|
|
+
|
|
<!-- <v-list-item to="/main/profile" append-icon="language">
|
|
<!-- <v-list-item to="/main/profile" append-icon="language">
|
|
<v-list-item-title>{{ t("language") }}</v-list-item-title>
|
|
<v-list-item-title>{{ t("language") }}</v-list-item-title>
|
|
</v-list-item> -->
|
|
</v-list-item> -->
|
|
@@ -159,13 +176,13 @@ const routeGuardMain = async (
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<v-list-item
|
|
<v-list-item
|
|
- v-for="(item, index) in lang"
|
|
|
|
- :key="index"
|
|
|
|
- :value="item.text"
|
|
|
|
- @click="setLang(item.text)"
|
|
|
|
- >
|
|
|
|
- <v-list-item-title>{{ item.title }}</v-list-item-title>
|
|
|
|
- </v-list-item>
|
|
|
|
|
|
+ v-for="(item, index) in lang"
|
|
|
|
+ :key="index"
|
|
|
|
+ :value="item.text"
|
|
|
|
+ @click="setLang(item.text)"
|
|
|
|
+ >
|
|
|
|
+ <v-list-item-title>{{ item.title }}</v-list-item-title>
|
|
|
|
+ </v-list-item>
|
|
</v-list-group>
|
|
</v-list-group>
|
|
|
|
|
|
<v-list-item @click="logout" append-icon="logout">
|
|
<v-list-item @click="logout" append-icon="logout">
|
|
@@ -184,7 +201,7 @@ const routeGuardMain = async (
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
-<style lang="scss" scoped>
|
|
|
|
|
|
+<style lang="scss">
|
|
.navbar {
|
|
.navbar {
|
|
color: #fff;
|
|
color: #fff;
|
|
background-image: linear-gradient(
|
|
background-image: linear-gradient(
|
|
@@ -193,4 +210,12 @@ const routeGuardMain = async (
|
|
rgb(178, 69, 146) 100%
|
|
rgb(178, 69, 146) 100%
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+.logo-img {
|
|
|
|
+ max-width: 200px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.card-title {
|
|
|
|
+ letter-spacing: 1px !important;
|
|
|
|
+}
|
|
</style>
|
|
</style>
|