| | |
| | | import operateRouter from "./operate/index.js" // 操作 |
| | | import warehouseManageRouter from "./warehouseManage/index.js" // 仓库管理 |
| | | import reportRouter from "./report/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 operate = (resolve) => require(["@/views/operate/index"], resolve) // 操作 |
| | | const warehouseManage = (resolve) => require(["@/views/warehouseManage/index"], resolve) // 仓库管理 |
| | | const reportForm = (resolve) => require(["@/views/reportForm/index"], resolve) // 报表 |
| | | |
| | | const noData = (resolve) => require(["@/views/NoData/index"], resolve) |
| | | const commonSet = (resolve) => require(["@/views/systemSet/commonSet/index"], resolve) // 系统设置 |
| | | export const routes = [ |
| | | // 无权限数据页面 |
| | | { |
| | | path: "noData", |
| | | name: "noData", |
| | | meta: { |
| | | title: "", |
| | | auth: true, |
| | | }, |
| | | component: noData, |
| | | }, |
| | | { |
| | | path: "overview", // 概述 |
| | | name: "overview", |
| | |
| | | title: "报表", |
| | | isAllways: true |
| | | } |
| | | }, |
| | | { |
| | | path: "/systemSet/commonSet", |
| | | name: "commonSet", |
| | | component: commonSet, |
| | | meta: { |
| | | title: "通用设置" |
| | | } |
| | | } |
| | | ] |
| | | export const 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 === 3); |
| | | if (foundObject) { |
| | | // 存储进vuex |
| | | store.commit('setMenus', foundObject.menus); |
| | | 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) => { |
| | | try { |
| | | const result = await hasPermission(to.path); |
| | | console.log(result,"result") |
| | | next(); |
| | | if (!isSkip) { |
| | | if(to.path==="/overview/overviewList"||to.path==="/overview/previewExcel"||to.path==="/operate/inventoryAdjustmentHistory"){ |
| | | next(); |
| | | }else{ |
| | | next('/noData') |
| | | } |
| | | } |
| | | } catch (error) { |
| | | console.error('Error in navigation guard:', error); |
| | | next(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | router.afterEach((to, from, next) => { |
| | | console.log(to, "to") |
| | | if ((to.path === "/overview/overviewList" || to.path === "/productManage/productList") && to.params.name) { |
| | | console.log(from, next) |
| | | to.meta.title = to.params.name |
| | | // document.title = to.meta.title |
| | | } else if (to.name === "inboundOutboundDetail") { |
| | | to.meta.title = "入库明细报表" |
| | | // document.title = to.meta.title |
| | | if(window.sessionStorage.getItem('routeName')){ |
| | | if(to.path === "/overview/overviewList"&&to.meta.title!="采购入库"){ |
| | | window.sessionStorage.setItem("routeName",to.params.name) |
| | | to.meta.title=to.params.name |
| | | }else if(to.meta.title==="采购入库"){ |
| | | to.meta.title = window.sessionStorage.getItem('routeName'); |
| | | } |
| | | }else{ |
| | | if ((to.path === "/overview/overviewList" || to.path === "/productManage/productList") && to.params.name) { |
| | | console.log(from, next) |
| | | window.sessionStorage.setItem("routeName",to.params.name) |
| | | to.meta.title = window.sessionStorage.getItem('routeName'); |
| | | // document.title = to.meta.title |
| | | } else if (to.name === "inboundOutboundDetail") { |
| | | to.meta.title = "入库明细报表" |
| | | // document.title = to.meta.title |
| | | }else{ |
| | | // window.sessionStorage.removeItem("routeName") |
| | | } |
| | | } |
| | | |
| | | }) |
| | | // router.beforeEach((to, from, next) => { |
| | | // must call `next` |