| | |
| | | import { getLoginPageSource } from "@/utils/loginSource"; // 导入登录来源判断工具 |
| | | import axios from "axios"; |
| | | |
| | | |
| | | |
| | | const permission = { |
| | | state: { |
| | | routes: [], |
| | |
| | | GenerateRoutes({ commit }) { |
| | | // 示例:根据登录来源执行不同的逻辑 |
| | | const loginSource = getLoginPageSource(); |
| | | // console.log(`用户从 ${loginSource} 页面登录`); |
| | | const HIsHide = false; |
| | | const hiddenMenuNames = [ |
| | | "WayBillPaymentBill", |
| | | "payWayBillPaymentBillList", |
| | | "Sell", |
| | | "Purchase", |
| | | "ICMO", |
| | | "ScMould", |
| | | "System", |
| | | "Production", |
| | | "Transport", |
| | | "GyWarehouse", |
| | | "GyStockPlace", |
| | | "GyItemMoney", |
| | | "GyEmployee", |
| | | "GyDepartment", |
| | | "GyCurrency", |
| | | "GyUnit", |
| | | "GySupplier", |
| | | "GyMaterial", |
| | | "GyCustomer", |
| | | "GyProperty", |
| | | ]; |
| | | let HIsHide = false; |
| | | if (loginSource == "loginTMS") { |
| | | HIsHide = true; |
| | | } |
| | | |
| | | // console.log(`用户从 ${loginSource} 页面登录`); |
| | | |
| | | function convertMenu(menu, level = 0) { |
| | | |
| | | const hasChildren = menu.childMenus && menu.childMenus.length > 0; |
| | | const route = { |
| | | name: menu.HNumber, |
| | |
| | | link: null, |
| | | noCache: false, |
| | | }, |
| | | hidden: hiddenMenuNames.includes(menu.HNumber) ? HIsHide : false, |
| | | // hidden: hiddenMenuNames.includes(menu.HNumber) ? HIsHide : false, |
| | | hidden: HIsHide , |
| | | component: hasChildren ? level === 0 ? "Layout" : "ParentView" : menu.Hurl, |
| | | }; |
| | | if (hasChildren) { |
| | |
| | | return route; |
| | | } |
| | | return new Promise((resolve) => { |
| | | let params = { HMakeName: sessionStorage["HUserName"], HType: "vue" }; |
| | | let req = { HMakeName: sessionStorage["HUserName"], HType: "vue" }; |
| | | // 向后端请求路由数据 |
| | | getRouters(params).then((res) => { |
| | | if (res.count == 1) { |
| | | let menuData = JSON.parse(res.data); |
| | | axios.get("http://localhost:8082/LuBaoAPI/Web/MenuList_1", { params: req }).then(res=>{ |
| | | if (res.data.code === "1") { |
| | | let menuData = JSON.parse(res.data.data); |
| | | const data = menuData.map((item) => convertMenu(item, 0)); |
| | | data.forEach((route) => { |
| | | route.alwaysShow = true; |
| | | }); |
| | | console.log("路由数据",data) |
| | | console.log("路由数据",typeof(data)) |
| | | const jsondata=JSON.stringify(data) |
| | | axios.post("http://localhost:8082/LuBaoAPI/Web/buildRouteObj", { |
| | | content: jsondata |
| | | }) |
| | | .then(res => { |
| | | if (res.data.code === "1") { |
| | | console.log(res.data.Message); |
| | | } |
| | | }); |
| | | const sdata = JSON.parse(JSON.stringify(data)); |
| | | const rdata = JSON.parse(JSON.stringify(data)); |
| | |
| | | commit("SET_DEFAULT_ROUTES", sidebarRoutes); |
| | | commit("SET_TOPBAR_ROUTES", sidebarRoutes); |
| | | resolve(rewriteRoutes); |
| | | } else { |
| | | }else if(res.data.code === "2") |
| | | { |
| | | const fileContent = res.data.data; // 字符串 |
| | | const data = JSON.parse(fileContent); // 解析为对象数组 |
| | | const sdata = JSON.parse(JSON.stringify(data)); |
| | | const rdata = JSON.parse(JSON.stringify(data)); |
| | | const sidebarRoutes = filterAsyncRouter(sdata); |
| | | const rewriteRoutes = filterAsyncRouter(rdata, false, true); |
| | | rewriteRoutes.push({ path: "*", redirect: "/404", hidden: true }); |
| | | router.addRoutes(rewriteRoutes); |
| | | commit("SET_ROUTES", rewriteRoutes); |
| | | commit("SET_SIDEBAR_ROUTERS", constantRoutes.concat(sidebarRoutes)); |
| | | commit("SET_DEFAULT_ROUTES", sidebarRoutes); |
| | | commit("SET_TOPBAR_ROUTES", sidebarRoutes); |
| | | resolve(rewriteRoutes); |
| | | } |
| | | else { |
| | | this.$modal.msgError(response.data.code + response.data.Message); |
| | | } |
| | | }); |