@yueglobal/ui 1.0.3 → 1.0.4

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.3",
3
+ "version": "1.0.4",
4
4
  "description": "粤链全球 - react组件库",
5
5
  "license": "MIT",
6
6
  "module": "index.js",
@@ -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;
@@ -144,7 +144,6 @@ var Index = function Index(_ref) {
144
144
  }
145
145
  },
146
146
  selectedKeys: selectedKeys
147
- // openKeys={['home']}
148
147
  }));
149
148
  };
150
149
  export default /*#__PURE__*/memo(Index);
@@ -25,6 +25,11 @@ export declare const firstMenuList: YueMenuItem[];
25
25
  export declare function flattenTreeList<T extends {
26
26
  children?: T[];
27
27
  }>(data: T[]): T[];
28
+ /**
29
+ * 则根据 key 的长度进行降序排序
30
+ * @param list
31
+ */
32
+ export declare function sortListByKey(list: any[]): any[];
28
33
  /**
29
34
  * 将 firstMenuList 转换为一维数组并根据 key 长度排序
30
35
  * @param isSort 是否进行排序
@@ -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',
@@ -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,9 +86,9 @@ export var firstMenuList = [{
86
86
  label: '关于我们'
87
87
  }];
88
88
 
89
- /**
90
- * 将树结构转换为一维数组
91
- * @param data
89
+ /**
90
+ * 将树结构转换为一维数组
91
+ * @param data
92
92
  */
