@yueglobal/ui 1.0.4 → 1.0.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yueglobal/ui",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "粤链全球 - react组件库",
5
5
  "license": "MIT",
6
6
  "module": "index.js",
@@ -1,6 +1,7 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import './index.less';
3
3
  interface Props {
4
+ hasSecondMenu?: boolean;
4
5
  moduleData: {
5
6
  title?: string;
6
7
  icon?: ReactNode;
@@ -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 menuRef = useRef(null);
22
- var _useState3 = useState(deepClone(firstMenuList)),
22
+ var _useState3 = useState(false),
23
23
  _useState4 = _slicedToArray(_useState3, 2),
24
- menuList = _useState4[0],
25
- setMenuList = _useState4[1];
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: 5,
128
- itemPaddingInline: 18,
143
+ activeBarHeight: 14,
144
+ itemPaddingInline: 4,
129
145
  itemColor: '#000',
130
146
  dropdownWidth: '100%',
131
147
  horizontalLineHeight: '30px'
@@ -136,14 +152,16 @@ var Index = function Index(_ref) {
136
152
  ref: menuRef,
137
153
  items: menuList,
138
154
  mode: "horizontal",
139
- rootClassName: "yue-page-header-first-menu",
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[0]);
159
+ onSubMenuOpen(val[val.length - 1]);
144
160
  }
161
+ setOpen(!!val.length);
145
162
  },
146
- selectedKeys: selectedKeys
163
+ selectedKeys: selectedKeys,
164
+ subMenuCloseDelay: 1.5
147
165
  }));
148
166
  };
149
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
- color: #1a4bff;
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
- border-bottom-color: #1a4bff;
36
- border-radius: 3px 3px 0 0;
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-selected:not(.ant-menu-submenu-active) {
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
- content: none;
81
+ border-bottom-color: #17c8b8;
43
82
  }
