首次提交
This commit is contained in:
41
chengduTestPlant/src/router/homePageRoutes.js
Normal file
41
chengduTestPlant/src/router/homePageRoutes.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const homePageRoutes = [
|
||||
{
|
||||
name: "dashboard",
|
||||
path: "/dashboard",
|
||||
meta: {
|
||||
title: "仪表盘",
|
||||
icon: "icon-dashboard",
|
||||
type: "M",
|
||||
affix: true
|
||||
},
|
||||
component: () => import("@/views/dashboard/index.vue")
|
||||
},
|
||||
{
|
||||
name: "userCenter",
|
||||
path: "/usercenter",
|
||||
meta: {
|
||||
title: "个人信息",
|
||||
icon: "icon-user",
|
||||
type: "M"
|
||||
},
|
||||
component: () => import("@/views/userCenter/index.vue")
|
||||
},
|
||||
{
|
||||
name: "message",
|
||||
path: "/message",
|
||||
meta: {
|
||||
title: "消息中心",
|
||||
icon: "icon-message",
|
||||
type: "M"
|
||||
},
|
||||
component: () => import("@/views/userCenter/message.vue")
|
||||
}
|
||||
]
|
||||
|
||||
export const homePage = {
|
||||
name: "home",
|
||||
path: "/home",
|
||||
meta: { title: "首页", icon: "icon-home", hidden: false, type: "M" }
|
||||
}
|
||||
|
||||
export default homePageRoutes
|
||||
58
chengduTestPlant/src/router/index.js
Normal file
58
chengduTestPlant/src/router/index.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import { createRouter, createWebHashHistory, createWebHistory } from "vue-router"
|
||||
import { useUserStore } from "@/store"
|
||||
import NProgress from "nprogress"
|
||||
import tool from "@/utils/tool"
|
||||
import "nprogress/nprogress.css"
|
||||
|
||||
import routes from "./webRouter.js"
|
||||
|
||||
const title = import.meta.env.VITE_APP_TITLE
|
||||
const defaultRoutePath = "/"
|
||||
const whiteRoute = ["login", "mineDoc", "interfaceList", "interfaceCode", "signature"]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
})
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start()
|
||||
const userStore = useUserStore()
|
||||
let toTitle = to.meta.title ? to.meta.title : to.name
|
||||
document.title = `${toTitle} - ${title}`
|
||||
const token = tool.local.get(import.meta.env.VITE_APP_TOKEN_PREFIX)
|
||||
|
||||
// 登录状态下
|
||||
if (token) {
|
||||
// 如果访问的是login直接跳转'/'
|
||||
if (to.name === "login") {
|
||||
next({ path: defaultRoutePath })
|
||||
return
|
||||
}
|
||||
// 如果没有pinia/userStore.user数据且不是undefined,则获取data然后跳转
|
||||
if (!userStore.user && userStore.user == undefined) {
|
||||
const data = await userStore.requestUserInfo()
|
||||
data && next({ path: to.path, query: to.query })
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
// 如果没有token,则看访问路径是否在白名单,如果在白名单则跳转访问,如果不在白名单跳转login页面
|
||||
if (!whiteRoute.includes(to.name)) {
|
||||
next({ name: "login", query: { redirect: to.fullPath } })
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
router.afterEach((to, from) => {
|
||||
NProgress.done()
|
||||
})
|
||||
|
||||
router.onError((error) => {
|
||||
console.log(error)
|
||||
NProgress.done()
|
||||
})
|
||||
|
||||
export default router
|
||||
70
chengduTestPlant/src/router/webRouter.js
Normal file
70
chengduTestPlant/src/router/webRouter.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import homePageRoutes from "./homePageRoutes"
|
||||
// 系统路由
|
||||
const routes = [
|
||||
{
|
||||
name: "layout",
|
||||
path: "/",
|
||||
component: () => import("@/layout/index.vue"),
|
||||
redirect: "dashboard",
|
||||
children: homePageRoutes
|
||||
},
|
||||
// 该路由不知道干嘛
|
||||
{
|
||||
name: "formLayout",
|
||||
path: "/formLayout",
|
||||
component: () => import("@/layout/index.vue"),
|
||||
redirect: "openForm",
|
||||
children: [
|
||||
{
|
||||
name: "openForm",
|
||||
path: "/openForm/:id",
|
||||
meta: {
|
||||
title: "公共表单",
|
||||
type: "M"
|
||||
},
|
||||
component: () => import("@/layout/form.vue")
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "login",
|
||||
path: "/login",
|
||||
component: () => import("@/views/login.vue"),
|
||||
meta: { title: "登录" }
|
||||
},
|
||||
// 不知道这个路由怎么进去
|
||||
{
|
||||
name: "mineDoc",
|
||||
path: "/mineDoc",
|
||||
component: () => import("@/views/mineDoc/index.vue"),
|
||||
meta: { title: "接口文档" },
|
||||
children: [
|
||||
{
|
||||
path: "/interfaceList",
|
||||
name: "interfaceList",
|
||||
meta: { title: "接口列表" },
|
||||
component: () => import("@/views/mineDoc/page/interfaceList.vue")
|
||||
},
|
||||
{
|
||||
path: "/interfaceCode",
|
||||
name: "interfaceCode",
|
||||
meta: { title: "代码释义" },
|
||||
component: () => import("@/views/mineDoc/page/interfaceCode.vue")
|
||||
},
|
||||
{
|
||||
path: "/signature",
|
||||
name: "signature",
|
||||
meta: { title: "签名算法" },
|
||||
component: () => import("@/views/mineDoc/page/signature.vue")
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
hidden: true,
|
||||
meta: { title: "访问的页面不存在" },
|
||||
component: () => import("@/layout/404.vue")
|
||||
}
|
||||
]
|
||||
|
||||
export default routes
|
||||
Reference in New Issue
Block a user