20260716215550
This commit is contained in:
1 parent
5cd4e1e1d2
commit
49dafe524c
21 files changed
+1218
-272
No files matched your search
@@ -1,13 +1,21 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import NProgress from "nprogress";
|
||||
import "nprogress/nprogress.css";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
|
||||
NProgress.configure({ showSpinner: false });
|
||||
|
||||
function getRedirectPath(value) {
|
||||
return typeof value === "string" && value.startsWith("/") && !value.startsWith("//")
|
||||
? value
|
||||
: "/dashboard";
|
||||
}
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
component: () => import("../layouts/DefaultLayout.vue"),
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
@@ -117,6 +125,12 @@ const routes = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: () => import("../views/LoginView.vue"),
|
||||
meta: { title: "登录" },
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
redirect: "/dashboard",
|
||||
@@ -133,6 +147,14 @@ router.beforeEach((to) => {
|
||||
NProgress.start();
|
||||
document.title = to.meta.title ? `${to.meta.title} - FMS 管理系统` : "FMS 管理系统";
|
||||
|
||||
const authStore = useAuthStore();
|
||||
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
|
||||
return { name: "login", query: { redirect: to.fullPath } };
|
||||
}
|
||||
if (to.name === "login" && authStore.isAuthenticated) {
|
||||
return getRedirectPath(to.query.redirect);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user