@yueglobal/ui 1.0.3 → 1.0.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/package.json +1 -1
- package/yue-page-footer/index.less +15 -0
- package/yue-page-header/first-menus/index.d.ts +1 -0
- package/yue-page-header/first-menus/index.js +31 -14
- package/yue-page-header/first-menus/index.less +60 -7
- package/yue-page-header/helper.d.ts +12 -1
- package/yue-page-header/helper.js +42 -9
- package/yue-page-header/index.js +2 -1
- package/yue-page-header/index.less +1 -0
- package/yue-page-header/second-menus/index.js +57 -11
package/package.json
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
.yue-page-footer {
|
|
2
2
|
background-color: #f4f7fc;
|
|
3
|
+
position: relative;
|
|
4
|
+
|
|
5
|
+
&:before {
|
|
6
|
+
content: '';
|
|
7
|
+
position: absolute;
|
|
8
|
+
top: 0;
|
|
9
|
+
left: 0;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 3px;
|
|
12
|
+
background: linear-gradient(
|
|
13
|
+
90deg,
|
|
14
|
+
rgba(23, 241, 161, 0.4),
|
|
15
|
+
rgba(26, 75, 255, 0.3)
|
|
16
|
+
);
|
|
17
|
+
}
|
|
3
18
|
|
|
4
19
|
* {
|
|
5
20
|
box-sizing: border-box;
|
|
@@ -9,20 +9,25 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
9
9
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
11
|
import { ConfigProvider, Menu } from 'antd';
|
|
12
|
-
import React, { memo, useEffect, useRef, useState } from 'react';
|
|
12
|
+
import React, { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
13
13
|
import { deepClone, firstMenuList, mainHost, setSubMenuPopupStyle } from "../helper";
|
|
14
14
|
import "./index.less";
|
|
15
15
|
var Index = function Index(_ref) {
|
|
16
|
-
var moduleData = _ref.moduleData
|
|
16
|
+
var moduleData = _ref.moduleData,
|
|
17
|
+
hasSecondMenu = _ref.hasSecondMenu;
|
|
17
18
|
var _useState = useState(),
|
|
18
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19
20
|
selectedKeys = _useState2[0],
|
|
20
21
|
setSelectedKeys = _useState2[1];
|
|
21
|
-
var
|
|
22
|
-
var _useState3 = useState(deepClone(firstMenuList)),
|
|
22
|
+
var _useState3 = useState(false),
|
|
23
23
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
open = _useState4[0],
|
|
25
|
+
setOpen = _useState4[1];
|
|
26
|
+
var menuRef = useRef(null);
|
|
27
|
+
var _useState5 = useState(deepClone(firstMenuList)),
|
|
28
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
29
|
+
menuList = _useState6[0],
|
|
30
|
+
setMenuList = _useState6[1];
|
|
26
31
|
useEffect(function () {
|
|
27
32
|
if (!!(menuList !== null && menuList !== void 0 && menuList.length) && moduleData) {
|
|
28
33
|
var key = moduleData.key;
|
|
@@ -108,24 +113,35 @@ var Index = function Index(_ref) {
|
|
|
108
113
|
window.location.href = key;
|
|
109
114
|
}
|
|
110
115
|
};
|
|
116
|
+
var previousKeyRef = useRef();
|
|
111
117
|
var onSubMenuOpen = function onSubMenuOpen(key) {
|
|
112
|
-
if (!menuRef.current) {
|
|
118
|
+
if (!menuRef.current || previousKeyRef.current === key) {
|
|
113
119
|
return false;
|
|
114
120
|
}
|
|
121
|
+
previousKeyRef.current = key;
|
|
115
122
|
var index = menuList.findIndex(function (m) {
|
|
116
123
|
return m.key === key;
|
|
117
124
|
});
|
|
118
125
|
if (index === -1) {
|
|
119
126
|
return false;
|
|
120
127
|
}
|
|
121
|
-
setSubMenuPopupStyle(menuRef.current, index);
|
|
128
|
+
setSubMenuPopupStyle(menuRef.current, index, true);
|
|
122
129
|
};
|
|
130
|
+
var menuClassName = useMemo(function () {
|
|
131
|
+
var res = ['yue-page-header-first-menu'];
|
|
132
|
+
if (!hasSecondMenu) {
|
|
133
|
+
res.push('single');
|
|
134
|
+
} else if (open) {
|
|
135
|
+
res.push('open');
|
|
136
|
+
}
|
|
137
|
+
return res.join(' ');
|
|
138
|
+
}, [open, hasSecondMenu]);
|
|
123
139
|
return /*#__PURE__*/React.createElement(ConfigProvider, {
|
|
124
140
|
theme: {
|
|
125
141
|
components: {
|
|
126
142
|
Menu: {
|
|
127
|
-
activeBarHeight:
|
|
128
|
-
itemPaddingInline:
|
|
143
|
+
activeBarHeight: 14,
|
|
144
|
+
itemPaddingInline: 4,
|
|
129
145
|
itemColor: '#000',
|
|
130
146
|
dropdownWidth: '100%',
|
|
131
147
|
horizontalLineHeight: '30px'
|
|
@@ -136,15 +152,16 @@ var Index = function Index(_ref) {
|
|
|
136
152
|
ref: menuRef,
|
|
137
153
|
items: menuList,
|
|
138
154
|
mode: "horizontal",
|
|
139
|
-
rootClassName:
|
|
155
|
+
rootClassName: menuClassName,
|
|
140
156
|
onSelect: onItem,
|
|
141
157
|
onOpenChange: function onOpenChange(val) {
|
|
142
158
|
if (!!(val !== null && val !== void 0 && val.length)) {
|
|
143
|
-
onSubMenuOpen(val[
|
|
159
|
+
onSubMenuOpen(val[val.length - 1]);
|
|
144
160
|
}
|
|
161
|
+
setOpen(!!val.length);
|
|
145
162
|
},
|
|
146
|
-
selectedKeys: selectedKeys
|
|
147
|
-
|
|
163
|
+
selectedKeys: selectedKeys,
|
|
164
|
+
subMenuCloseDelay: 1.5
|
|
148
165
|
}));
|
|
149
166
|
};
|
|
150
167
|
export default /*#__PURE__*/memo(Index);
|
|
@@ -28,21 +28,66 @@
|
|
|
28
28
|
justify-content: center;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
.ant-menu-title-content {
|
|
32
|
+
height: 38px;
|
|
33
|
+
line-height: 36px;
|
|
34
|
+
border-radius: 20px;
|
|
35
|
+
padding-inline: 16px;
|
|
36
|
+
min-width: 80px;
|
|
37
|
+
text-align: center;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.ant-menu-submenu-active,
|
|
41
|
+
.ant-menu-item-active {
|
|
42
|
+
.ant-menu-title-content {
|
|
43
|
+
background: linear-gradient(
|
|
44
|
+
90deg,
|
|
45
|
+
rgba(23, 241, 161, 0.25),
|
|
46
|
+
rgba(26, 75, 255, 0.25)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.ant-menu-submenu-selected,
|
|
31
52
|
.ant-menu-item-selected {
|
|
32
|
-
|
|
53
|
+
.ant-menu-title-content {
|
|
54
|
+
color: #fff;
|
|
55
|
+
background: linear-gradient(90deg, #17f1a1, #1a4bff);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
33
58
|
|
|
59
|
+
.ant-menu-item::after {
|
|
60
|
+
content: none;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.ant-menu-submenu {
|
|
34
64
|
&::after {
|
|
35
|
-
|
|
36
|
-
|
|
65
|
+
width: 0;
|
|
66
|
+
height: 0;
|
|
67
|
+
left: 50%;
|
|
68
|
+
transform: translateX(-50%);
|
|
69
|
+
border: 14px solid transparent;
|
|
70
|
+
border-top-width: 0;
|
|
71
|
+
transition: border-bottom-width 0.2s ease-in-out;
|
|
37
72
|
}
|
|
38
73
|
}
|
|
39
74
|
|
|
40
|
-
.ant-menu-submenu-
|
|
75
|
+
.ant-menu-submenu-open.ant-menu-submenu-active::after {
|
|
76
|
+
border-bottom-color: rgba(4, 41, 131, 80%) !important;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.ant-menu-submenu-selected:first-child {
|
|
41
80
|
&::after {
|
|
42
|
-
|
|
81
|
+
border-bottom-color: #17c8b8;
|
|
43
82
|
}
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&.single,
|
|
86
|
+
&.open {
|
|
87
|
+
.ant-menu-submenu-selected:first-child {
|
|
88
|
+
&::after {
|
|
89
|
+
border-bottom-color: transparent;
|
|
90
|
+
}
|
|
46
91
|
}
|
|
47
92
|
}
|
|
48
93
|
}
|
|
@@ -117,3 +162,11 @@
|
|
|
117
162
|
}
|
|
118
163
|
}
|
|
119
164
|
}
|
|
165
|
+
|
|
166
|
+
.yue-first-selected-arrow {
|
|
167
|
+
position: absolute;
|
|
168
|
+
bottom: 0;
|
|
169
|
+
left: 50px;
|
|
170
|
+
z-index: 1;
|
|
171
|
+
background: linear-gradient(90deg, #17f1a1, #1a4bff);
|
|
172
|
+
}
|
|
@@ -18,6 +18,11 @@ export declare const mainHost = "https://www.yueglobal.com";
|
|
|
18
18
|
* 一级菜单(主菜单)
|
|
19
19
|
*/
|
|
20
20
|
export declare const firstMenuList: YueMenuItem[];
|
|
21
|
+
/**
|
|
22
|
+
* 是首页菜单里的
|
|
23
|
+
* @param key
|
|
24
|
+
*/
|
|
25
|
+
export declare function isHomeChildRoute(key: string): boolean;
|
|
21
26
|
/**
|
|
22
27
|
* 将树结构转换为一维数组
|
|
23
28
|
* @param data
|
|
@@ -25,6 +30,11 @@ export declare const firstMenuList: YueMenuItem[];
|
|
|
25
30
|
export declare function flattenTreeList<T extends {
|
|
26
31
|
children?: T[];
|
|
27
32
|
}>(data: T[]): T[];
|
|
33
|
+
/**
|
|
34
|
+
* 则根据 key 的长度进行降序排序
|
|
35
|
+
* @param list
|
|
36
|
+
*/
|
|
37
|
+
export declare function sortListByKey(list: any[]): any[];
|
|
28
38
|
/**
|
|
29
39
|
* 将 firstMenuList 转换为一维数组并根据 key 长度排序
|
|
30
40
|
* @param isSort 是否进行排序
|
|
@@ -76,5 +86,6 @@ export declare function deepClone<T>(obj: T): T;
|
|
|
76
86
|
* 设置子菜单弹出层的样式
|
|
77
87
|
* @param menuRef - 菜单实例
|
|
78
88
|
* @param index - 子菜单索引
|
|
89
|
+
* @param zIndex - 是否重设 zIndex
|
|
79
90
|
*/
|
|
80
|
-
export declare function setSubMenuPopupStyle(menuRef: MenuRef, index: number): false | undefined;
|
|
91
|
+
export declare function setSubMenuPopupStyle(menuRef: MenuRef, index: number, zIndex?: boolean): false | undefined;
|
|
@@ -46,7 +46,7 @@ export var firstMenuList = [{
|
|
|
46
46
|
icon: /*#__PURE__*/React.createElement(LawIcon, null)
|
|
47
47
|
}, {
|
|
48
48
|
key: "".concat(mainHost, "/ktms-web/"),
|
|
49
|
-
label: '
|
|
49
|
+
label: '数智关税',
|
|
50
50
|
icon: /*#__PURE__*/React.createElement(TaxationIcon, null)
|
|
51
51
|
}, {
|
|
52
52
|
key: "".concat(mainHost, "/hwc/"),
|
|
@@ -86,6 +86,21 @@ export var firstMenuList = [{
|
|
|
86
86
|
label: '关于我们'
|
|
87
87
|
}];
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* 是首页菜单里的
|
|
91
|
+
* @param key
|
|
92
|
+
*/
|
|
93
|
+
export function isHomeChildRoute(key) {
|
|
94
|
+
var _homeRoute$children;
|
|
95
|
+
var homeRoute = firstMenuList[0];
|
|
96
|
+
if (homeRoute.key === key) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return !!((_homeRoute$children = homeRoute.children) !== null && _homeRoute$children !== void 0 && _homeRoute$children.find(function (c) {
|
|
100
|
+
return c.key === key;
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
|
|
89
104
|
/**
|
|
90
105
|
* 将树结构转换为一维数组
|
|
91
106
|
* @param data
|
|
@@ -114,6 +129,16 @@ export function flattenTreeList(data) {
|
|
|
114
129
|
return flatten(data);
|
|
115
130
|
}
|
|
116
131
|
|
|
132
|
+
/**
|
|
133
|
+
* 则根据 key 的长度进行降序排序
|
|
134
|
+
* @param list
|
|
135
|
+
*/
|
|
136
|
+
export function sortListByKey(list) {
|
|
137
|
+
return list.sort(function (a, b) {
|
|
138
|
+
return b.key.length - a.key.length;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
117
142
|
/**
|
|
118
143
|
* 将 firstMenuList 转换为一维数组并根据 key 长度排序
|
|
119
144
|
* @param isSort 是否进行排序
|
|
@@ -125,9 +150,7 @@ export function flattenMenuList(isSort) {
|
|
|
125
150
|
|
|
126
151
|
// 如果需要排序,则根据 key 的长度进行降序排序
|
|
127
152
|
if (isSort) {
|
|
128
|
-
return flattenedList
|
|
129
|
-
return b.key.length - a.key.length;
|
|
130
|
-
});
|
|
153
|
+
return sortListByKey(flattenedList);
|
|
131
154
|
}
|
|
132
155
|
return flattenedList;
|
|
133
156
|
}
|
|
@@ -341,7 +364,8 @@ export function deepClone(obj) {
|
|
|
341
364
|
}
|
|
342
365
|
return clonedObj;
|
|
343
366
|
}
|
|
344
|
-
|
|
367
|
+
var popupZIndex = 2000;
|
|
368
|
+
function _setPopupStyle(uuid, left, zIndex) {
|
|
345
369
|
var popupUL = window.document.getElementById(uuid);
|
|
346
370
|
if (popupUL) {
|
|
347
371
|
var contentWidth = 0;
|
|
@@ -355,9 +379,17 @@ function _setPopupStyle(uuid, left) {
|
|
|
355
379
|
popupUL.style.paddingLeft = "unset";
|
|
356
380
|
popupUL.style.justifyContent = 'center';
|
|
357
381
|
} else {
|
|
358
|
-
popupUL.style.paddingLeft = "".concat(left -
|
|
382
|
+
popupUL.style.paddingLeft = "".concat(left - 4, "px");
|
|
359
383
|
popupUL.style.justifyContent = 'unset';
|
|
360
384
|
}
|
|
385
|
+
if (zIndex) {
|
|
386
|
+
var _popupUL$parentElemen, _rootEle$tagName;
|
|
387
|
+
var rootEle = (_popupUL$parentElemen = popupUL.parentElement) === null || _popupUL$parentElemen === void 0 ? void 0 : _popupUL$parentElemen.parentElement;
|
|
388
|
+
if (rootEle && ((_rootEle$tagName = rootEle.tagName) === null || _rootEle$tagName === void 0 ? void 0 : _rootEle$tagName.toLowerCase()) !== 'body') {
|
|
389
|
+
rootEle.style.position = 'relative';
|
|
390
|
+
rootEle.style.zIndex = ++popupZIndex + '';
|
|
391
|
+
}
|
|
392
|
+
}
|
|
361
393
|
return true;
|
|
362
394
|
}
|
|
363
395
|
return false;
|
|
@@ -367,8 +399,9 @@ function _setPopupStyle(uuid, left) {
|
|
|
367
399
|
* 设置子菜单弹出层的样式
|
|
368
400
|
* @param menuRef - 菜单实例
|
|
369
401
|
* @param index - 子菜单索引
|
|
402
|
+
* @param zIndex - 是否重设 zIndex
|
|
370
403
|
*/
|
|
371
|
-
export function setSubMenuPopupStyle(menuRef, index) {
|
|
404
|
+
export function setSubMenuPopupStyle(menuRef, index, zIndex) {
|
|
372
405
|
var _menuRef$menu;
|
|
373
406
|
var li = menuRef === null || menuRef === void 0 || (_menuRef$menu = menuRef.menu) === null || _menuRef$menu === void 0 || (_menuRef$menu = _menuRef$menu.list) === null || _menuRef$menu === void 0 || (_menuRef$menu = _menuRef$menu.children) === null || _menuRef$menu === void 0 ? void 0 : _menuRef$menu.item(index);
|
|
374
407
|
if (!li) {
|
|
@@ -385,11 +418,11 @@ export function setSubMenuPopupStyle(menuRef, index) {
|
|
|
385
418
|
var _li$getBoundingClient = li.getBoundingClientRect(),
|
|
386
419
|
left = _li$getBoundingClient.left;
|
|
387
420
|
setTimeout(function () {
|
|
388
|
-
var success = _setPopupStyle(uuid, left);
|
|
421
|
+
var success = _setPopupStyle(uuid, left, zIndex);
|
|
389
422
|
if (!success) {
|
|
390
423
|
setTimeout(function () {
|
|
391
424
|
// 重新执行一次
|
|
392
|
-
_setPopupStyle(uuid, left);
|
|
425
|
+
_setPopupStyle(uuid, left, zIndex);
|
|
393
426
|
}, 100);
|
|
394
427
|
}
|
|
395
428
|
}, 100, uuid, left);
|
package/yue-page-header/index.js
CHANGED
|
@@ -101,7 +101,8 @@ var Index = function Index(_ref) {
|
|
|
101
101
|
})), /*#__PURE__*/React.createElement("div", {
|
|
102
102
|
className: "menus-bar"
|
|
103
103
|
}, /*#__PURE__*/React.createElement(FirstMenus, {
|
|
104
|
-
moduleData: moduleData
|
|
104
|
+
moduleData: moduleData,
|
|
105
|
+
hasSecondMenu: hasSecondMenu
|
|
105
106
|
})), /*#__PURE__*/React.createElement(RightContent, {
|
|
106
107
|
content: rightContent,
|
|
107
108
|
onLocaleChange: onLocaleChange
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
8
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
9
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -8,7 +14,7 @@ import { ComputerIcon } from "../../components/svg-icon";
|
|
|
8
14
|
import { ConfigProvider, Menu } from 'antd';
|
|
9
15
|
import React, { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
16
|
import Breadcrumb from "../breadcrumb";
|
|
11
|
-
import { flattenTreeList, setSubMenuPopupStyle } from "../helper";
|
|
17
|
+
import { flattenTreeList, setSubMenuPopupStyle, sortListByKey } from "../helper";
|
|
12
18
|
import "./index.less";
|
|
13
19
|
var Index = function Index(_ref) {
|
|
14
20
|
var width = _ref.width,
|
|
@@ -23,7 +29,12 @@ var Index = function Index(_ref) {
|
|
|
23
29
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24
30
|
selectedKeys = _useState2[0],
|
|
25
31
|
setSelectedKeys = _useState2[1];
|
|
32
|
+
var _useState3 = useState(false),
|
|
33
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
+
isLoaded = _useState4[0],
|
|
35
|
+
setIsLoaded = _useState4[1];
|
|
26
36
|
var menuRef = useRef(null);
|
|
37
|
+
var menuListRef = useRef([]);
|
|
27
38
|
|
|
28
39
|
// 弹出层的布局,默认是 vertical
|
|
29
40
|
var popupLayout = useMemo(function () {
|
|
@@ -32,16 +43,51 @@ var Index = function Index(_ref) {
|
|
|
32
43
|
}
|
|
33
44
|
return 'vertical';
|
|
34
45
|
}, [subMenuLayout]);
|
|
46
|
+
var mergeMenuItems = useMemo(function () {
|
|
47
|
+
return menuItems === null || menuItems === void 0 ? void 0 : menuItems.map(function (m) {
|
|
48
|
+
var _m$children;
|
|
49
|
+
var item = _objectSpread({}, m);
|
|
50
|
+
if ((_m$children = m.children) !== null && _m$children !== void 0 && _m$children.length) {
|
|
51
|
+
item.onTitleClick = function (_ref2) {
|
|
52
|
+
var key = _ref2.key;
|
|
53
|
+
if (item.key === key) {
|
|
54
|
+
onRouteChange === null || onRouteChange === void 0 || onRouteChange({
|
|
55
|
+
key: key,
|
|
56
|
+
label: item.label
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return item;
|
|
62
|
+
});
|
|
63
|
+
}, [menuItems]);
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
if (menuItems !== null && menuItems !== void 0 && menuItems.length) {
|
|
66
|
+
setIsLoaded(true);
|
|
67
|
+
}
|
|
68
|
+
menuListRef.current = sortListByKey(flattenTreeList(menuItems !== null && menuItems !== void 0 ? menuItems : []));
|
|
69
|
+
}, [menuItems]);
|
|
35
70
|
useEffect(function () {
|
|
36
|
-
if (pathname)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
71
|
+
if (pathname) {
|
|
72
|
+
var _menuListRef$current;
|
|
73
|
+
var key = pathname;
|
|
74
|
+
if ((_menuListRef$current = menuListRef.current) !== null && _menuListRef$current !== void 0 && _menuListRef$current.length) {
|
|
75
|
+
var cur = menuListRef.current.find(function (m) {
|
|
76
|
+
return m.key && pathname.startsWith(m.key);
|
|
77
|
+
});
|
|
78
|
+
if (cur) {
|
|
79
|
+
key = cur.key;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
setSelectedKeys([key]);
|
|
83
|
+
}
|
|
84
|
+
}, [pathname, isLoaded]);
|
|
85
|
+
var onMenuClick = function onMenuClick(_ref3) {
|
|
86
|
+
var key = _ref3.key;
|
|
87
|
+
setSelectedKeys([key]);
|
|
42
88
|
if (onRouteChange && menuItems !== null && menuItems !== void 0 && menuItems.length) {
|
|
43
|
-
var
|
|
44
|
-
var current =
|
|
89
|
+
var _menuListRef$current2;
|
|
90
|
+
var current = (_menuListRef$current2 = menuListRef.current) === null || _menuListRef$current2 === void 0 ? void 0 : _menuListRef$current2.find(function (m) {
|
|
45
91
|
return m.key === key;
|
|
46
92
|
});
|
|
47
93
|
var value = {
|
|
@@ -106,10 +152,10 @@ var Index = function Index(_ref) {
|
|
|
106
152
|
className: "menus"
|
|
107
153
|
}, /*#__PURE__*/React.createElement(Menu, {
|
|
108
154
|
ref: menuRef,
|
|
109
|
-
items:
|
|
155
|
+
items: mergeMenuItems,
|
|
110
156
|
mode: "horizontal",
|
|
111
157
|
rootClassName: ['yue-second-menu-bar', "yue-second-menu-".concat(popupLayout)].join(' '),
|
|
112
|
-
|
|
158
|
+
onClick: onMenuClick,
|
|
113
159
|
selectedKeys: selectedKeys,
|
|
114
160
|
onOpenChange: function onOpenChange(val) {
|
|
115
161
|
if (!!(val !== null && val !== void 0 && val.length) && popupLayout === 'horizontal') {
|