Skip to content

Commit

Permalink
fix(menu): make sure the menu is activated correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jun 29, 2021
1 parent 749ba5c commit cdb10cc
Show file tree
Hide file tree
Showing 6 changed files with 466 additions and 476 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- **Icon** 修复 SvgIcon 缺少部分样式的问题
- **LockScreen** 修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题
- 修复多个窗口同时打开页面时,`Token` 不会同步的问题
- **Menu** 修复路由映射模式下,单级菜单刷新不会激活

## 2.5.2(2021-06-27)

Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@logicflow/extension": "^0.5.0",
"@vueuse/core": "^5.0.3",
"@zxcvbn-ts/core": "^1.0.0-beta.0",
"ant-design-vue": "2.2.0-beta.6",
"ant-design-vue": "2.2.0-rc.1",
"axios": "^0.21.1",
"codemirror": "^5.62.0",
"cropperjs": "^1.5.12",
Expand All @@ -53,6 +53,7 @@
"pinia": "^2.0.0-beta.3",
"print-js": "^1.6.0",
"qrcode": "^1.4.4",
"resize-observer-polyfill": "^1.5.1",
"sortablejs": "^1.13.0",
"tinymce": "^5.8.2",
"vditor": "^3.8.5",
Expand All @@ -66,7 +67,7 @@
"devDependencies": {
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@iconify/json": "^1.1.362",
"@iconify/json": "^1.1.364",
"@purge-icons/generated": "^0.7.0",
"@types/codemirror": "^5.60.1",
"@types/crypto-js": "^4.0.1",
Expand All @@ -81,8 +82,8 @@
"@types/qrcode": "^1.4.0",
"@types/qs": "^6.9.6",
"@types/sortablejs": "^1.10.6",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"@vitejs/plugin-legacy": "^1.4.3",
"@vitejs/plugin-vue": "^1.2.4",
"@vitejs/plugin-vue-jsx": "^1.1.6",
Expand All @@ -105,15 +106,15 @@
"husky": "^6.0.0",
"inquirer": "^8.1.1",
"is-ci": "^3.0.0",
"jest": "^27.0.5",
"jest": "^27.0.6",
"less": "^4.1.1",
"lint-staged": "^11.0.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.3.5",
"prettier": "^2.3.2",
"pretty-quick": "^3.1.1",
"rimraf": "^3.0.2",
"rollup-plugin-visualizer": "5.5.0",
"rollup-plugin-visualizer": "5.5.1",
"stylelint": "^13.13.1",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^22.0.0",
Expand All @@ -122,7 +123,7 @@
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"typescript": "4.3.4",
"vite": "2.3.8",
"vite": "2.4.0-beta.2",
"vite-plugin-compression": "^0.2.5",
"vite-plugin-html": "^2.0.7",
"vite-plugin-imagemin": "^0.3.2",
Expand Down
3 changes: 1 addition & 2 deletions src/components/SimpleMenu/src/SimpleMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import type { MenuState } from './types';
import type { Menu as MenuType } from '/@/router/types';
import type { RouteLocationNormalizedLoaded } from 'vue-router';
import { defineComponent, computed, ref, unref, reactive, toRefs, watch } from 'vue';
import { useDesign } from '/@/hooks/web/useDesign';
import Menu from './components/Menu.vue';
import SimpleSubMenu from './SimpleSubMenu.vue';
import { listenerRouteChange } from '/@/logics/mitt/routeChange';
Expand Down Expand Up @@ -123,6 +121,7 @@
return;
}
const path = (route || unref(currentRoute)).path;
menuState.activeName = path;
setOpenKeys(path);
Expand Down
6 changes: 4 additions & 2 deletions src/router/helper/menuHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AppRouteModule } from '/@/router/types';
import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types';

import { findPath, treeMap } from '/@/utils/helper/treeHelper';
import { cloneDeep } from 'lodash-es';
import { isUrl } from '/@/utils/is';
Expand Down Expand Up @@ -36,11 +35,14 @@ export function transformMenuModule(menuModule: MenuModule): Menu {
return menuList[0];
}

export function transformRouteToMenu(routeModList: AppRouteModule[]) {
export function transformRouteToMenu(routeModList: AppRouteModule[], routerMapping = false) {
const cloneRouteModList = cloneDeep(routeModList);
const routeList: AppRouteRecordRaw[] = [];

cloneRouteModList.forEach((item) => {
if (routerMapping && item.meta.hideChildrenInMenu && typeof item.redirect === 'string') {
item.path = item.redirect;
}
if (item.meta?.single) {
const realItem = item?.children?.[0];
realItem && routeList.push(realItem);
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ export const usePermissionStore = defineStore({
case PermissionModeEnum.ROUTE_MAPPING:
routes = filter(asyncRoutes, routeFilter);
routes = routes.filter(routeFilter);
const menuList = transformRouteToMenu(asyncRoutes);
const menuList = transformRouteToMenu(asyncRoutes, true);
menuList.sort((a, b) => {
return (a.meta?.orderNo || 0) - (b.meta?.orderNo || 0);
});

this.setFrontMenuList(menuList);
// Convert multi-level routing to level 2 routing
routes = flatMultiLevelRoutes(routes);
Expand Down
Loading

0 comments on commit cdb10cc

Please sign in to comment.