93
93
  export function flattenTreeList(data) {
94
94
  // 递归函数,将嵌套的菜单数组转换为一维数组
@@ -114,10 +114,20 @@ export function flattenTreeList(data) {
114
114
  return flatten(data);
115
115
  }
116
116
 
117
- /**
118
- * firstMenuList 转换为一维数组并根据 key 长度排序
119
- * @param isSort 是否进行排序
120
- * @returns 排序后的一维数组
117
+ /**
118
+ * 则根据 key 的长度进行降序排序
119
+ * @param list
120
+ */
121
+ export function sortListByKey(list) {
122
+ return list.sort(function (a, b) {
123
+ return b.key.length - a.key.length;
124
+ });
125
+ }
126
+
127
+ /**
128
+ * 将 firstMenuList 转换为一维数组并根据 key 长度排序
129
+ * @param isSort 是否进行排序
130
+ * @returns 排序后的一维数组
121
131
  */
122
132
  export function flattenMenuList(isSort) {
123
133
  // 将嵌套的菜单数组转换为一维数组
@@ -125,17 +135,15 @@ export function flattenMenuList(isSort) {
125
135
 
126
136
  // 如果需要排序,则根据 key 的长度进行降序排序
127
137
  if (isSort) {
128
- return flattenedList.sort(function (a, b) {
129
- return b.key.length - a.key.length;
130
- });
138
+ return sortListByKey(flattenedList);
131
139
  }
132
140
  return flattenedList;
133
141
  }
134
142
 
135
- /**
136
- * 加载script域外资源
137
- * @param src
138
- * @param async
143
+ /**
144
+ * 加载script域外资源
145
+ * @param src
146
+ * @param async
139
147
  */
140
148
  export function loadScript(src, async) {
141
149
  return new Promise(function (resolve, reject) {
@@ -163,10 +171,10 @@ export function loadScript(src, async) {
163
171
  });
164
172
  }
165
173
 
166
- /**
167
- * 检查页面中是否已存在指定文件名的script资源
168
- * @param filename 要检查的脚本文件名
169
- * @returns 如果存在返回true,否则返回false
174
+ /**
175
+ * 检查页面中是否已存在指定文件名的script资源
176
+ * @param filename 要检查的脚本文件名
177
+ * @returns 如果存在返回true,否则返回false
170
178
  */
171
179
  export function checkExistScript(filename) {
172
180
  // 使用filename参数检查script标签是否存在
@@ -174,11 +182,11 @@ export function checkExistScript(filename) {
174
182
  return !!script;
175
183
  }
176
184
 
177
- /**
178
- * 检查路径是否匹配,支持路由参数匹配
179
- * @param routePath 路由定义路径,可能包含参数如 /news/:id/detail
180
- * @param actualPath 实际访问路径,如 /news/123/detail
181
- * @returns 是否匹配
185
+ /**
186
+ * 检查路径是否匹配,支持路由参数匹配
187
+ * @param routePath 路由定义路径,可能包含参数如 /news/:id/detail
188
+ * @param actualPath 实际访问路径,如 /news/123/detail
189
+ * @returns 是否匹配
182
190
  */
183
191
  function isPathMatch(routePath, actualPath) {
184
192
  if (routePath === actualPath) {
@@ -215,11 +223,11 @@ function isPathMatch(routePath, actualPath) {
215
223
  }
216
224
  return true;
217
225
  }
218
- /**
219
- * 根据path值获取完整的节点路径数组(支持动态路由参数)
220
- * @param arr - 包含id, parentId, title, path字段的数组
221
- * @param path - 要查找的完整path值
222
- * @returns 完整的节点路径数组,如果未找到则返回空数组
226
+ /**
227
+ * 根据path值获取完整的节点路径数组(支持动态路由参数)
228
+ * @param arr - 包含id, parentId, title, path字段的数组
229
+ * @param path - 要查找的完整path值
230
+ * @returns 完整的节点路径数组,如果未找到则返回空数组
223
231
  */
224
232
  export function getFullPathNodesByPath(arr, path) {
225
233
  if (!path || path === '/') {
@@ -277,10 +285,10 @@ export function getFullPathNodesByPath(arr, path) {
277
285
  return result;
278
286
  }
279
287
 
280
- /**
281
- * 根据path值对数组进行去重
282
- * @param arr - 包含path字段的数组
283
- * @returns 去重后的数组
288
+ /**
289
+ * 根据path值对数组进行去重
290
+ * @param arr - 包含path字段的数组
291
+ * @returns 去重后的数组
284
292
  */
285
293
  export function uniqByPath(arr) {
286
294
  var seenPaths = new Set();
@@ -304,10 +312,10 @@ export function uniqByPath(arr) {
304
312
  return result;
305
313
  }
306
314
 
307
- /**
308
- * 深度拷贝对象或数组
309
- * @param obj - 要深度拷贝的对象或数组
310
- * @returns 拷贝后的新对象或数组
315
+ /**
316
+ * 深度拷贝对象或数组
317
+ * @param obj - 要深度拷贝的对象或数组
318
+ * @returns 拷贝后的新对象或数组
311
319
  */
312
320
  export function deepClone(obj) {
313
321
  // 处理 null 和 undefined
@@ -363,10 +371,10 @@ function _setPopupStyle(uuid, left) {
363
371
  return false;
364
372
  }
365
373
 
366
- /**
367
- * 设置子菜单弹出层的样式
368
- * @param menuRef - 菜单实例
369
- * @param index - 子菜单索引
374
+ /**
375
+ * 设置子菜单弹出层的样式
376
+ * @param menuRef - 菜单实例
377
+ * @param index - 子菜单索引
370
378
  */
371
379
  export function setSubMenuPopupStyle(menuRef, index) {
372
380
  var _menuRef$menu;
@@ -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,52 @@ 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) setSelectedKeys([pathname]);
37
- }, [pathname]);
38
- var onMenuClick = function onMenuClick(_ref2) {
39
- var key = _ref2.key,
40
- selectedKeys = _ref2.selectedKeys;
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
+ selectedKeys = _ref3.selectedKeys;
41
88
  setSelectedKeys(selectedKeys);
42
89
  if (onRouteChange && menuItems !== null && menuItems !== void 0 && menuItems.length) {
43
- var menuList = flattenTreeList(menuItems);
44
- var current = menuList.find(function (m) {
90
+ var _menuListRef$current2;
91
+ var current = (_menuListRef$current2 = menuListRef.current) === null || _menuListRef$current2 === void 0 ? void 0 : _menuListRef$current2.find(function (m) {
45
92
  return m.key === key;
46
93
  });
47
94
  var value = {
@@ -106,7 +153,7 @@ var Index = function Index(_ref) {
106
153
  className: "menus"
107
154
  }, /*#__PURE__*/React.createElement(Menu, {
108
155
  ref: menuRef,
109
- items: menuItems,
156
+ items: mergeMenuItems,
110
157
  mode: "horizontal",
111
158
  rootClassName: ['yue-second-menu-bar', "yue-second-menu-".concat(popupLayout)].join(' '),
112
159
  onSelect: onMenuClick,