import Vue from "vue"
|
import Router from "vue-router"
|
|
import orderManageRouter from "./orderManage/index.js"
|
// import { getMenuTreeByRole } from "@/api/menus/index"
|
// import store from "@/store/index.js"
|
|
Vue.use(Router)
|
const login = (resolve) => require(["@/views/other/login/index"], resolve)
|
const orderManageModule = (resolve) => require(["@/views/orderManageModule/index"], resolve)
|
const noData = (resolve) => require(["@/views/NoData/index"], resolve)
|
|
export const routes = [
|
// 无数据页面
|
{
|
path: "noData",
|
name: "noData",
|
meta: {
|
title: "",
|
auth: true
|
},
|
component: noData
|
},
|
{
|
path: "orderManageModule", // 订单管理
|
name: "orderManageModule",
|
component: orderManageModule,
|
children: orderManageRouter,
|
meta: {
|
title: "订单管理",
|
isAllways: true
|
}
|
}
|
]
|
export const constantRoutes = [
|
{
|
path: "/",
|
component: () => import("@/components/layout/index"),
|
name: "Index",
|
meta: {
|
title: "首页",
|
isAllways: true,
|
insIndex: true
|
},
|
redirect: {
|
name: "orderManage"
|
},
|
children: routes
|
},
|
{
|
path: "/login",
|
component: login,
|
meta: {
|
isLogin: true,
|
title: "登录"
|
}
|
},
|
{
|
path: "*",
|
component: () => import("@/views/other/error/404"),
|
meta: {
|
title: "404"
|
}
|
}
|
]
|
// 导出路由 在 main.js 里使用
|
const createRouter = () =>
|
new Router({
|
mode: "history",
|
// base: window.getServerJson.context,
|
scrollBehavior: () => ({ y: 0 }),
|
routes: constantRoutes
|
})
|
|
const router = createRouter()
|
|
// let isSkip = false
|
// async function hasPermission(routePath) {
|
// isSkip = false
|
// try {
|
// const res = await getMenuTreeByRole()
|
// const newPath = {
|
// path: "/noData"
|
// }
|
// const foundObject = res.data.list.find((obj) => obj.systemType === 4)
|
// if (foundObject) {
|
// // 存储进vuex
|
// store.commit("setMenus", foundObject)
|
// foundObject.menus.forEach((item) => {
|
// const nextPath = item.children.find((obj) => obj.path === routePath)
|
// if (nextPath) {
|
// newPath.path = nextPath.path
|
// isSkip = true
|
// }
|
// })
|
// } else {
|
// newPath.path = "/noData"
|
// }
|
// return newPath
|
// } catch (error) {
|
// return { path: "/noData" }
|
// }
|
// }
|
router.beforeEach(async (to, from, next) => {
|
console.log(to, from, "看看")
|
try {
|
// const result = await hasPermission(to.path)
|
// console.log(result, "result")
|
next()
|
// if (!isSkip) {
|
// next("/noData")
|
// }
|
} catch (error) {
|
console.error("Error in navigation guard:", error)
|
next()
|
}
|
})
|
|
// router.beforeEach((to, from, next) => {
|
// must call `next`
|
// console.log(to, from)
|
// if (to.path === "/custom/salesLead") {
|
// next()
|
// } else {
|
// if (to.meta.requireAuth) {
|
// next({
|
// path: "/login",
|
// query: { redirect: to.fullPath }
|
// })
|
// } else {
|
// next()
|
// }
|
// }
|
// })
|
|
export default router
|