import auth from "@/plugins/auth"; import router, { constantRoutes, dynamicRoutes } from "@/router"; import { getRouters } from "@/api/menu"; import Layout from "@/layout/index"; import ParentView from "@/components/ParentView"; import InnerLink from "@/layout/components/InnerLink"; const permission = { state: { routes: [], addRoutes: [], defaultRoutes: [], topbarRouters: [], sidebarRouters: [], }, mutations: { SET_ROUTES: (state, routes) => { state.addRoutes = routes; state.routes = constantRoutes.concat(routes); }, SET_DEFAULT_ROUTES: (state, routes) => { state.defaultRoutes = constantRoutes.concat(routes); }, SET_TOPBAR_ROUTES: (state, routes) => { state.topbarRouters = routes; }, SET_SIDEBAR_ROUTERS: (state, routes) => { state.sidebarRouters = routes; }, }, actions: { // 生成路由 GenerateRoutes({ commit }) { return new Promise((resolve) => { // 向后端请求路由数据 let data = [ { alwaysShow: true, component: "Layout", meta: { icon: "build", link: null, noCache: false, title: "销售管理", }, hidden: false, name: "Sell", path: "/sell", redirect: "noRedirect", children: [ { meta: { icon: "build", link: null, noCache: false, title: "销售出库单", }, hidden: false, name: "SellOut", path: "sellOut", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "销售出库单维护", }, component: () => import("@/views/sell/sellOut/sellOutBill.vue"), hidden: false, name: "SellOutBill", path: "sellOutBill", }, { meta: { icon: "build", link: null, noCache: false, title: "销售出库单", }, component: () => import("@/views/sell/sellOut/sellOutBillEdit.vue"), hidden: false, name: "SellOutBillEdit", path: "sellOutBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "销售订单", }, hidden: false, name: "SeOrder", path: "seOrder", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "销售订单维护", }, component: () => import("@/views/sell/xsSeOrderBill/xsSeOrderBill.vue"), hidden: false, name: "XsSeOrderBill", path: "xsSeOrderBill", }, { meta: { icon: "build", link: null, noCache: false, title: "销售订单", }, component: () => import( "@/views/sell/xsSeOrderBill/xsSeOrderBillEdit.vue" ), hidden: false, name: "XsSeOrderBillEdit", path: "xsSeOrderBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "发货通知单", }, hidden: false, name: "SeOutStock", path: "seOutStock", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "发货通知单维护", }, component: () => import("@/views/sell/XsSeOutStockBill.vue"), hidden: false, name: "XsSeOutStockBill", path: "xsSeOutStockBill", }, { meta: { icon: "build", link: null, noCache: false, title: "发货通知单", }, component: () => import("@/views/sell/XsSeOutStockBillEdit.vue"), hidden: false, name: "XsSeOutStockBillEdit", path: "xsSeOutStockBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "退货通知单", }, hidden: false, name: "SeOutStockBack", path: "seOutStockBack", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "退货通知单维护", }, component: () => import("@/views/sell/XsSeOutStockBackBillList.vue"), hidden: false, name: "XsSeOutStockBackBillList", path: "xsSeOutStockBackBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "退货通知单", }, component: () => import("@/views/sell/XsSeOutStockBackBillEdit.vue"), hidden: false, name: "XsSeOutStockBackBillEdit", path: "xsSeOutStockBackBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "销售退货单", }, hidden: false, name: "StockBillMainList", path: "StockBillMainList", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "销售退货单维护", }, component: () =>import ("@/views/sell/Kf_ICStockBillMainList/Kf_ICStockBillMainList.vue"), hidden: false, name: "KfICStockBillMainList", path: "KfICStockBillMainList", }, { meta: { icon: "build", link: null, noCache: false, title: "销售退货单", }, component: () =>import ("@/views/sell/Kf_ICStockBillMainList/Kf_ICStockBillMainListEdit.vue"), hidden: false, name: "KfICStockBillMainListEdit", path: "KfICStockBillMainListEdit", }, ], }, ], }, { alwaysShow: true, component: "Layout", meta: { icon: "build", link: null, noCache: false, title: "仓库管理", }, hidden: false, name: "Warehouse", path: "/warehouse", redirect: "noRedirect", children: [ { meta: { icon: "build", link: null, noCache: false, title: "领料发货", }, hidden: false, name: "Shipment", path: "shipment", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "出库申请单维护", }, component: () => import("@/views/warehouse/shipment/Kf_StockOutRequestBillList.vue"), hidden: false, name: "Kf_StockOutRequestBillList", path: "Kf_StockOutRequestBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "出库申请单", }, component: () => import("@/views/warehouse/shipment/Kf_StockOutRequestBill.vue"), hidden: false, name: "Kf_StockOutRequestBill", path: "Kf_StockOutRequestBill", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "调拨盘点", }, hidden: false, name: "Transfer", path: "transfer", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "调拨申请单维护", }, component: () => import("@/views/warehouse/transfer/Kf_MoveStockRequestBillList.vue"), hidden: false, name: "Kf_MoveStockRequestBillList", path: "Kf_MoveStockRequestBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "调拨申请单", }, component: () => import("@/views/warehouse/transfer/Kf_MoveStockRequestBillEdit.vue"), hidden: false, name: "Kf_MoveStockRequestBillEdit", path: "Kf_MoveStockRequestBillEdit", }, { meta: { icon: "build", link: null, noCache: false, title: "直接调拨单维护", }, component: () => import("@/views/KCGL/MoveStockBill/Kf_MoveStockBillList.vue"), hidden: false, name: "Kf_MoveStockBillList", path: "Kf_MoveStockBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "直接调拨单", }, component: () => import("@/views/KCGL/MoveStockBill/Kf_MoveStockBillEdit.vue"), hidden: false, name: "Kf_MoveStockBillEdit", path: "Kf_MoveStockBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "条码主档", }, hidden: false, name: "BarcodeMaster", path: "barcodeMaster", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "条码生成", }, component: () => import("@/views/warehouse/barcodeMaster/Gy_BarCodeBill.vue"), hidden: false, name: "Gy_BarCodeBill", path: "Gy_BarCodeBill", }, ], }, ], }, { alwaysShow: true, component: "Layout", meta: { icon: "build", link: null, noCache: false, title: "基础建模", }, hidden: false, name: "Basic", path: "/basic", redirect: "noRedirect", children: [ { meta: { icon: "build", link: null, noCache: false, title: "生产资料", }, hidden: false, name: "Production", path: "production", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "生产资料列表", }, component: () => import("@/views/basic/production/gySource.vue"), hidden: false, name: "GySource", path: "gySource", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "公用资料", }, hidden: false, name: "Gy", path: "gy", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "仓库列表", }, component: () => import("@/views/basic/gyWarehouse/gyWarehouse.vue"), hidden: false, name: "GyWarehouse", path: "gyWarehouse", }, { meta: { icon: "build", link: null, noCache: false, title: "仓位列表", }, component: () => import("@/views/basic/gyStockPlace/gyStockPlace.vue"), hidden: false, name: "GyStockPlace", path: "gyStockPlace", }, { meta: { icon: "build", link: null, noCache: false, title: "职员列表", }, component: () => import("@/views/basic/gyEmployee/gyEmployee.vue"), hidden: false, name: "GyEmployee", path: "gyEmployee", }, { meta: { icon: "build", link: null, noCache: false, title: "部门列表", }, component: () => import("@/views/basic/gy/gyDepartment.vue"), hidden: false, name: "GyDepartment", path: "gyDepartment", }, { meta: { icon: "build", link: null, noCache: false, title: "供应商列表", }, component: () => import("@/views/basic/gy/gySupplier.vue"), hidden: false, name: "GySupplier", path: "gySupplier", }, { meta: { icon: "build", link: null, noCache: false, title: "物料列表", }, component: () => import("@/views/gyMaterial/GyMaterial.vue"), hidden: false, name: "GyMaterial", path: "GyMaterial", }, { meta: { icon: "build", link: null, noCache: false, title: "客户列表", }, component: () => import("@/views/GyCustomer/index.vue"), hidden: false, name: "GyCustomer", path: "GyCustomer", }, ], }, ], }, { alwaysShow: true, component: "Layout", meta: { icon: "build", link: null, noCache: false, title: "采购管理", }, hidden: false, name: "Purchase", path: "/purchase", redirect: "noRedirect", children: [ { meta: { icon: "build", link: null, noCache: false, title: "采购订单", }, hidden: false, name: "PoOrder", path: "poOrder", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "采购订单列表", }, component: () => import("@/views/purchase/cgPoOrderBill/cgPoOrderBill"), hidden: false, name: "CgPoOrderBill", path: "cgPoOrderBill", }, { meta: { icon: "build", link: null, noCache: false, title: "采购订单", }, component: () => import( "@/views/purchase/cgPoOrderBill/cgPoOrderBillEdit" ), hidden: false, name: "CgPoOrderBillEdit", path: "cgPoOrderBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "收料通知单", }, hidden: false, name: "PoInStock", path: "PoInStock", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "收料通知单列表", }, component: () => import( "@/views/purchase/cgPoInStockBill/cgPoInStockBill.vue" ), hidden: false, name: "CgPoInStockBillList", path: "cgPoInStockBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "收料通知单", }, component: () => import( "@/views/purchase/cgPoInStockBill/cgPoInStockBillEdit.vue" ), hidden: false, name: "CgPoInStockBillEdit", path: "cgPoInStockBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "采购入库单", }, hidden: false, name: "POStockInBill", path: "POStockInBill", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "采购入库单维护", }, component: () => import( "@/views/CaiGouGuanLi/CaiGouRuKu/Kf_POStockInBillList.vue" ), hidden: false, name: "POStockInBillList", path: "POStockInBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "采购入库单", }, component: () => import( "@/views/CaiGouGuanLi/CaiGouRuKu/Kf_POStockInBillEdit.vue" ), hidden: false, name: "POStockInBillEdit", path: "POStockInBillEdit", }, { meta: { icon: "build", link: null, noCache: false, title: "分布式调入单维护", }, component: () => import( "@/views/FbStepFoldinBillList/fbStepFoldinBillList.vue" ), hidden: false, name: "FbStepFoldinBillList", path: "FbStepFoldinBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "分布式调出单维护", }, component: () => import( "@/views/FbStepFoldOutBillList/fbStepFoldOutBillList.vue" ), hidden: false, name: "FbStepFoldOutBillList", path: "FbStepFoldOutBillList", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "采购退料单", }, hidden: false, name: "PostockInBack", path: "postockInBack", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "采购退料单维护", }, component: () => import( "@/views/purchase/postockInBack/Kf_POStockInBackBillList.vue" ), hidden: false, name: "Kf_POStockInBackBillList", path: "Kf_POStockInBackBillList", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "其他出库单维护", }, hidden: false, name: "OtherOutBill", path: "OtherOutBill", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "其他出库单列表", }, component: () => import("@/views/KCGL/OtherOutBill/Kf_OtherOutBillList.vue"), hidden: false, name: "OtherOutBillList", path: "OtherOutBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "其他出库单", }, component: () => import("@/views/KCGL/OtherOutBill/Kf_OtherOutBillEdit.vue"), hidden: false, name: "OtherOutBillEdit", path: "OtherOutBillEdit", }, ], }, ], }, { alwaysShow: true, component: "Layout", meta: { icon: "build", link: null, noCache: false, title: "生产管理", }, hidden: false, name: "ICMO", path: "/icmo", redirect: "noRedirect", children: [ { meta: { icon: "build", link: null, noCache: false, title: "生产订单", }, hidden: false, name: "ScIcmoBill", path: "scIcmoBill", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "生产订单列表", }, component: () => import("@/views/ICMO/ScICMOBillList.vue"), hidden: false, name: "ScICMOBillList", path: "scICMOBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "生产订单", }, component: () => import("@/views/ICMO/ScICMOBillEdit.vue"), hidden: false, name: "ScICMOBillEdit", path: "scICMOBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "生产入库维护", }, hidden: false, name: "ProductInBill", path: "ProductInBill", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "生产入库列表", }, component: () => import("@/views/ProductInBill/Kf_ProductInBillList.vue"), hidden: false, name: "ProductInBillList", path: "ProductInBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "生产入库单", }, component: () => import("@/views/ProductInBill/Kf_ProductInBillEdit.vue"), hidden: false, name: "ProductInBillEdit", path: "ProductInBillEdit", }, ], }, ], }, { alwaysShow: true, component: "Layout", meta: { icon: "build", link: null, noCache: false, title: "器具管理", }, hidden: false, name: "ScMould", path: "/scMould", redirect: "noRedirect", children: [ { meta: { icon: "build", link: null, noCache: false, title: "仓储管理", }, hidden: false, name: "Warehouse", path: "warehouse", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "器具领用出库单维护", }, component: () => import( "@/views/scMould/warehouse/Sc_MouldProdOutBillList" ), hidden: false, name: "Sc_MouldProdOutBillList", path: "Sc_MouldProdOutBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "器具领用出库单", }, component: () => import( "@/views/scMould/warehouse/Sc_MouldProdOutBillEdit" ), hidden: false, name: "Sc_MouldProdOutBillEdit", path: "Sc_MouldProdOutBillEdit", }, { meta: { icon: "build", link: null, noCache: false, title: "器具领用退库单维护", }, component: () => import( "@/views/scMould/warehouse/Sc_MouldProdBackBillList" ), hidden: false, name: "Sc_MouldProdBackBillList", path: "Sc_MouldProdBackBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "器具领用退库单", }, component: () => import( "@/views/scMould/warehouse/Sc_MouldProdBackBillEdit" ), hidden: false, name: "Sc_MouldProdBackBillEdit", path: "Sc_MouldProdBackBillEdit", }, { meta: { icon: "build", link: null, noCache: false, title: "器具直接调拨单维护", }, component: () => import( "@/views/scMould/warehouse/Sc_MouldProdMoveBillList" ), hidden: false, name: "Sc_MouldProdMoveBillList", path: "Sc_MouldProdMoveBillList", }, { meta: { icon: "build", link: null, noCache: false, title: "器具直接调拨单", }, component: () => import( "@/views/scMould/warehouse/Sc_MouldProdMoveBillEdit" ), hidden: false, name: "Sc_MouldProdMoveBillEdit", path: "Sc_MouldProdMoveBillEdit", }, ], }, { meta: { icon: "build", link: null, noCache: false, title: "基础建模", }, hidden: false, name: "BasicModeling", path: "basicModeling", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "器具主档", }, component: () => import("@/views/scMould/basicModeling/Gy_MouldFile.vue"), hidden: false, name: "Gy_MouldFile", path: "Gy_MouldFile", }, { meta: { icon: "build", link: null, noCache: false, title: "器具主档维护", }, component: () => import( "@/views/scMould/basicModeling/Gy_MouldFileList.vue" ), hidden: false, name: "Gy_MouldFileList", path: "Gy_MouldFileList", }, { meta: { icon: "build", link: null, noCache: false, title: "产品包装容器关联信息维护", }, component: () => import( "@/views/scMould/basicModeling/Gy_MaterialPackingRelationList.vue" ), hidden: false, name: "Gy_MaterialPackingRelationList", path: "Gy_MaterialPackingRelationList", }, ], }, ], }, { alwaysShow: true, component: "Layout", meta: { icon: "build", link: null, noCache: false, title: "系统管理", }, hidden: false, name: "System", path: "/system", redirect: "noRedirect", children: [ { meta: { icon: "build", link: null, noCache: false, title: "用户管理", }, hidden: false, name: "User", path: "user", redirect: "noRedirect", component: "Layout", children: [ { meta: { icon: "build", link: null, noCache: false, title: "用户列表", }, component: () => import("@/views/system/user/xtUserList.vue"), hidden: false, name: "XtUserList", path: "xtUserList", }, { meta: { icon: "build", link: null, noCache: false, title: "权限查询", }, component: () => import("@/views/system/user/xtUserRightQuery.vue"), hidden: true, name: "XtUserRightQuery", path: "xtUserRightQuery", }, ], }, ], }, ]; const sdata = JSON.parse(JSON.stringify(data)); const rdata = JSON.parse(JSON.stringify(data)); const sidebarRoutes = filterAsyncRouter(sdata); const rewriteRoutes = filterAsyncRouter(rdata, false, true); const asyncRoutes = filterDynamicRoutes(dynamicRoutes); rewriteRoutes.push({ path: "*", redirect: "/404", hidden: true }); router.addRoutes(asyncRoutes); commit("SET_ROUTES", rewriteRoutes); commit("SET_SIDEBAR_ROUTERS", constantRoutes.concat(sidebarRoutes)); commit("SET_DEFAULT_ROUTES", sidebarRoutes); commit("SET_TOPBAR_ROUTES", sidebarRoutes); resolve(rewriteRoutes); }); }, }, }; // 遍历后台传来的路由字符串,转换为组件对象 function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { return asyncRouterMap.filter((route) => { if (type && route.children) { route.children = filterChildren(route.children); } if (route.component) { // Layout ParentView 组件特殊处理 if (route.component === "Layout") { route.component = Layout; } else if (route.component === "ParentView") { route.component = ParentView; } else if (route.component === "InnerLink") { route.component = InnerLink; } else { route.component = loadView(route.component); } } if (route.children != null && route.children && route.children.length) { route.children = filterAsyncRouter(route.children, route, type); } else { delete route["children"]; delete route["redirect"]; } return true; }); } function filterChildren(childrenMap, lastRouter = false) { var children = []; childrenMap.forEach((el) => { el.path = lastRouter ? lastRouter.path + "/" + el.path : el.path; if (el.children && el.children.length && el.component === "ParentView") { children = children.concat(filterChildren(el.children, el)); } else { children.push(el); } }); return children; } // 动态路由遍历,验证是否具备权限 export function filterDynamicRoutes(routes) { const res = []; routes.forEach((route) => { if (route.permissions) { if (auth.hasPermiOr(route.permissions)) { res.push(route); } } else if (route.roles) { if (auth.hasRoleOr(route.roles)) { res.push(route); } } }); return res; } export const loadView = (view) => { if (process.env.NODE_ENV === "development") { return (resolve) => require([`@/views/${view}`], resolve); } else { // 使用 import 实现生产环境的路由懒加载 return () => import(`@/views/${view}`); } }; export default permission;