保存进度!

This commit is contained in:
2022-12-15 09:25:51 +08:00
parent 5c72437e2d
commit 5dcff64bf5
130 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";
export const routes = [
// 根路由
{
path: "/",
redirect: "Login",
hidden: true
},
// 登录
{
path: "/login",
name: "Login",
hidden: true,
component: () => import("../views/account/Login.vue")
},
// 路由中转
{
path: "/admin",
name: "Admin",
hidden: true
}
];
const router = createRouter({
history: createWebHashHistory(),
routes
});
export default router;

View File

@@ -0,0 +1,118 @@
import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";
export const routes = [
{
path: "/",
redirect: "Login",
hidden: true,
aaa: "",
bbb:""
},
// 登录
{
path: "/login",
name: "Login",
hidden: true,
component: () => import("../views/account/Login.vue")
},
// 后台首页
{
path: "/home",
name: "Home",
meta: {
title: "控制台",
icon: "home"
},
component: () => import("../layout/Index.vue"),
children: [
{
path: "/console",
name: "Console",
meta: {
title: "首页"
},
component: () => import("../views/console/Index.vue"),
}
]
},
{
path: "/system",
name: "System",
meta: {
title: "系统配置",
icon: "system"
},
component: () => import("../layout/Index.vue"),
children: [
{
path: "/user",
name: "User",
meta: {
title: "用户列表"
},
component: () => import("../views/system/User.vue"),
},
{
path: "/role",
name: "Role",
meta: {
title: "角色列表"
},
component: () => import("../views/system/Role.vue"),
},
{
path: "/menu",
name: "Menu",
meta: {
title: "菜单列表"
},
component: () => import("../views/system/Menu.vue"),
}
]
},
{
path: "/news",
name: "News",
meta: {
title: "信息管理",
icon: "information"
},
component: () => import("../layout/Index.vue"),
children: [
{
path: "/newsIndex",
name: "NewsIndex",
meta: {
title: "信息列表"
},
component: () => import("../views/info/Index.vue"),
},
{
path: "/newsCategory",
name: "NewsCategory",
meta: {
title: "信息分类"
},
component: () => import("../views/info/Category.vue"),
},
{
path: "/newsDetailed",
name: "NewsDetailed",
hidden: true,
meta: {
title: "信息详情"
},
component: () => import("../views/info/Detailed.vue"),
}
]
}
];
const router = createRouter({
history: createWebHashHistory(),
routes
});
export default router;

View File

@@ -0,0 +1,41 @@
import router from "./index";
import store from "../store";
// cookie
import { getToken } from "@u/cookies";
// 全局前置守卫
router.beforeEach((to, from, next) => {
if(!getToken()) {
if(to.name !== "Login") {
next("Login");
}else{
next();
}
}else{
if(store.state.permission.async_router.length === 0){
store.dispatch("permission/getRouterAction").then(response => {
// 获取动态路由
const async_router_data = store.getters["permission/async_router"];
// 获取静态路由
const default_router_data = router.options.routes;
// 更新静态路由
router.options.routes = default_router_data.concat(async_router_data);
// 更新动态路由
async_router_data.forEach(item => {
router.addRoute(item);
});
if(to.name === "Admin") {
const first_router = async_router_data[0]?.children[0] || async_router_data[0];
next({ ...first_router, replace: true});
}else{
// 确认进入下一个路由
next({ ...to, replace: true});
}
})
}else{
next();
}
}
})
// 全局后置守卫
router.afterEach((to, from) => {
})