From b36a765fdb452803c22fcac23b9d53217cd46db5 Mon Sep 17 00:00:00 2001 From: hooray <304327508@qq.com> Date: Thu, 11 Nov 2021 09:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=9F=E6=88=90=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 9 ++------- src/store/modules/menu.js | 10 ++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index acb05305..523a68ba 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -150,14 +150,9 @@ router.beforeEach(async(to, from, next) => { } else { let accessRoutes = [] if (!store.state.settings.enableBackendReturnRoute) { - accessRoutes = await store.dispatch('menu/generateRoutesAtFront', { - asyncRoutes, - currentPath: to.path - }) + accessRoutes = await store.dispatch('menu/generateRoutesAtFront', asyncRoutes) } else { - accessRoutes = await store.dispatch('menu/generateRoutesAtBack', { - currentPath: to.path - }) + accessRoutes = await store.dispatch('menu/generateRoutesAtBack') } accessRoutes.push(lastRoute) let removeRoutes = [] diff --git a/src/store/modules/menu.js b/src/store/modules/menu.js index 3e2b57e6..4b6a143b 100644 --- a/src/store/modules/menu.js +++ b/src/store/modules/menu.js @@ -169,19 +169,18 @@ const getters = { const actions = { // 根据权限动态生成路由(前端生成) - generateRoutesAtFront({ rootState, dispatch, commit }, data) { + generateRoutesAtFront({ rootState, dispatch, commit }, asyncRoutes) { // eslint-disable-next-line no-async-promise-executor return new Promise(async resolve => { let accessedRoutes // 如果权限功能开启,则需要对路由数据进行筛选过滤 if (rootState.settings.enablePermission) { const permissions = await dispatch('user/getPermissions', null, { root: true }) - accessedRoutes = filterAsyncRoutes(data.asyncRoutes, permissions) + accessedRoutes = filterAsyncRoutes(asyncRoutes, permissions) } else { - accessedRoutes = deepClone(data.asyncRoutes) + accessedRoutes = deepClone(asyncRoutes) } commit('setRoutes', accessedRoutes) - commit('setHeaderActived', data.currentPath) let routes = [] accessedRoutes.map(item => { routes.push(...item.children) @@ -200,7 +199,7 @@ const actions = { }) }, // 生成路由(后端获取) - generateRoutesAtBack({ rootState, dispatch, commit }, data) { + generateRoutesAtBack({ rootState, dispatch, commit }) { return new Promise(resolve => { api.get('route/list', { baseURL: '/mock/' @@ -215,7 +214,6 @@ const actions = { accessedRoutes = deepClone(asyncRoutes) } commit('setRoutes', accessedRoutes) - commit('setHeaderActived', data.currentPath) let routes = [] accessedRoutes.map(item => { routes.push(...item.children)