diff --git a/src/router/full-routers.js b/src/router/full-routers.js index 47f5463..479e566 100644 --- a/src/router/full-routers.js +++ b/src/router/full-routers.js @@ -32,7 +32,7 @@ export default { parentName: null, name: "运营管理", url: "operation-management", - perms: "", + perms: "operation-management", type: 0, elIcon: "el-icon-s-help", orderNum: 0, @@ -44,7 +44,7 @@ export default { parentName: null, name: "市场列表", url: "operation-management/market-list/index", - perms: "", + perms: "operation-management:market-list:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -57,7 +57,7 @@ export default { parentName: null, name: "店铺列表", url: "operation-management/shop-list/index", - perms: "", + perms: "operation-management:shop-list:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -70,7 +70,7 @@ export default { parentName: null, name: "品牌店铺", url: "operation-management/brand-store/index", - perms: "", + perms: "operation-management:brand-store:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -83,7 +83,7 @@ export default { parentName: null, name: "品牌市场", url: "operation-management/brand-market/index", - perms: "", + perms: "operation-management:brand-market:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -96,7 +96,7 @@ export default { parentName: null, name: "分销商列表", url: "operation-management/distributor/index", - perms: "", + perms: "operation-management:distributor:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -109,7 +109,7 @@ export default { parentName: null, name: "商品管理", url: "operation-management/commodity/index", - perms: "", + perms: "operation-management:commodity:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, @@ -122,7 +122,7 @@ export default { parentName: null, name: "总订单管理", url: "operation-management/total-order/index", - perms: "", + perms: "operation-management:total-order:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, @@ -136,7 +136,7 @@ export default { parentName: null, name: "订单管理", url: "operation-management/order/index", - perms: "", + perms: "operation-management:order:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, @@ -149,7 +149,7 @@ export default { parentName: null, name: "订单管理", url: "operation-management/brand-order/index", - perms: "", + perms: "operation-management:brand-order:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, @@ -162,7 +162,7 @@ export default { parentName: null, name: "轮播图管理", url: "operation-management/banner/index", - perms: "", + perms: "operation-management:banner:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, @@ -175,7 +175,7 @@ export default { parentName: null, name: "购物须知管理", url: "operation-management/paynotice/index", - perms: "", + perms: "operation-management:paynotice:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, @@ -188,39 +188,39 @@ export default { parentName: null, name: "公告管理", url: "operation-management/notice/index", - perms: "", + perms: "operation-management:notice:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, open: null, list: [] }, - { - menuId: getUUID(), - parentId: 0, - parentName: null, - name: "账号管理", - url: "operation-management/accountNumber/index", - perms: "", - type: 1, - elIcon: "el-icon-menu", - orderNum: 0, - open: null, - list: [] - }, - { - menuId: getUUID(), - parentId: 0, - parentName: null, - name: "角色管理", - url: "operation-management/role/index", - perms: "", - type: 1, - elIcon: "el-icon-user", - orderNum: 0, - open: null, - list: [] - } + // { + // menuId: getUUID(), + // parentId: 0, + // parentName: null, + // name: "账号管理", + // url: "operation-management/accountNumber/index", + // perms: "operation-management:accountNumber:index", + // type: 1, + // elIcon: "el-icon-menu", + // orderNum: 0, + // open: null, + // list: [] + // }, + // { + // menuId: getUUID(), + // parentId: 0, + // parentName: null, + // name: "角色管理", + // url: "operation-management/role/index", + // perms: "operation-management:role:index", + // type: 1, + // elIcon: "el-icon-user", + // orderNum: 0, + // open: null, + // list: [] + // } ] }, { @@ -229,7 +229,7 @@ export default { parentName: null, name: "数据中心", url: "datacenter", - perms: "", + perms: "datacenter", type: 0, elIcon: "el-icon-tickets", orderNum: 0, @@ -241,7 +241,7 @@ export default { parentName: null, name: "客户分析", url: "datacenter/customer-analysis/index", - perms: "", + perms: "datacenter:customer-analysis:index", type: 1, elIcon: "el-icon-user", orderNum: 0, @@ -254,7 +254,7 @@ export default { parentName: null, name: "商品分析", url: "datacenter/product-analysis/index", - perms: "", + perms: "datacenter:product-analysis:index", type: 1, elIcon: "el-icon-data-analysis", orderNum: 0, @@ -267,7 +267,7 @@ export default { parentName: null, name: "订单统计分析", url: "datacenter/order-analysis/index", - perms: "", + perms: "datacenter:order-analysis:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -282,7 +282,7 @@ export default { parentName: null, name: "银行卡管理", url: "bank-card/index", - perms: "", + perms: "bank-card:index", type: 0, elIcon: "el-icon-picture-outline", orderNum: 0, @@ -296,7 +296,7 @@ export default { parentName: null, name: "品牌管理", url: "brand", - perms: "", + perms: "brand", type: 0, elIcon: "el-icon-money", orderNum: 0, @@ -308,7 +308,7 @@ export default { parentName: null, name: "品牌管理", url: "brand/config/index", - perms: "", + perms: "brand:config:index", type: 1, elIcon: "el-icon-postcard", orderNum: 0, @@ -323,7 +323,7 @@ export default { parentName: null, name: "优惠卷营销工具管理", url: "coupon/index", - perms: "", + perms: "coupon:index", type: 0, elIcon: "el-icon-document-remove", orderNum: 0, @@ -336,7 +336,7 @@ export default { parentName: null, name: "预售营销工具管理", url: "presale", - perms: "", + perms: "presale", type: 0, elIcon: "el-icon-data-analysis", orderNum: 0, @@ -348,7 +348,7 @@ export default { parentName: null, name: "预售商品", url: "presale/products/index", - perms: "", + perms: "presale:products:index", type: 1, elIcon: "el-icon-postcard", orderNum: 0, @@ -361,7 +361,7 @@ export default { parentName: null, name: "预售订单", url: "presale/order/index", - perms: "", + perms: "presale:order:index", type: 1, elIcon: "el-icon-postcard", orderNum: 0, @@ -376,7 +376,7 @@ export default { parentName: null, name: "等级明细", url: "marketing-level/detail", - perms: "", + perms: "marketing-level:detail", type: 1, elIcon: "el-icon-user", orderNum: 0, @@ -390,7 +390,7 @@ export default { parentName: null, name: "会员营销工具管理", url: "marketing", - perms: "", + perms: "marketing", type: 0, elIcon: "el-icon-tickets", orderNum: 0, @@ -402,7 +402,7 @@ export default { parentName: null, name: "等级设置", url: "marketing/level/index", - perms: "", + perms: "marketing:level:index", type: 1, elIcon: "el-icon-user", orderNum: 0, @@ -416,7 +416,7 @@ export default { parentName: null, name: "会员列表", url: "marketing/user/index", - perms: "", + perms: "marketing:user:index", type: 1, elIcon: "el-icon-data-analysis", orderNum: 0, @@ -429,7 +429,7 @@ export default { // parentName: null, // name: "积分设置", // url: "marketing/points-setting/index", - // perms: "", + // perms: "marketing:points-setting:index", // type: 1, // elIcon: "el-icon-shopping-cart-full", // orderNum: 0, @@ -442,7 +442,7 @@ export default { parentName: null, name: "积分商品", url: "marketing/points-mall/index", - perms: "", + perms: "marketing:points-mall:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -455,7 +455,7 @@ export default { parentName: null, name: "积分订单", url: "marketing/points-order/index", - perms: "", + perms: "marketing:points-order:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -470,7 +470,7 @@ export default { parentName: null, name: "代理商", url: "agent", - perms: "", + perms: "agent", type: 0, elIcon: "el-icon-tickets", orderNum: 0, @@ -482,7 +482,7 @@ export default { parentName: null, name: "数据面板", url: "agent/data-panel/index", - perms: "", + perms: "agent:data-panel:index", type: 1, elIcon: "el-icon-user", orderNum: 0, @@ -495,7 +495,7 @@ export default { parentName: null, name: "品牌管理", url: "agent/brand/index", - perms: "", + perms: "agent:brand:index", type: 1, elIcon: "el-icon-data-analysis", orderNum: 0, @@ -508,7 +508,7 @@ export default { parentName: null, name: "报表", url: "agent/report-form/index", - perms: "", + perms: "agent:report-form:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -521,7 +521,7 @@ export default { parentName: null, name: "权限管理", url: "agent/jurisdiction/index", - perms: "", + perms: "agent:jurisdiction:index", type: 1, elIcon: "el-icon-shopping-cart-full", orderNum: 0, @@ -549,7 +549,7 @@ export default { parentName: null, name: "我的钱包", url: "wallet/index", - perms: "", + perms: "wallet:index", type: 1, elIcon: "el-icon-menu", orderNum: 0, @@ -564,7 +564,7 @@ export default { parentName: null, name: "运费管理", url: "ogistics-fare", - perms: "", + perms: "ogistics-fare", type: 0, elIcon: "el-icon-money", orderNum: 0, @@ -576,7 +576,7 @@ export default { parentName: null, name: "运费模板", url: "logistics-fare/logistics-template/index", - perms: "", + perms: "logistics-fare:logistics-template:index", type: 1, elIcon: "el-icon-postcard", orderNum: 0, @@ -591,7 +591,7 @@ export default { // parentName: null, // name: "会员管理", // url: "member-management", - // perms: "", + // perms: "member-management", // type: 0, // elIcon: "el-icon-user-solid", // orderNum: 0, @@ -603,7 +603,7 @@ export default { // parentName: null, // name: "等级设置", // url: "member-management/level-setting/index", - // perms: "", + // perms: "member-management:level-setting:index", // type: 1, // elIcon: "el-icon-star-on", // orderNum: 0, @@ -618,7 +618,7 @@ export default { // parentName: null, // name: "会员列表", // url: "member-list", - // perms: "", + // perms: "member-list", // type: 0, // elIcon: "el-icon-user", // orderNum: 0, @@ -630,7 +630,7 @@ export default { // parentName: null, // name: "会员列表", // url: "member-list/member-list/index", - // perms: "", + // perms: "member-list:member-list:index", // type: 1, // elIcon: "el-icon-user", // orderNum: 0, diff --git a/src/router/index.js b/src/router/index.js index 518cd77..b54c206 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -8,7 +8,7 @@ import Vue from "vue"; import Router from "vue-router"; import http from "@/utils/httpRequest"; import { isURL } from "@/utils/validate"; -import { clearLoginInfo, getMenu } from "@/utils"; +import { clearLoginInfo } from "@/utils"; import FULL_ROUTERS from "./full-routers"; import $api from "@/api/index.js"; import store from "@/store"; @@ -25,20 +25,20 @@ const globalRoutes = [ path: "/404", component: _import("common/404"), name: "404", - meta: { title: "404未找到" } + meta: { title: "404未找到" }, }, { path: "/login", component: _import("common/login"), name: "login", - meta: { title: "登录" } + meta: { title: "登录" }, }, { path: "/test-member-detail", component: _import("test-member-detail"), name: "test-member-detail", - meta: { title: "会员详情样式测试" } - } + meta: { title: "会员详情样式测试" }, + }, //test用,会员管理 ]; @@ -58,20 +58,20 @@ const mainRoutes = { path: "/home", component: _import("common/home"), name: "home", - meta: { title: "首页" } + meta: { title: "首页" }, }, { path: "/theme", component: _import("common/theme"), name: "theme", - meta: { title: "主题" } + meta: { title: "主题" }, }, { path: "/demo-echarts", component: _import("demo/echarts"), name: "demo-echarts", - meta: { title: "demo-echarts", isTab: true } - } + meta: { title: "demo-echarts", isTab: true }, + }, ], beforeEnter(to, from, next) { let token = Vue.cookie.get("token"); @@ -80,7 +80,7 @@ const mainRoutes = { next({ name: "login" }); } next(); - } + }, }; const router = new Router({ @@ -88,7 +88,7 @@ const router = new Router({ // mode:"history", scrollBehavior: () => ({ y: 0 }), isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由 - routes: globalRoutes.concat(mainRoutes) + routes: globalRoutes.concat(mainRoutes), }); router.beforeEach((to, from, next) => { @@ -104,47 +104,53 @@ router.beforeEach((to, from, next) => { } else { let loadingInstance = Loading.service({ text: "正在初始化中...", - background: "rgba(255,255,255,0.7)" + background: "rgba(255,255,255,0.7)", }); $api .getUserInfo() .then(async ({ data }) => { - let permissionsData = getMenu(data.data.role, data.data.manageMode); - if (permissionsData === null) { - let res = await $api.role.getRoleList({ roleId: data.data.role }); - permissionsData = res.data.data; - } - const filterTreeData = (data, permissions) => { - console.log(data); + // 从后端获取的权限码 (只包含叶子节点) + const permissionCodes = data.data.permissions?.permissionCodes || []; - // return data; //临时性返回所有菜单方便调试 - return data.reduce((filtered, node) => { - // 如果节点的权限在权限数组中 - if (permissions.includes(node.url)) { - // 递归过滤子节点 - const list = filterTreeData(node.list || [], permissions); - // 创建一个新的节点,包含过滤后的子节点 - filtered.push({ - ...node, - list - }); + const filterTreeData = (menuData, permissions) => { + const result = []; + menuData.forEach((node) => { + // 检查当前节点是否为叶子节点 + const isLeaf = !node.list || node.list.length === 0; + + if (isLeaf) { + // 如果是叶子节点,检查其权限是否存在于权限码中 + if (permissions.includes(node.perms)) { + result.push({ ...node }); + } + } else { + // 如果是父节点,递归过滤其子节点 + const filteredChildren = filterTreeData(node.list, permissions); + // 如果过滤后的子节点列表不为空,则保留该父节点 + if (filteredChildren.length > 0) { + result.push({ + ...node, + list: filteredChildren, + }); + } } - return filtered; - }, []); + }); + return result; }; + console.log(data, "用户信息"); sessionStorage.setItem("role", JSON.stringify(data.data.role)); if (data.data.markets?.length > 0) { // 存在多个市场 $api.mer_admin .storeList({ marketId: data.data.markets[0].marketId }) - .then(res => { + .then((res) => { store.commit("userData/setState", { isMerchant: true, marketList: data.data.markets, storeList: res.data.data, marketId: data.data.markets[0].marketId, - shopId: res.data.data[0].shopId + shopId: res.data.data[0].shopId, }); }); console.log(data.data.markets); @@ -156,7 +162,7 @@ router.beforeEach((to, from, next) => { marketList: [], storeList: [], marketId: data.data.marketId, - shopId: data.data.shopId + shopId: data.data.shopId, }); } else { store.commit("userData/setState", { @@ -164,7 +170,7 @@ router.beforeEach((to, from, next) => { marketList: [], storeList: [], marketId: -1, - shopId: data.data.shopId + shopId: data.data.shopId, }); } } else { @@ -174,28 +180,22 @@ router.beforeEach((to, from, next) => { marketList: [], storeList: [], marketId: "", - shopId: "" + shopId: "", }); } sessionStorage.setItem("userInfo", JSON.stringify(data.data)); sessionStorage.setItem( "permissions", - JSON.stringify(data.data.permissions || "[]") + JSON.stringify(permissionCodes || "[]") ); - //添加全量菜单,根据权限进行过滤 - // let _menu = filterTreeData( - // FULL_ROUTERS.menuList, - // data.data.permissions - // ); - console.log(permissionsData, "11111111111111111111111111111"); - let _menu = filterTreeData(FULL_ROUTERS.menuList, permissionsData); + let _menu = filterTreeData(FULL_ROUTERS.menuList, permissionCodes); fnAddDynamicMenuRoutes(_menu); sessionStorage.setItem("menuList", JSON.stringify(_menu)); router.options.isAddDynamicMenuRoutes = true; next({ ...to, replace: true }); }) - .catch(e => { + .catch((e) => { sessionStorage.setItem("menuList", "[]"); sessionStorage.setItem("permissions", "[]"); console.log( @@ -208,24 +208,6 @@ router.beforeEach((to, from, next) => { .finally(() => { loadingInstance.close(); }); - // http({ - // url: '/sys/menu/nav', - // method: 'get', - // params: http.adornParams() - // }).then(({ data }) => { - // if (data && data.code === 0) { - // // router.options.isAddDynamicMenuRoutes = true - // // sessionStorage.setItem('permissions', JSON.stringify(data.permissions || '[]')) - // next({ ...to, replace: true }) - // } else { - // // sessionStorage.setItem('menuList', '[]') - // // sessionStorage.setItem('permissions', '[]') - // next() - // } - // }).catch((e) => { - // console.log(`%c${e} 请求菜单列表和权限失败,跳转至登录页!!`, 'color:blue') - // router.push({ name: 'login' }) - // }) } }); @@ -270,8 +252,8 @@ function fnAddDynamicMenuRoutes(menuList = [], routes = []) { isDynamic: true, isTab: true, iframeUrl: "", - isMicroApp: menuList[i].isMicroApp - } + isMicroApp: menuList[i].isMicroApp, + }, }; // url以http[s]://开头, 通过iframe展示,或者启用microApp框架 if (isURL(menuList[i].url)) { diff --git a/src/utils/index.js b/src/utils/index.js index 679177e..068c008 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -136,159 +136,7 @@ function doHandleMonth(month) { } return m; } -/** - * 权限 - * @param {*} min - * @param {*} max - */ -export function getMenu(role, manageMode) { - if (role == "ROLE_MANAGER") { - return [ - "operation-management", - "operation-management/commodity/index", - "operation-management/order/index", - "operation-management/banner/index", - "operation-management/notice/index", - "operation-management/paynotice/index", - "operation-management/role/index", - "datacenter", - "datacenter/customer-analysis/index", - "datacenter/product-analysis/index", - "datacenter/order-analysis/index", - "coupon/index", - "presale", - "presale/products/index", - "presale/order/index", - "marketing", - "marketing/level/index", - "marketing-level/detail", - "marketing/user/index", - "marketing/points-setting/index", - "marketing/points-mall/index", - "marketing/points-order/index", - // "member-management", - // "member-management/level-setting/index", - // "member-list", - // "member-list/member-list/index", - "local-course/resources", - "wallet/index", - "ogistics-fare", - "logistics-fare/logistics-template/index", - "bank-card/index", - "operation-management/total-order/index", - "operation-management/accountNumber/index" - ]; - } else if (role == "ROLE_MERCHANT") { - if (manageMode === 1) { - return [ - "operation-management", - "operation-management/commodity/index", - "operation-management/order/index", - "operation-management/banner/index", - "operation-management/notice/index", - "operation-management/paynotice/index", - "operation-management/role/index", - "datacenter", - "datacenter/customer-analysis/index", - "datacenter/product-analysis/index", - "datacenter/order-analysis/index", - "coupon/index", - "presale", - "presale/products/index", - "presale/order/index", - "marketing", - "marketing/points-mall/index", - "marketing/points-order/index", - // "member-management", - // "member-management/level-setting/index", - // "member-list", - // "member-list/member-list/index", - "local-course/resources", - "wallet/index", - "ogistics-fare", - "logistics-fare/logistics-template/index", - "bank-card/index", - "operation-management/total-order/index", - "operation-management/accountNumber/index" - ]; - } else { - return [ - "operation-management", - "operation-management/commodity/index", - "operation-management/order/index", - "operation-management/banner/index", - "operation-management/notice/index", - "operation-management/paynotice/index", - "operation-management/role/index", - "datacenter", - "datacenter/customer-analysis/index", - "datacenter/product-analysis/index", - "datacenter/order-analysis/index", - "coupon/index", - "presale", - "presale/products/index", - "presale/order/index", - "marketing", - "marketing/level/index", - "marketing-level/detail", - "marketing/user/index", - "marketing/points-setting/index", - "marketing/points-mall/index", - "marketing/points-order/index", - // "member-management", - // "member-management/level-setting/index", - // "member-list", - // "member-list/member-list/index", - "local-course/resources", - "wallet/index", - "ogistics-fare", - "logistics-fare/logistics-template/index", - "bank-card/index", - "operation-management/total-order/index", - "operation-management/accountNumber/index" - ]; - } - } else if (role == "ROLE_BRAND_MANAGER") { - return [ - "operation-management", - // "operation-management/shop-list/index", - "operation-management/brand-market/index", - "operation-management/brand-store/index", - "operation-management/distributor/index", - // "operation-management/order/index", - "operation-management/brand-order/index", - // "operation-management/role/index", - "datacenter", - "datacenter/customer-analysis/index", - "datacenter/product-analysis/index", - "datacenter/order-analysis/index", - "brand", - "brand/config/index", - "local-course/resources", - "wallet/index" - // "operation-management/accountNumber/index", - ]; - } else if (role == "ROLE_AGENT") { - return [ - "operation-management", - "operation-management/shop-list/index", - "operation-management/market-list/index", - // "operation-management/order/index", - "operation-management/brand-order/index", - // "operation-management/role/index", - "datacenter", - "datacenter/customer-analysis/index", - "datacenter/product-analysis/index", - "datacenter/order-analysis/index", - "local-course/resources", - "wallet/index" - // "operation-management/accountNumber/index", - ]; - } else { - return null; - } -} export function isNumberStr(str) { return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str); -} +} \ No newline at end of file