xt_web_td/src/router/index.js

82 lines
1.8 KiB
JavaScript

import { createRouter, createWebHistory} from 'vue-router';
import { authToken } from '@/store/index.js'
import http from "@/api/request.js";
const routes = [
{ path: "/", redirect: "/login" },
{
path: "/login",
name: "Login",
component: () => import("@/pages/login/index.vue"),
},
{
path: "/",
component: () => import("@/components/layout/index.vue"),
name: "Layout",
children: [
{
path: "",
name: "工作台",
meta: { icon: "file"},
children: [
// {
// path: "home",
// name: "主页",
// component: () => import("@/pages/home/index.vue"),
// },
// {
// path: "user",
// name: "用户管理",
// component: () => import("@/pages/system/user.vue"),
// },
{
path: "home",
name: "快捷导航",
component: () => import("@/pages/cal/index.vue"),
},
{
path: "dq",
name: "贷前计算",
component: () => import("@/pages/cal/dq.vue"),
},
{
path: "dh",
name: "贷后计算",
component: () => import("@/pages/cal/dh.vue"),
},
],
},
],
},
];
const router = createRouter({
history: createWebHistory(),
routes,
});
router.beforeEach(async (to, from, next) => {
if (to.path === "/login") {
if (authToken.access) {
next("/home");
} else {
next();
}
} else {
if (authToken.access) {
try{
await http.get("/check_token/")
next();
} catch(e){
authToken.access = null;
authToken.refresh = null;
next("/login");
}
} else {
next("/login");
}
}
})
export default router;