From d68b036a3b3c67273b8effa3c9925ef3869a91ba Mon Sep 17 00:00:00 2001 From: haoxuan <haoxuan> Date: 星期三, 07 二月 2024 13:56:50 +0800 Subject: [PATCH] wms项目 wms系统参数设置的页面开发+路由+是否显示表头配置 --- src/router/index.js | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 100 insertions(+), 10 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index e37ce73..f1cf18e 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,6 +5,9 @@ import productRouter from "./product/index.js" // 浜у搧 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) @@ -12,8 +15,20 @@ const productManage = (resolve) => require(["@/views/productManage/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", @@ -51,6 +66,24 @@ meta: { title: "浠撳簱绠$悊", isAllways: true + } + }, + { + path: "reportForm", // 鎶ヨ〃 + name: "reportForm", + component: reportForm, + children: reportRouter, + meta: { + title: "鎶ヨ〃", + isAllways: true + } + }, + { + path: "/systemSet/commonSet", + name: "commonSet", + component: commonSet, + meta: { + title: "閫氱敤璁剧疆" } } ] @@ -95,18 +128,75 @@ }) 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) { + // 瀛樺偍杩泇uex + 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) => { - if ( - (to.path === "/overview/overviewList" || - to.path === "/reportForm/inOutboundDetail" || - to.path === "/productManage/productList") && - to.params.name - ) { - console.log(from, next) - to.meta.title = to.params.name - 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` -- Gitblit v1.8.0