44
- .ant-menu-submenu-title {
45
- color: #000;
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
@@ -81,5 +86,6 @@ export declare function deepClone<T>(obj: T): T;
81
86
  * 设置子菜单弹出层的样式
82
87
  * @param menuRef - 菜单实例
83
88
  * @param index - 子菜单索引
89
+ * @param zIndex - 是否重设 zIndex
84
90
  */
85
- export declare function setSubMenuPopupStyle(menuRef: MenuRef, index: number): false | undefined;
91
+ export declare function setSubMenuPopupStyle(menuRef: MenuRef, index: number, zIndex?: boolean): false | undefined;
@@ -11,8 +11,8 @@ import { ExpoIcon, HomeIcon, HwcIcon, InsuranceIcon, LawIcon, SelectionIcon, Tax
11
11
  // 主网站域名
12
12
  export var mainHost = 'https://www.yueglobal.com';
13
13
 
14
- /**
15
- * 一级菜单(主菜单)
14
+ /**
15
+ * 一级菜单(主菜单)
16
16
  */
17
17
  export var firstMenuList = [{
18
18
  key: 'home',
@@ -86,9 +86,24 @@ export var firstMenuList = [{
86
86
  label: '关于我们'
87
87
  }];
88
88
 
89
- /**
90
- * 将树结构转换为一维数组
91
- * @param data
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
+
104
+ /**
105
+ * 将树结构转换为一维数组
106
+ * @param data
92
107
  */
93
108
  export function flattenTreeList(data) {
94
109
  // 递归函数,将嵌套的菜单数组转换为一维数组
@@ -114,9 +129,9 @@ export function flattenTreeList(data) {
114
129
  return flatten(data);
115
130
  }
116
131
 
117
- /**
118
- * 则根据 key 的长度进行降序排序
119
- * @param list
132
+ /**
133
+ * 则根据 key 的长度进行降序排序
134
+ * @param list
120
135
  */
121
136
  export function sortListByKey(list) {
122
137
  return list.sort(function (a, b) {
@@ -124,10 +139,10 @@ export function sortListByKey(list) {
124
139
  });
125
140
  }
126
141
 
127
- /**
128
- * 将 firstMenuList 转换为一维数组并根据 key 长度排序
129
- * @param isSort 是否进行排序
130
- * @returns 排序后的一维数组
142
+ /**
143
+ * 将 firstMenuList 转换为一维数组并根据 key 长度排序
144
+ * @param isSort 是否进行排序
145
+ * @returns 排序后的一维数组
131
146
  */
132
147
  export function flattenMenuList(isSort) {
133
148
  // 将嵌套的菜单数组转换为一维数组
@@ -140,10 +155,10 @@ export function flattenMenuList(isSort) {
140
155
  return flattenedList;
141
156
  }
142
157
 
143
- /**
144
- * 加载script域外资源
145
- * @param src
146
- * @param async
158
+ /**
159
+ * 加载script域外资源
160
+ * @param src
161
+ * @param async
147
162
  */
148
163
  export function loadScript(src, async) {
149
164
  return new Promise(function (resolve, reject) {
@@ -171,10 +186,10 @@ export function loadScript(src, async) {
171
186
  });
172
187
  }
173
188
 
174
- /**
175
- * 检查页面中是否已存在指定文件名的script资源
176
- * @param filename 要检查的脚本文件名
177
- * @returns 如果存在返回true,否则返回false
189
+ /**
190
+ * 检查页面中是否已存在指定文件名的script资源
191
+ * @param filename 要检查的脚本文件名
192
+ * @returns 如果存在返回true,否则返回false
178
193
  */
179
194
  export function checkExistScript(filename) {
180
195
  // 使用filename参数检查script标签是否存在
@@ -182,11 +197,11 @@ export function checkExistScript(filename) {
182
197
  return !!script;
183
198
  }
184
199
 
185
- /**
186
- * 检查路径是否匹配,支持路由参数匹配
187
- * @param routePath 路由定义路径,可能包含参数如 /news/:id/detail
188
- * @param actualPath 实际访问路径,如 /news/123/detail
189
- * @returns 是否匹配
200
+ /**
201
+ * 检查路径是否匹配,支持路由参数匹配
202
+ * @param routePath 路由定义路径,可能包含参数如 /news/:id/detail
203
+ * @param actualPath 实际访问路径,如 /news/123/detail
204
+ * @returns 是否匹配
190
205
  */
191
206
  function isPathMatch(routePath, actualPath) {
192
207
  if (routePath === actualPath) {
@@ -223,11 +238,11 @@ function isPathMatch(routePath, actualPath) {
223
238
  }
224
239
  return true;
225
240
  }
226
- /**
227
- * 根据path值获取完整的节点路径数组(支持动态路由参数)
228
- * @param arr - 包含id, parentId, title, path字段的数组
229
- * @param path - 要查找的完整path值
230
- * @returns 完整的节点路径数组,如果未找到则返回空数组
241
+ /**
242
+ * 根据path值获取完整的节点路径数组(支持动态路由参数)
243
+ * @param arr - 包含id, parentId, title, path字段的数组
244
+ * @param path - 要查找的完整path值
245
+ * @returns 完整的节点路径数组,如果未找到则返回空数组
231
246
  */
232
247
  export function getFullPathNodesByPath(arr, path) {
233
248
  if (!path || path === '/') {
@@ -285,10 +300,10 @@ export function getFullPathNodesByPath(arr, path) {
285
300
  return result;
286
301
  }
287
302
 
288
- /**
289
- * 根据path值对数组进行去重
290
- * @param arr - 包含path字段的数组
291
- * @returns 去重后的数组
303
+ /**
304
+ * 根据path值对数组进行去重
305
+ * @param arr - 包含path字段的数组
306
+ * @returns 去重后的数组
292
307
  */
293
308
  export function uniqByPath(arr) {
294
309
  var seenPaths = new Set();
@@ -312,10 +327,10 @@ export function uniqByPath(arr) {
312
327
  return result;
313
328
  }
314
329
 
315
- /**
316
- * 深度拷贝对象或数组
317
- * @param obj - 要深度拷贝的对象或数组
318
- * @returns 拷贝后的新对象或数组
330
+ /**
331
+ * 深度拷贝对象或数组
332
+ * @param obj - 要深度拷贝的对象或数组
333
+ * @returns 拷贝后的新对象或数组
319
334
  */
320
335
  export function deepClone(obj) {
321
336
  // 处理 null 和 undefined
@@ -349,7 +364,8 @@ export function deepClone(obj) {
349
364
  }
350
365
  return clonedObj;
351
366
  }
352
- function _setPopupStyle(uuid, left) {
367
+ var popupZIndex = 2000;
368
+ function _setPopupStyle(uuid, left, zIndex) {
353
369
  var popupUL = window.document.getElementById(uuid);
354
370
  if (popupUL) {
355
371
  var contentWidth = 0;
@@ -363,20 +379,30 @@ function _setPopupStyle(uuid, left) {
363
379
  popupUL.style.paddingLeft = "unset";
364
380
  popupUL.style.justifyContent = 'center';
365
381
  } else {
366
- popupUL.style.paddingLeft = "".concat(left - 8, "px");
382
+ popupUL.style.paddingLeft = "".concat(left - 4, "px");
367
383
  popupUL.style.justifyContent = 'unset';
368
384
  }
385
+ if (zIndex) {
386
+ var _rootEle$tagName;
387
+ // const rootEle = popupUL.parentElement?.parentElement;
388
+ var rootEle = popupUL.parentElement;
389
+ if (rootEle && ((_rootEle$tagName = rootEle.tagName) === null || _rootEle$tagName === void 0 ? void 0 : _rootEle$tagName.toLowerCase()) !== 'body') {
390
+ // rootEle.style.position = 'relative';
391
+ rootEle.style.zIndex = ++popupZIndex + '';
392
+ }
393
+ }
369
394
  return true;
370
395
  }
371
396
  return false;
372
397
  }
373
398
 
374
- /**
375
- * 设置子菜单弹出层的样式
376
- * @param menuRef - 菜单实例
377
- * @param index - 子菜单索引
399
+ /**
400
+ * 设置子菜单弹出层的样式
401
+ * @param menuRef - 菜单实例
402
+ * @param index - 子菜单索引
403
+ * @param zIndex - 是否重设 zIndex
378
404
  */
379
- export function setSubMenuPopupStyle(menuRef, index) {
405
+ export function setSubMenuPopupStyle(menuRef, index, zIndex) {
380
406
  var _menuRef$menu;
381
407
  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);
382
408
  if (!li) {
@@ -393,11 +419,11 @@ export function setSubMenuPopupStyle(menuRef, index) {
393
419
  var _li$getBoundingClient = li.getBoundingClientRect(),
394
420
  left = _li$getBoundingClient.left;
395
421
  setTimeout(function () {
396
- var success = _setPopupStyle(uuid, left);
422
+ var success = _setPopupStyle(uuid, left, zIndex);
397
423
  if (!success) {
398
424
  setTimeout(function () {
399
425
  // 重新执行一次
400
- _setPopupStyle(uuid, left);
426
+ _setPopupStyle(uuid, left, zIndex);
401
427
  }, 100);
402
428
  }
403
429
  }, 100, uuid, left);
@@ -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
@@ -40,5 +40,6 @@
40
40
  height: 100%;
41
41
  flex: 1 1 0%;
42
42
  min-width: 0;
43
+ position: relative;
43
44
  }
44
45
  }
@@ -83,9 +83,8 @@ var Index = function Index(_ref) {
83
83
  }
84
84
  }, [pathname, isLoaded]);
85
85
  var onMenuClick = function onMenuClick(_ref3) {
86
- var key = _ref3.key,
87
- selectedKeys = _ref3.selectedKeys;
88
- setSelectedKeys(selectedKeys);
86
+ var key = _ref3.key;
87
+ setSelectedKeys([key]);
89
88
  if (onRouteChange && menuItems !== null && menuItems !== void 0 && menuItems.length) {
90
89
  var _menuListRef$current2;
91
90
  var current = (_menuListRef$current2 = menuListRef.current) === null || _menuListRef$current2 === void 0 ? void 0 : _menuListRef$current2.find(function (m) {
@@ -156,7 +155,7 @@ var Index = function Index(_ref) {
156
155
  items: mergeMenuItems,
157
156
  mode: "horizontal",
158
157
  rootClassName: ['yue-second-menu-bar', "yue-second-menu-".concat(popupLayout)].join(' '),
159
- onSelect: onMenuClick,
158
+ onClick: onMenuClick,
160
159
  selectedKeys: selectedKeys,
161
160
  onOpenChange: function onOpenChange(val) {
162
161
  if (!!(val !== null && val !== void 0 && val.length) && popupLayout === 'horizontal') {