@zat-design/sisyphus-react 4.6.5-beta.6 → 4.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/ProLayout/components/Layout/Menu/FoldMenu/index.js +8 -11
- package/es/ProLayout/components/Layout/Menu/NormalMenuSelection.d.ts +8 -0
- package/es/ProLayout/components/Layout/Menu/NormalMenuSelection.js +29 -0
- package/es/ProLayout/components/Layout/Menu/OpenMenu/index.js +20 -21
- package/es/ProLayout/components/Layout/Menu/index.d.ts +6 -2
- package/es/ProLayout/components/Layout/Menu/index.js +5 -2
- package/es/ProLayout/index.d.ts +2 -0
- package/es/ProLayout/index.js +2 -1
- package/es/ProLayout/utils/index.d.ts +0 -11
- package/es/ProLayout/utils/index.js +16 -100
- package/package.json +1 -1
|
@@ -2,36 +2,33 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { Popover, Tooltip } from "antd";
|
|
4
4
|
import classnames from "classnames";
|
|
5
|
-
import { Link as RouterLink
|
|
5
|
+
import { Link as RouterLink } from "react-router-dom";
|
|
6
6
|
import ProIcon from "../../../../../ProIcon";
|
|
7
7
|
import SideMenu from "../SideMenu";
|
|
8
8
|
import { LayoutContext } from "../../../../index";
|
|
9
|
-
import {
|
|
9
|
+
import { getUrlParams, getPathNameKey, findMenuItemByKey } from "../../../../utils";
|
|
10
10
|
const Link = RouterLink;
|
|
11
11
|
const FoldMenu = (props) => {
|
|
12
12
|
const { style, dataSource, onMenuClick } = props;
|
|
13
13
|
const { menus, iconfontUrl, notice, collapsed, headerHeight } = dataSource;
|
|
14
|
-
const
|
|
14
|
+
const pathNamePrefix = `/${window.location.pathname.split("/")[1]}`;
|
|
15
15
|
const noticeCls = classnames({
|
|
16
16
|
"pro-layout-menu-tooltip": true,
|
|
17
17
|
"pro-layout-menu-tooltip-has-notice": notice,
|
|
18
18
|
"pro-layout-menu-tooltip-nav-open": collapsed
|
|
19
19
|
});
|
|
20
|
-
const { selectedPath, onSelected } = useContext(LayoutContext) || {
|
|
20
|
+
const { selectedPath, onSelected, menuSelectedPath } = useContext(LayoutContext) || {
|
|
21
21
|
selectedPath: "",
|
|
22
22
|
onSelected: () => {
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
const currentKeyIdPath = resolveMenuKeyIdPath({
|
|
26
|
-
menus,
|
|
27
|
-
pathname: location.pathname,
|
|
28
|
-
search: location.search,
|
|
29
|
-
selectedPath
|
|
30
|
-
});
|
|
31
25
|
return /* @__PURE__ */ jsx("div", { className: "pro-layout-menu-fold", style: { ...style }, children: /* @__PURE__ */ jsx("ul", { className: "pro-layout-menu-fold-list", style: { ...style }, children: menus.filter((item) => !item.hideInMenu).map((item, index) => {
|
|
32
26
|
var _a;
|
|
33
27
|
const { id, url, name, icon, imgUrl, imgActiveUrl, children } = item;
|
|
34
28
|
const toPath = item.redirectUrl || item.url;
|
|
29
|
+
const selectedMenu = getUrlParams("activeMenu");
|
|
30
|
+
const pathToMatch = menuSelectedPath ?? (selectedPath || selectedMenu || window.location.pathname);
|
|
31
|
+
const currentKeyIdPath = pathToMatch ? getPathNameKey({ menus, pathName: pathToMatch }) || [] : [];
|
|
35
32
|
const cls = classnames({
|
|
36
33
|
active: currentKeyIdPath.includes(id)
|
|
37
34
|
});
|
|
@@ -41,7 +38,7 @@ const FoldMenu = (props) => {
|
|
|
41
38
|
"img",
|
|
42
39
|
{
|
|
43
40
|
className: "pro-layout-icon",
|
|
44
|
-
src:
|
|
41
|
+
src: pathNamePrefix === url ? imgActiveUrl || imgUrl : imgUrl,
|
|
45
42
|
alt: "icon"
|
|
46
43
|
}
|
|
47
44
|
) : /* @__PURE__ */ jsx(
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { MenusType } from '../../../propTypes';
|
|
3
|
+
/** 单页路由命中菜单时更新入口,未命中的详情页沿用最近入口。 */
|
|
4
|
+
declare const NormalMenuSelection: ({ menus, children }: {
|
|
5
|
+
menus: MenusType[];
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default NormalMenuSelection;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useEffect } from "react";
|
|
3
|
+
import { useLocation } from "react-router-dom";
|
|
4
|
+
import { LayoutContext } from "../../../index";
|
|
5
|
+
import { getIdsByPathName } from "../../../utils";
|
|
6
|
+
const NormalMenuSelection = ({ menus, children }) => {
|
|
7
|
+
const location = useLocation();
|
|
8
|
+
const context = useContext(LayoutContext);
|
|
9
|
+
const onSelected = context == null ? void 0 : context.onSelected;
|
|
10
|
+
const activeMenu = new URLSearchParams(location.search).get("activeMenu");
|
|
11
|
+
const routeMenuPath = activeMenu || (getIdsByPathName(menus, location.pathname).length ? location.pathname : "");
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (routeMenuPath)
|
|
14
|
+
onSelected == null ? void 0 : onSelected({ selectedPath: routeMenuPath });
|
|
15
|
+
}, [routeMenuPath, onSelected]);
|
|
16
|
+
if (!context)
|
|
17
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
LayoutContext.Provider,
|
|
20
|
+
{
|
|
21
|
+
value: { ...context, menuSelectedPath: routeMenuPath || context.selectedPath },
|
|
22
|
+
children
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
var NormalMenuSelection_default = NormalMenuSelection;
|
|
27
|
+
export {
|
|
28
|
+
NormalMenuSelection_default as default
|
|
29
|
+
};
|
|
@@ -4,14 +4,15 @@ import { Menu } from "antd";
|
|
|
4
4
|
import { useDeepCompareEffect, useSetState } from "ahooks";
|
|
5
5
|
import { CaretDownOutlined } from "@ant-design/icons";
|
|
6
6
|
import classnames from "classnames";
|
|
7
|
-
import { Link as RouterLink
|
|
7
|
+
import { Link as RouterLink } from "react-router-dom";
|
|
8
8
|
import cloneDeep from "lodash/cloneDeep";
|
|
9
9
|
import { LayoutContext } from "../../../../index";
|
|
10
|
-
import {
|
|
10
|
+
import { getIdsByPathName, findMenuItemByKey } from "../../../../utils";
|
|
11
11
|
import { canOpenAsTab } from "../../../TabsManager/utils";
|
|
12
12
|
import ProIcon from "../../../../../ProIcon";
|
|
13
13
|
const Link = RouterLink;
|
|
14
14
|
const OpenMenu = (props) => {
|
|
15
|
+
var _a;
|
|
15
16
|
const { className, dataSource, style, onMenuClick, textVisible = true } = props;
|
|
16
17
|
const { menus, sideMenu } = dataSource || {};
|
|
17
18
|
const linkRef = useRef(null);
|
|
@@ -20,7 +21,7 @@ const OpenMenu = (props) => {
|
|
|
20
21
|
openKeys: [],
|
|
21
22
|
router: ""
|
|
22
23
|
});
|
|
23
|
-
const
|
|
24
|
+
const query = new URLSearchParams(window.location.search);
|
|
24
25
|
const layoutContext = useContext(LayoutContext);
|
|
25
26
|
const layoutSelectedPath = layoutContext == null ? void 0 : layoutContext.selectedPath;
|
|
26
27
|
const layoutOnSelected = layoutContext == null ? void 0 : layoutContext.onSelected;
|
|
@@ -30,12 +31,8 @@ const OpenMenu = (props) => {
|
|
|
30
31
|
"pro-layout-menu-text-hidden": textVisible === false,
|
|
31
32
|
[`${className}`]: className
|
|
32
33
|
});
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
pathname: location.pathname,
|
|
36
|
-
search: location.search,
|
|
37
|
-
selectedPath: layoutSelectedPath
|
|
38
|
-
}).map((item) => String(item));
|
|
34
|
+
const preferredPath = (layoutContext == null ? void 0 : layoutContext.menuSelectedPath) ?? (query.get("activeMenu") || (layoutSelectedPath === "##EMPTY##" ? null : layoutSelectedPath) || window.location.pathname);
|
|
35
|
+
const selectKeyIdPath = preferredPath ? ((_a = getIdsByPathName(menus, preferredPath)) == null ? void 0 : _a.map((item) => String(item))) || [] : [];
|
|
39
36
|
const selectedRootKey = selectKeyIdPath[0];
|
|
40
37
|
const itemsTransform = useMemo(() => {
|
|
41
38
|
const result = cloneDeep(menus);
|
|
@@ -43,12 +40,9 @@ const OpenMenu = (props) => {
|
|
|
43
40
|
return [];
|
|
44
41
|
}
|
|
45
42
|
const menuDeep = (data) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
visibleItems.forEach((item) => {
|
|
50
|
-
var _a, _b;
|
|
51
|
-
const isFirstMenu = ((_a = item.keyIdPath) == null ? void 0 : _a.length) === 1 || sideMenu && ((_b = item.keyIdPath) == null ? void 0 : _b.length) === 2;
|
|
43
|
+
data.forEach((item) => {
|
|
44
|
+
var _a2, _b, _c;
|
|
45
|
+
const isFirstMenu = ((_a2 = item.keyIdPath) == null ? void 0 : _a2.length) === 1 || sideMenu && ((_b = item.keyIdPath) == null ? void 0 : _b.length) === 2;
|
|
52
46
|
item.label = /* @__PURE__ */ jsxs(
|
|
53
47
|
"div",
|
|
54
48
|
{
|
|
@@ -83,16 +77,21 @@ const OpenMenu = (props) => {
|
|
|
83
77
|
).forEach((_keyItem) => {
|
|
84
78
|
delete item[_keyItem];
|
|
85
79
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
if (Array.isArray(item == null ? void 0 : item.children) && ((_c = item == null ? void 0 : item.children) == null ? void 0 : _c.length) > 0) {
|
|
81
|
+
const _item = item == null ? void 0 : item.children[0];
|
|
82
|
+
if ((_item == null ? void 0 : _item.hideInMenu) || ["TAB", "QUERY", "BUTTON"].includes(_item == null ? void 0 : _item.type)) {
|
|
83
|
+
delete item.children;
|
|
84
|
+
} else {
|
|
85
|
+
menuDeep(item.children);
|
|
86
|
+
}
|
|
89
87
|
} else {
|
|
90
88
|
delete item.children;
|
|
91
89
|
}
|
|
92
90
|
});
|
|
93
|
-
return
|
|
91
|
+
return data;
|
|
94
92
|
};
|
|
95
|
-
|
|
93
|
+
menuDeep(result);
|
|
94
|
+
return result;
|
|
96
95
|
}, [dataSource, selectedRootKey]);
|
|
97
96
|
useDeepCompareEffect(() => {
|
|
98
97
|
if (Array.isArray(selectKeyIdPath)) {
|
|
@@ -141,7 +140,7 @@ const OpenMenu = (props) => {
|
|
|
141
140
|
}
|
|
142
141
|
if (menuItem && canOpenAsTab(menuItem) && shouldActivate) {
|
|
143
142
|
setState({
|
|
144
|
-
selectedKeys:
|
|
143
|
+
selectedKeys: keyPath,
|
|
145
144
|
router: menuRouter
|
|
146
145
|
});
|
|
147
146
|
layoutOnSelected == null ? void 0 : layoutOnSelected({
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type { FC } from 'react';
|
|
1
|
+
import type { FC, ReactNode } from 'react';
|
|
2
2
|
import type { ProLayoutType } from '../../../propTypes';
|
|
3
|
-
|
|
3
|
+
type MenuProps = Pick<ProLayoutType, 'mode' | 'headerHeight' | 'dataSource' | 'iconfontUrl' | 'collapsed' | 'notice' | 'pure' | 'sideMenuFooterRender' | 'onMenuClick'> & {
|
|
4
|
+
sideMenuHeaderRender?: ReactNode;
|
|
5
|
+
onToggle?: () => void;
|
|
6
|
+
};
|
|
7
|
+
declare const Menu: FC<MenuProps>;
|
|
4
8
|
export default Menu;
|
|
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState, useCallback } from "react";
|
|
|
3
3
|
import classnames from "classnames";
|
|
4
4
|
import OpenMenu from "./OpenMenu";
|
|
5
5
|
import FoldMenu from "./FoldMenu";
|
|
6
|
+
import NormalMenuSelection from "./NormalMenuSelection";
|
|
6
7
|
const iconfontCache = /* @__PURE__ */ new Set();
|
|
7
8
|
const loadIconfontScript = (url) => {
|
|
8
9
|
if (!url || iconfontCache.has(url))
|
|
@@ -33,7 +34,8 @@ const Menu = (props) => {
|
|
|
33
34
|
pure,
|
|
34
35
|
sideMenuFooterRender,
|
|
35
36
|
sideMenuHeaderRender,
|
|
36
|
-
onMenuClick
|
|
37
|
+
onMenuClick,
|
|
38
|
+
mode
|
|
37
39
|
} = props || {};
|
|
38
40
|
let menus = [];
|
|
39
41
|
const menuRef = useRef(null);
|
|
@@ -110,7 +112,7 @@ const Menu = (props) => {
|
|
|
110
112
|
if ((pure == null ? void 0 : pure.leftMenu) || pure === true) {
|
|
111
113
|
return /* @__PURE__ */ jsx(Fragment, {});
|
|
112
114
|
}
|
|
113
|
-
|
|
115
|
+
const menuDom = /* @__PURE__ */ jsxs(
|
|
114
116
|
"div",
|
|
115
117
|
{
|
|
116
118
|
ref: menuRef,
|
|
@@ -170,6 +172,7 @@ const Menu = (props) => {
|
|
|
170
172
|
]
|
|
171
173
|
}
|
|
172
174
|
);
|
|
175
|
+
return mode === "normal" ? /* @__PURE__ */ jsx(NormalMenuSelection, { menus, children: menuDom }) : menuDom;
|
|
173
176
|
};
|
|
174
177
|
var Menu_default = Menu;
|
|
175
178
|
export {
|
package/es/ProLayout/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { useProLayoutTabs } from './components/TabsManager/hooks/useProLayoutTab
|
|
|
4
4
|
import { useActiveTab } from './components/TabsManager/hooks/useActiveTab';
|
|
5
5
|
interface LayoutContextValue {
|
|
6
6
|
selectedPath: string;
|
|
7
|
+
/** normal 模式根据当前路由解析后的菜单路径,空字符串表示没有选中项。 */
|
|
8
|
+
menuSelectedPath?: string;
|
|
7
9
|
onSelected: (params: Partial<ProLayoutStatesType>) => void;
|
|
8
10
|
target: '_blank' | '_parent' | '_self' | '_top';
|
|
9
11
|
}
|
package/es/ProLayout/index.js
CHANGED
|
@@ -129,7 +129,7 @@ const ProLayout = (props) => {
|
|
|
129
129
|
const userData = transformMenus(dataSource, pathPrefix);
|
|
130
130
|
const menuData = Array.isArray(userData) ? userData : (userData == null ? void 0 : userData.menus) || [];
|
|
131
131
|
setState({ menus: menuData });
|
|
132
|
-
}, [dataSource
|
|
132
|
+
}, [dataSource]);
|
|
133
133
|
const menuDataSource = useMemo(() => {
|
|
134
134
|
if (Array.isArray(menus) && menus.length > 0) {
|
|
135
135
|
return { menus };
|
|
@@ -238,6 +238,7 @@ const ProLayout = (props) => {
|
|
|
238
238
|
noticeRef: setNoticeElRef
|
|
239
239
|
};
|
|
240
240
|
const menuProps = {
|
|
241
|
+
mode,
|
|
241
242
|
headerHeight,
|
|
242
243
|
dataSource: Array.isArray(menus) ? { menus } : menus,
|
|
243
244
|
iconfontUrl,
|
|
@@ -6,16 +6,6 @@ import type { MenusType } from '../propTypes';
|
|
|
6
6
|
* @return result
|
|
7
7
|
*/
|
|
8
8
|
export declare const getIdsByPathName: (menus: any[], activeMenu?: string) => number[];
|
|
9
|
-
interface ResolveMenuKeyIdPathOptions {
|
|
10
|
-
menus: any[];
|
|
11
|
-
pathname: string;
|
|
12
|
-
search?: string;
|
|
13
|
-
selectedPath?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 统一解析菜单激活路径:显式 activeMenu 优先,其次匹配真实路由,最后回退上次选择。
|
|
17
|
-
*/
|
|
18
|
-
export declare const resolveMenuKeyIdPath: ({ menus, pathname, search, selectedPath, }: ResolveMenuKeyIdPathOptions) => number[];
|
|
19
9
|
/**
|
|
20
10
|
* 转换菜单数据源评价keyUrlPath与keyIdPath
|
|
21
11
|
* @param menuData 菜单数据源
|
|
@@ -51,4 +41,3 @@ export declare const getPathNameKey: ({ menus, pathName }: {
|
|
|
51
41
|
* @returns 找到的菜单项数据或null
|
|
52
42
|
*/
|
|
53
43
|
export declare const findMenuItemByKey: (menus: any[], key: string) => any;
|
|
54
|
-
export {};
|
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
import isPlainObject from "lodash/isPlainObject";
|
|
2
|
-
const addPathPrefix = (pathPrefix, route) => {
|
|
3
|
-
if (!route || !pathPrefix || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(route))
|
|
4
|
-
return route || "";
|
|
5
|
-
const normalizedPrefix = `/${pathPrefix.replace(/^\/+|\/+$/g, "")}`;
|
|
6
|
-
if (normalizedPrefix === "/")
|
|
7
|
-
return route;
|
|
8
|
-
const match = route.match(/^([^?#]*)(.*)$/);
|
|
9
|
-
const pathname = (match == null ? void 0 : match[1]) || "";
|
|
10
|
-
const suffix = (match == null ? void 0 : match[2]) || "";
|
|
11
|
-
const normalizedPathname = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
12
|
-
const alreadyPrefixed = normalizedPathname === normalizedPrefix || normalizedPathname.startsWith(`${normalizedPrefix}/`);
|
|
13
|
-
return `${alreadyPrefixed ? normalizedPathname : `${normalizedPrefix}${normalizedPathname}`}${suffix}`;
|
|
14
|
-
};
|
|
15
2
|
const updateBestMatch = (pathName, itemUrl, itemRedirectUrl, keyIdPath, bestMatch) => {
|
|
16
|
-
|
|
17
|
-
if (!candidate)
|
|
18
|
-
return false;
|
|
19
|
-
const normalizedCandidate = candidate.length > 1 ? candidate.replace(/\/+$/, "") : candidate;
|
|
20
|
-
if (pathName === normalizedCandidate)
|
|
21
|
-
return true;
|
|
22
|
-
const boundary = pathName.charAt(normalizedCandidate.length);
|
|
23
|
-
return pathName.startsWith(normalizedCandidate) && ["/", "?", "#"].includes(boundary);
|
|
24
|
-
};
|
|
25
|
-
if (isSameOrNestedPath(itemUrl)) {
|
|
3
|
+
if (itemUrl && pathName.includes(itemUrl)) {
|
|
26
4
|
const urlLength = itemUrl.length;
|
|
27
5
|
if (!bestMatch || urlLength > bestMatch.urlLength) {
|
|
28
6
|
return { keyIdPath, urlLength };
|
|
29
7
|
}
|
|
30
8
|
}
|
|
31
|
-
if (
|
|
9
|
+
if (itemRedirectUrl && pathName.includes(itemRedirectUrl)) {
|
|
32
10
|
const urlLength = itemRedirectUrl.length;
|
|
33
11
|
if (!bestMatch || urlLength > bestMatch.urlLength) {
|
|
34
12
|
return { keyIdPath, urlLength };
|
|
@@ -36,39 +14,17 @@ const updateBestMatch = (pathName, itemUrl, itemRedirectUrl, keyIdPath, bestMatc
|
|
|
36
14
|
}
|
|
37
15
|
return bestMatch;
|
|
38
16
|
};
|
|
39
|
-
const getExactMenuKeyIdPath = (menus, pathname) => {
|
|
40
|
-
const normalizePathname = (value) => {
|
|
41
|
-
if (!value)
|
|
42
|
-
return "";
|
|
43
|
-
const path = value.split(/[?#]/)[0];
|
|
44
|
-
return path.length > 1 ? path.replace(/\/+$/, "") : path;
|
|
45
|
-
};
|
|
46
|
-
const targetPathname = normalizePathname(pathname);
|
|
47
|
-
for (const item of menus || []) {
|
|
48
|
-
const routes = [item == null ? void 0 : item.redirectUrl, item == null ? void 0 : item.router, item == null ? void 0 : item.url].map(normalizePathname);
|
|
49
|
-
if (targetPathname && routes.includes(targetPathname)) {
|
|
50
|
-
return item.keyIdPath || [];
|
|
51
|
-
}
|
|
52
|
-
if (Array.isArray(item == null ? void 0 : item.children) && item.children.length) {
|
|
53
|
-
const childPath = getExactMenuKeyIdPath(item.children, pathname);
|
|
54
|
-
if (childPath.length)
|
|
55
|
-
return childPath;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return [];
|
|
59
|
-
};
|
|
60
17
|
const getIdsByPathName = (menus, activeMenu) => {
|
|
61
18
|
const _pathName = activeMenu || window.location.pathname;
|
|
62
19
|
let result;
|
|
63
20
|
let bestMatch = null;
|
|
64
21
|
const menuDeep = (menuDeepItem) => {
|
|
65
|
-
var _a, _b
|
|
22
|
+
var _a, _b;
|
|
66
23
|
for (let i = 0; i <= menuDeepItem.length - 1; i++) {
|
|
67
24
|
const item = menuDeepItem[i];
|
|
68
25
|
const itemUrl = ((_a = item == null ? void 0 : item.url) == null ? void 0 : _a.split("?")[0]) || "";
|
|
69
26
|
const itemRedirectUrl = ((_b = item == null ? void 0 : item.redirectUrl) == null ? void 0 : _b.split("?")[0]) || "";
|
|
70
|
-
|
|
71
|
-
if ((item == null ? void 0 : item.url) === _pathName || item.redirectUrl === _pathName || item.router === _pathName) {
|
|
27
|
+
if ((item == null ? void 0 : item.url) === _pathName || item.redirectUrl === _pathName) {
|
|
72
28
|
result = item.keyIdPath;
|
|
73
29
|
return;
|
|
74
30
|
}
|
|
@@ -81,40 +37,13 @@ const getIdsByPathName = (menus, activeMenu) => {
|
|
|
81
37
|
continue;
|
|
82
38
|
}
|
|
83
39
|
bestMatch = updateBestMatch(_pathName, itemUrl, itemRedirectUrl, item.keyIdPath, bestMatch);
|
|
84
|
-
bestMatch = updateBestMatch(_pathName, itemRouter, "", item.keyIdPath, bestMatch);
|
|
85
40
|
}
|
|
86
41
|
};
|
|
87
42
|
menuDeep(menus);
|
|
88
43
|
return result || (bestMatch == null ? void 0 : bestMatch.keyIdPath) || [];
|
|
89
44
|
};
|
|
90
|
-
const resolveMenuKeyIdPath = ({
|
|
91
|
-
menus,
|
|
92
|
-
pathname,
|
|
93
|
-
search = "",
|
|
94
|
-
selectedPath
|
|
95
|
-
}) => {
|
|
96
|
-
if (selectedPath === "##EMPTY##")
|
|
97
|
-
return [];
|
|
98
|
-
const activeMenu = new URLSearchParams(search).get("activeMenu");
|
|
99
|
-
const activeMenuPath = activeMenu ? getIdsByPathName(menus, activeMenu) : [];
|
|
100
|
-
if (activeMenuPath.length)
|
|
101
|
-
return activeMenuPath;
|
|
102
|
-
const exactRoutePath = getExactMenuKeyIdPath(menus, pathname);
|
|
103
|
-
if (exactRoutePath.length)
|
|
104
|
-
return exactRoutePath;
|
|
105
|
-
const nestedRoutePath = getIdsByPathName(menus, pathname);
|
|
106
|
-
if (nestedRoutePath.length)
|
|
107
|
-
return nestedRoutePath;
|
|
108
|
-
return selectedPath ? getIdsByPathName(menus, selectedPath) : [];
|
|
109
|
-
};
|
|
110
45
|
const transformMenu = (menuData, pathPrefix) => {
|
|
111
|
-
const
|
|
112
|
-
...item,
|
|
113
|
-
keyUrlPath: Array.isArray(item.keyUrlPath) ? [...item.keyUrlPath] : item.keyUrlPath,
|
|
114
|
-
keyIdPath: Array.isArray(item.keyIdPath) ? [...item.keyIdPath] : item.keyIdPath,
|
|
115
|
-
children: Array.isArray(item.children) ? cloneMenuTree(item.children) : item.children
|
|
116
|
-
}));
|
|
117
|
-
const data = cloneMenuTree(menuData);
|
|
46
|
+
const data = [...menuData];
|
|
118
47
|
const menuDeep = (menuDeepItem) => {
|
|
119
48
|
var _a, _b, _c;
|
|
120
49
|
if (!Array.isArray(menuDeepItem) || !menuDeepItem.length) {
|
|
@@ -122,26 +51,18 @@ const transformMenu = (menuData, pathPrefix) => {
|
|
|
122
51
|
}
|
|
123
52
|
for (let i = menuDeepItem.length - 1; i >= 0; i -= 1) {
|
|
124
53
|
const item = menuDeepItem[i];
|
|
125
|
-
item.code = item.code
|
|
126
|
-
item.url =
|
|
127
|
-
item.redirectUrl =
|
|
128
|
-
if (item.router)
|
|
129
|
-
item.router = addPathPrefix(pathPrefix, item.router);
|
|
130
|
-
const itemRoute = item.redirectUrl || item.url || item.router;
|
|
54
|
+
item.code = item.code || item.id;
|
|
55
|
+
item.url = `${pathPrefix}${item.url}`;
|
|
56
|
+
item.redirectUrl = (item == null ? void 0 : item.redirectUrl) ? `${pathPrefix}${item.redirectUrl}` : "";
|
|
131
57
|
if ((_a = item == null ? void 0 : item.keyUrlPath) == null ? void 0 : _a.length) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
item.keyUrlPath = item.keyUrlPath.filter(
|
|
135
|
-
(route, index, routes) => routes.indexOf(route) === index
|
|
136
|
-
);
|
|
58
|
+
item.keyUrlPath.push(item.redirectUrl || item.url);
|
|
59
|
+
item.keyUrlPath = [...new Set(item.keyUrlPath)];
|
|
137
60
|
} else {
|
|
138
|
-
item.keyUrlPath =
|
|
61
|
+
item.keyUrlPath = [item.redirectUrl || item.url];
|
|
139
62
|
}
|
|
140
63
|
if ((_b = item == null ? void 0 : item.keyIdPath) == null ? void 0 : _b.length) {
|
|
141
64
|
item.keyIdPath.push(item.id);
|
|
142
|
-
item.keyIdPath = item.keyIdPath
|
|
143
|
-
(id, index, ids) => ids.indexOf(id) === index
|
|
144
|
-
);
|
|
65
|
+
item.keyIdPath = [...new Set(item.keyIdPath)];
|
|
145
66
|
} else {
|
|
146
67
|
item.keyIdPath = [item.id];
|
|
147
68
|
}
|
|
@@ -164,10 +85,8 @@ const transformMenus = (data, pathPrefix) => {
|
|
|
164
85
|
if (!Array.isArray(data == null ? void 0 : data.menus)) {
|
|
165
86
|
return [];
|
|
166
87
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
menus: transformMenu(data.menus, pathPrefix)
|
|
170
|
-
};
|
|
88
|
+
data.menus = transformMenu(data.menus, pathPrefix);
|
|
89
|
+
return data;
|
|
171
90
|
}
|
|
172
91
|
if (Array.isArray(data)) {
|
|
173
92
|
return transformMenu(data, pathPrefix);
|
|
@@ -197,7 +116,7 @@ const getPathNameKey = ({ menus, pathName }) => {
|
|
|
197
116
|
let result;
|
|
198
117
|
let bestMatch = null;
|
|
199
118
|
const menuDeep = (menuDeepItem) => {
|
|
200
|
-
var _a, _b
|
|
119
|
+
var _a, _b;
|
|
201
120
|
if (!Array.isArray(menuDeepItem) || !menuDeepItem.length) {
|
|
202
121
|
return;
|
|
203
122
|
}
|
|
@@ -208,8 +127,7 @@ const getPathNameKey = ({ menus, pathName }) => {
|
|
|
208
127
|
}
|
|
209
128
|
const itemUrl = ((_a = item == null ? void 0 : item.url) == null ? void 0 : _a.split("?")[0]) || "";
|
|
210
129
|
const itemRedirectUrl = ((_b = item == null ? void 0 : item.redirectUrl) == null ? void 0 : _b.split("?")[0]) || "";
|
|
211
|
-
|
|
212
|
-
if ((item == null ? void 0 : item.url) === pathName || (item == null ? void 0 : item.redirectUrl) === pathName || (item == null ? void 0 : item.router) === pathName) {
|
|
130
|
+
if ((item == null ? void 0 : item.url) === pathName || (item == null ? void 0 : item.redirectUrl) === pathName) {
|
|
213
131
|
result = item.keyIdPath;
|
|
214
132
|
return;
|
|
215
133
|
}
|
|
@@ -222,7 +140,6 @@ const getPathNameKey = ({ menus, pathName }) => {
|
|
|
222
140
|
continue;
|
|
223
141
|
}
|
|
224
142
|
bestMatch = updateBestMatch(pathName, itemUrl, itemRedirectUrl, item.keyIdPath, bestMatch);
|
|
225
|
-
bestMatch = updateBestMatch(pathName, itemRouter, "", item.keyIdPath, bestMatch);
|
|
226
143
|
}
|
|
227
144
|
};
|
|
228
145
|
menuDeep(menus);
|
|
@@ -246,7 +163,6 @@ export {
|
|
|
246
163
|
getIdsByPathName,
|
|
247
164
|
getPathNameKey,
|
|
248
165
|
getUrlParams,
|
|
249
|
-
resolveMenuKeyIdPath,
|
|
250
166
|
transformMenu,
|
|
251
167
|
transformMenus
|
|
252
168
|
};
|