init project
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import RootLayout from "@/layout/RootLayout.vue";
|
||||
import MainLayout from "@/layout/MainLayout.vue";
|
||||
import Login from "@/pages/Login.vue";
|
||||
import chartRoutes from "@/router/routes/chartRoutes";
|
||||
import customerRoutes from "@/router/routes/customerRoutes";
|
||||
import { managementAccountRoutes, managementSettingRoutes } from "@/router/routes/managementRoutes";
|
||||
import permissionRoutes from "@/router/routes/permissionRoutes";
|
||||
import registrationRoutes from "@/router/routes/registrationRoutes";
|
||||
import tabRoutes from "@/router/routes/tabRoutes";
|
||||
import userRoutes from "@/router/routes/userRoutes";
|
||||
import { useGlobalUIStore } from "@/store/globalUI";
|
||||
import { useUserStore } from "timi-web";
|
||||
|
||||
const detailRoutes = [
|
||||
...customerRoutes,
|
||||
...userRoutes,
|
||||
...registrationRoutes,
|
||||
...managementSettingRoutes,
|
||||
...permissionRoutes,
|
||||
...chartRoutes,
|
||||
...managementAccountRoutes
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory("/"),
|
||||
scrollBehavior(_to, _from, savedPosition) {
|
||||
if (savedPosition) {
|
||||
return savedPosition;
|
||||
}
|
||||
|
||||
return {
|
||||
left: 0,
|
||||
top: 0
|
||||
};
|
||||
},
|
||||
routes: [
|
||||
{
|
||||
path: "/",
|
||||
component: RootLayout,
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
redirect: "/customers"
|
||||
},
|
||||
{
|
||||
path: "login",
|
||||
name: "Login",
|
||||
component: Login,
|
||||
meta: {
|
||||
depth: 1,
|
||||
navBarVisible: false,
|
||||
tabBarVisible: false,
|
||||
bodyBackground: "#F5F5F8",
|
||||
darkBodyBackground: "#10161f"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "",
|
||||
component: MainLayout,
|
||||
meta: {
|
||||
depth: 1,
|
||||
navBarVisible: false,
|
||||
tabBarVisible: false,
|
||||
bodyBackground: "#F5F5F8",
|
||||
darkBodyBackground: "#10161f"
|
||||
},
|
||||
children: [
|
||||
...tabRoutes,
|
||||
...detailRoutes
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
redirect: "/customers"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const userStore = useUserStore();
|
||||
if (to.path === "/login") {
|
||||
return userStore.isLogged() ? "/management" : true;
|
||||
}
|
||||
|
||||
if (!userStore.isLogged()) {
|
||||
return {
|
||||
path: "/login",
|
||||
query: {
|
||||
redirect: to.fullPath
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
router.afterEach((to) => {
|
||||
const globalUIStore = useGlobalUIStore();
|
||||
const isDarkMode = globalUIStore.themeMode === "dark";
|
||||
const fallbackBackground = isDarkMode ? "#10161f" : "#F5F5F8";
|
||||
const targetBackground = isDarkMode ? to.meta.darkBodyBackground : to.meta.bodyBackground;
|
||||
globalUIStore.setBodyBackground(typeof targetBackground === "string" ? targetBackground : fallbackBackground);
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user