@yueglobal/ui 1.0.2 → 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/README.md CHANGED
@@ -25,20 +25,22 @@ import {
25
25
 
26
26
  ### 属性
27
27
 
28
- | 属性 | 说明 | 类型 | 默认值 |
29
- | ----------------- | ----------------------------------- | ------------------------------------------- | ------ |
30
- | `width` | 内容宽度 | `string` \| `number` | `80%` |
31
- | `backgroundColor` | 头部背景色 | `string` | `#fff` |
32
- | `activeLabel` | 当前选中的一级菜单项的标题 | `string` | |
33
- | `rightContent` | 顶部右侧的登录/用户信息按钮 | `ReactNode` | |
34
- | `menuItems` | 各业务系统的菜单 | `YueMenuItem`[] | |
35
- | `pageTitle` | 缺值时从一级菜单取值 | `string` | |
36
- | `pageIcon` | 页面图标 | `ReactNode` | |
37
- | `breadcrumbs` | 自定义面包屑数据 | `YueBreadcrumb`[] | |
38
- | `routes` | 路由数据,用于自动生成面包屑 | any | |
39
- | `pathname` | 当前的路由 | `string` | |
40
- | `onRouteChange` | 点击菜单/面包屑时触发的路由切换事件 | `({ key: string; label?: string }) => void` | |
41
- | `onLocaleChange` | 切换语言时的回调事件 | `({locale: string}) => void` | |
28
+ | 属性 | 说明 | 类型 | 默认值 |
29
+ | ----------------- | ----------------------------------- | ------------------------------------------- | ---------- |
30
+ | `width` | 内容宽度 | `string` \| `number` | `80%` |
31
+ | `backgroundColor` | 头部背景色 | `string` | `#fff` |
32
+ | `activeLabel` | 当前选中的一级菜单项的标题 | `string` | |
33
+ | `rightContent` | 顶部右侧的登录/用户信息按钮 | `ReactNode` | |
34
+ | `onLocaleChange` | 切换语言时的回调事件 | `({locale: string}) => void` | |
35
+ | | `以下二级导航栏的配置` | | |
36
+ | `menuItems` | 各业务系统的菜单 | `YueMenuItem`[] | |
37
+ | `pageTitle` | 缺值时从一级菜单匹配值 | `string` | |
38
+ | `pageIcon` | 页面图标 | `ReactNode` | |
39
+ | `breadcrumbs` | 自定义面包屑数据 | `YueBreadcrumb`[] | |
40
+ | `routes` | 路由数据,用于自动生成面包屑 | any | |
41
+ | `pathname` | 当前的路由 | `string` | |
42
+ | `subMenuLayout` | 二级导航栏的菜单弹出层布局 | `vertical` \| `horizontal` | `vertical` |
43
+ | `onRouteChange` | 点击菜单/面包屑时触发的路由切换事件 | `({ key: string; label?: string }) => void` | |
42
44
 
43
45
  - 业务子系统:`pageTitle`或`pageIcon`缺省时会根据`url`自动从一级菜单匹配值
44
46
 
@@ -0,0 +1,9 @@
1
+ <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
2
+ width="1em" height="1em">
3
+ <path
4
+ d="M890.56 110.69666665H133.33333333c-35.2 0-64.10666667 28.8-64.10666666 64.10666668v518.4c0 35.2 28.8 64.10666667 64.10666666 64.10666667h346.56s0.10666667 0 0.10666667 0.10666666v139.84s0 0.10666667-0.10666667 0.10666666H170.66666667c-17.49333333 0-32.21333333 13.65333333-32.74666667 31.14666668-0.42666667 18.02666667 14.08 32.85333333 32 32.85333333H853.33333333c17.49333333 0 32.21333333-13.65333333 32.74666667-31.14666667 0.42666667-18.02666667-14.08-32.85333333-32-32.85333334H544s-0.10666667 0-0.10666667-0.10666666V757.20333333s0-0.10666667 0.10666667-0.10666667h346.56c35.2 0 64.10666667-28.8 64.10666667-64.10666666v-518.4c0-35.09333333-28.90666667-63.89333333-64.10666667-63.89333335z m0.10666667 582.29333335l-0.21333334 0.21333333H133.44l-0.21333333-0.21333333V174.91l0.21333333-0.21333335h757.01333333l0.21333334 0.21333335v518.08z"
5
+ ></path>
6
+ <path
7
+ d="M266.45333333 251.49666666h-33.70666666c-11.73333333 0-21.33333333 9.6-21.33333334 21.33333334v33.70666665c0 11.73333333 9.6 21.33333333 21.33333334 21.33333335h33.70666666c11.73333333 0 21.33333333-9.6 21.33333334-21.33333335v-33.70666665c0-11.73333333-9.6-21.33333333-21.33333334-21.33333334zM363.52 251.49666666h-33.70666667c-11.73333333 0-21.33333333 9.6-21.33333333 21.33333334v33.70666665c0 11.73333333 9.6 21.33333333 21.33333333 21.33333335h33.70666667c11.73333333 0 21.33333333-9.6 21.33333333-21.33333335v-33.70666665c0-11.73333333-9.6-21.33333333-21.33333333-21.33333334zM460.69333333 251.49666666h-33.70666666c-11.73333333 0-21.33333333 9.6-21.33333334 21.33333334v33.70666665c0 11.73333333 9.6 21.33333333 21.33333334 21.33333335h33.70666666c11.73333333 0 21.33333333-9.6 21.33333334-21.33333335v-33.70666665c0-11.73333333-9.6-21.33333333-21.33333334-21.33333334z"
8
+ ></path>
9
+ </svg>
@@ -6,6 +6,7 @@ export interface SvgIconProps {
6
6
  onClick?: (e?: any) => void;
7
7
  [key: string]: any;
8
8
  }
9
+ export declare const ComputerIcon: FC<SvgIconProps>;
9
10
  export declare const DeclarationIcon: FC<SvgIconProps>;
10
11
  export declare const ExpoIcon: FC<SvgIconProps>;
11
12
  export declare const HwcIcon: FC<SvgIconProps>;
@@ -9,6 +9,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
9
9
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
10
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
11
  import React, { memo } from 'react';
12
+ import { ReactComponent as Computer } from "./computer.svg";
12
13
  import { ReactComponent as Declaration } from "./declaration.svg";
13
14
  import { ReactComponent as Expo } from "./expo.svg";
14
15
  import { ReactComponent as Home } from "./home.svg";
@@ -34,6 +35,11 @@ var SvgIcon = /*#__PURE__*/memo(function (_ref) {
34
35
  }), children);
35
36
  });
36
37
 
38
+ // 电脑(默认图标)
39
+ export var ComputerIcon = /*#__PURE__*/memo(function (props) {
40
+ return /*#__PURE__*/React.createElement(SvgIcon, props, /*#__PURE__*/React.createElement(Computer, null));
41
+ });
42
+
37
43
  // 通关申报
38
44
  export var DeclarationIcon = /*#__PURE__*/memo(function (props) {
39
45
  return /*#__PURE__*/React.createElement(SvgIcon, props, /*#__PURE__*/React.createElement(Declaration, null));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yueglobal/ui",
3
- "version": "1.0.2",
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;
@@ -88,9 +88,9 @@ var Index = function Index(_ref) {
88
88
 
89
89
  // 其他是模块内部路由跳转
90
90
  var isLast = (currentRoute === null || currentRoute === void 0 ? void 0 : currentRoute.path) === ((_items = items[items.length - 1]) === null || _items === void 0 ? void 0 : _items.path);
91
- var fullPath = newPaths.join('/');
92
- if (!fullPath.startsWith('/')) {
93
- fullPath = '/' + fullPath;
91
+ var currentPath = newPaths[newPaths.length - 1];
92
+ if (!currentPath.startsWith('/')) {
93
+ currentPath = '/' + currentPath;
94
94
  }
95
95
  return isLast ? /*#__PURE__*/React.createElement(Text, {
96
96
  ellipsis: {
@@ -99,7 +99,7 @@ var Index = function Index(_ref) {
99
99
  }, title) : /*#__PURE__*/React.createElement("a", {
100
100
  onClick: function onClick() {
101
101
  onRouteChange === null || onRouteChange === void 0 || onRouteChange({
102
- key: fullPath,
102
+ key: currentPath,
103
103
  label: title
104
104
  });
105
105
  }
@@ -24,7 +24,7 @@ var Index = function Index(_ref) {
24
24
  menuList = _useState4[0],
25
25
  setMenuList = _useState4[1];
26
26
  useEffect(function () {
27
- if (!(selectedKeys !== null && selectedKeys !== void 0 && selectedKeys.length) && !!(menuList !== null && menuList !== void 0 && menuList.length) && moduleData) {
27
+ if (!!(menuList !== null && menuList !== void 0 && menuList.length) && moduleData) {
28
28
  var key = moduleData.key;
29
29
  if (!key) {
30
30
  var _menuList$find;
@@ -36,7 +36,7 @@ var Index = function Index(_ref) {
36
36
  setSelectedKeys([key]);
37
37
  }
38
38
  }
39
- }, [selectedKeys, menuList, moduleData]);
39
+ }, [menuList, moduleData]);
40
40
 
41
41
  // 获取新闻资讯的类目
42
42
  var fetchNewsData = /*#__PURE__*/function () {
@@ -69,7 +69,6 @@ var Index = function Index(_ref) {
69
69
  return {
70
70
  key: "".concat(mainHost, "/consultation/content-list?classId=").concat(d.id, "&title=").concat(d.className),
71
71
  label: d.className
72
- // icon: <i className="yue-icon-dot" />,
73
72
  };
74
73
  }));
75
74
  case 8:
@@ -145,7 +144,6 @@ var Index = function Index(_ref) {
145
144
  }
146
145
  },
147
146
  selectedKeys: selectedKeys
148
- // openKeys={['home']}
149
147
  }));
150
148
  };
151
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;
@@ -19,6 +19,7 @@ export interface YuePageHeaderProps {
19
19
  onLocaleChange?: (value: {
20
20
  locale: string;
21
21
  }) => void;
22
+ subMenuLayout?: 'vertical' | 'horizontal';
22
23
  }
23
24
  declare const _default: React.NamedExoticComponent<YuePageHeaderProps>;
24
25
  export default _default;
@@ -32,23 +32,28 @@ var Index = function Index(_ref) {
32
32
  var icon = pageIcon;
33
33
  var key;
34
34
  var firstMenuList = flattenMenuList(true);
35
- var _window$location = window.location,
36
- origin = _window$location.origin,
37
- pathname = _window$location.pathname;
38
- var url = origin + pathname;
39
- var current = firstMenuList.find(function (m) {
40
- return !!(m !== null && m !== void 0 && m.key) && url.startsWith("".concat(m.key));
41
- });
35
+ var current;
36
+ // 先判断activeLabel
37
+ if (activeLabel) {
38
+ current = firstMenuList.find(function (m) {
39
+ return (m === null || m === void 0 ? void 0 : m.label) === activeLabel;
40
+ });
41
+ }
42
+ // 再判断pageTitle
43
+ if (!current && pageTitle) {
44
+ current = firstMenuList.find(function (m) {
45
+ return (m === null || m === void 0 ? void 0 : m.label) === pageTitle;
46
+ });
47
+ }
48
+ // 最后从url匹配
42
49
  if (!current) {
43
- if (activeLabel) {
44
- current = firstMenuList.find(function (m) {
45
- return (m === null || m === void 0 ? void 0 : m.label) === activeLabel;
46
- });
47
- } else if (pageTitle) {
48
- current = firstMenuList.find(function (m) {
49
- return (m === null || m === void 0 ? void 0 : m.label) === pageTitle;
50
- });
51
- }
50
+ var _window$location = window.location,
51
+ origin = _window$location.origin,
52
+ pathname = _window$location.pathname;
53
+ var url = origin + pathname;
54
+ current = firstMenuList.find(function (m) {
55
+ return !!(m !== null && m !== void 0 && m.key) && url.startsWith("".concat(m.key));
56
+ });
52
57
  }
53
58
  if (current) {
54
59
  if (!title) {
@@ -1,13 +1,20 @@
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); }
4
10
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
11
  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; } }
6
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import { ComputerIcon } from "../../components/svg-icon";
7
14
  import { ConfigProvider, Menu } from 'antd';
8
- import React, { memo, useEffect, useRef, useState } from 'react';
15
+ import React, { memo, useEffect, useMemo, useRef, useState } from 'react';
9
16
  import Breadcrumb from "../breadcrumb";
10
- import { flattenTreeList, setSubMenuPopupStyle } from "../helper";
17
+ import { flattenTreeList, setSubMenuPopupStyle, sortListByKey } from "../helper";
11
18
  import "./index.less";
12
19
  var Index = function Index(_ref) {
13
20
  var width = _ref.width,
@@ -16,22 +23,72 @@ var Index = function Index(_ref) {
16
23
  menuItems = _ref.menuItems,
17
24
  pathname = _ref.pathname,
18
25
  moduleData = _ref.moduleData,
19
- onRouteChange = _ref.onRouteChange;
26
+ onRouteChange = _ref.onRouteChange,
27
+ subMenuLayout = _ref.subMenuLayout;
20
28
  var _useState = useState(),
21
29
  _useState2 = _slicedToArray(_useState, 2),
22
30
  selectedKeys = _useState2[0],
23
31
  setSelectedKeys = _useState2[1];
32
+ var _useState3 = useState(false),
33
+ _useState4 = _slicedToArray(_useState3, 2),
34
+ isLoaded = _useState4[0],
35
+ setIsLoaded = _useState4[1];
24
36
  var menuRef = useRef(null);
37
+ var menuListRef = useRef([]);
38
+
39
+ // 弹出层的布局,默认是 vertical
40
+ var popupLayout = useMemo(function () {
41
+ if (subMenuLayout === 'vertical' || subMenuLayout === 'horizontal') {
42
+ return subMenuLayout;
43
+ }
44
+ return 'vertical';
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]);
25
70
  useEffect(function () {
26
- if (pathname) setSelectedKeys([pathname]);
27
- }, [pathname]);
28
- var onMenuClick = function onMenuClick(_ref2) {
29
- var key = _ref2.key,
30
- 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;
31
88
  setSelectedKeys(selectedKeys);
32
89
  if (onRouteChange && menuItems !== null && menuItems !== void 0 && menuItems.length) {
33
- var menuList = flattenTreeList(menuItems);
34
- 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) {
35
92
  return m.key === key;
36
93
  });
37
94
  var value = {
@@ -86,21 +143,23 @@ var Index = function Index(_ref) {
86
143
  className: "yue-flex left"
87
144
  }, /*#__PURE__*/React.createElement("div", {
88
145
  className: "yue-flex module-info"
89
- }, !!moduleData.icon && /*#__PURE__*/React.createElement("span", {
146
+ }, !!moduleData.icon ? /*#__PURE__*/React.createElement("span", {
147
+ className: "module-icon"
148
+ }, moduleData.icon) : !!moduleData.title && /*#__PURE__*/React.createElement("span", {
90
149
  className: "module-icon"
91
- }, moduleData.icon), !!moduleData.title && /*#__PURE__*/React.createElement("div", {
150
+ }, /*#__PURE__*/React.createElement(ComputerIcon, null)), !!moduleData.title && /*#__PURE__*/React.createElement("div", {
92
151
  className: "module-title"
93
152
  }, moduleData.title)), /*#__PURE__*/React.createElement("div", {
94
153
  className: "menus"
95
154
  }, /*#__PURE__*/React.createElement(Menu, {
96
155
  ref: menuRef,
97
- items: menuItems,
156
+ items: mergeMenuItems,
98
157
  mode: "horizontal",
99
- rootClassName: "yue-second-menu-bar",
158
+ rootClassName: ['yue-second-menu-bar', "yue-second-menu-".concat(popupLayout)].join(' '),
100
159
  onSelect: onMenuClick,
101
160
  selectedKeys: selectedKeys,
102
161
  onOpenChange: function onOpenChange(val) {
103
- if (!!(val !== null && val !== void 0 && val.length)) {
162
+ if (!!(val !== null && val !== void 0 && val.length) && popupLayout === 'horizontal') {
104
163
  onSubMenuOpen(val[0]);
105
164
  }
106
165
  }
@@ -1,160 +1,227 @@
1
- .yue-page-header-second-menu {
2
- height: 60px;
3
- background: linear-gradient(90deg, #17f1a1, #1a4bff);
4
- opacity: 1;
5
- transition: opacity 0.2s ease-in-out;
6
-
7
- &.hidden {
8
- //opacity: 0;
9
- }
10
-
11
- .wrapper {
12
- margin: 0 auto;
13
- justify-content: space-between;
14
- height: 100%;
15
- color: #fff;
16
- max-width: 98%;
17
- }
18
-
19
- .left {
20
- gap: 8px;
21
- height: 100%;
22
- }
23
-
24
- .module-info {
25
- gap: 14px;
26
- margin-right: 10px;
27
- flex-shrink: 0;
28
- }
29
-
30
- .module-icon {
31
- font-size: 27px;
32
- line-height: 0;
33
- }
34
-
35
- .module-title {
36
- font-size: 24px;
37
- font-weight: bold;
38
- min-width: 147px;
39
- max-width: 300px;
40
- white-space: nowrap;
41
- overflow: hidden;
42
- text-overflow: ellipsis;
43
- }
44
-
45
- .vr {
46
- width: 1px;
47
- height: 28px;
48
- background-color: rgba(255, 255, 255, 85%);
49
- flex-shrink: 0;
50
- }
51
-
52
- .menus {
53
- //max-width: 82%;
54
- height: 100%;
55
- padding-block: 1px;
56
- flex: 1 1 0;
57
- min-width: 0;
58
- padding-right: 30px;
59
- }
60
- }
61
-
62
- .yue-second-menu-bar {
63
- &.ant-menu-root {
64
- background-color: transparent;
65
- font-size: 18px;
66
- height: 100%;
67
- border-bottom: none;
68
- gap: 4px;
69
-
70
- & > li {
71
- display: flex;
72
- align-items: center;
73
- justify-content: center;
74
- }
75
-
76
- .ant-menu-submenu-title {
77
- height: 100%;
78
- display: flex;
79
- align-items: center;
80
- justify-content: center;
81
- }
82
-
83
- .ant-menu-title-content {
84
- height: 34px;
85
- line-height: 32px;
86
- border-radius: 16px;
87
- padding-inline: 16px;
88
- min-width: 80px;
89
- text-align: center;
90
- }
91
-
92
- .ant-menu-submenu-active,
93
- .ant-menu-item-active {
94
- .ant-menu-title-content {
95
- background-color: rgba(255, 255, 255, 20%);
96
- }
97
- }
98
-
99
- .ant-menu-submenu-selected,
100
- .ant-menu-item-selected {
101
- .ant-menu-title-content {
102
- background-color: #fff;
103
- }
104
- }
105
- }
106
-
107
- &.ant-menu-submenu-popup {
108
- left: 0 !important;
109
- padding: 0;
110
- font-size: 18px;
111
- //background-color: rgba(0, 0, 0, 45%);
112
- background-color: rgba(4, 41, 131, 0.65);
113
- border-radius: 0;
114
- width: 100%;
115
-
116
- .ant-menu-sub {
117
- display: flex;
118
- justify-content: center;
119
- background-color: transparent;
120
- border-radius: 0;
121
- box-shadow: none;
122
- }
123
-
124
- .ant-menu-item {
125
- width: max-content;
126
- flex: unset;
127
- color: #fff;
128
- margin: 0;
129
- border-radius: 0;
130
- height: 60px;
131
- line-height: 30px;
132
- display: flex;
133
- align-items: center;
134
- padding-inline: 25px 18px;
135
- flex-shrink: 0;
136
- position: relative;
137
-
138
- &::before {
139
- content: '';
140
- position: absolute;
141
- left: 10px;
142
- top: 50%;
143
- transform: translateY(-50%);
144
- width: 4px;
145
- height: 4px;
146
- border-radius: 50%;
147
- background-color: rgba(255, 255, 255, 85%);
148
- }
149
- }
150
-
151
- .ant-menu-item-active,
152
- .ant-menu-item-selected {
153
- background: linear-gradient(90deg, #17f1a1, #1a4bff);
154
- }
155
-
156
- /*.ant-menu-item-selected {
157
- background-color: rgba(0, 0, 0, 40%);
158
- }*/
159
- }
160
- }
1
+ .yue-page-header-second-menu {
2
+ height: 60px;
3
+ background: linear-gradient(90deg, #17f1a1, #1a4bff);
4
+ opacity: 1;
5
+ transition: opacity 0.2s ease-in-out;
6
+
7
+ &.hidden {
8
+ //opacity: 0;
9
+ }
10
+
11
+ .wrapper {
12
+ margin: 0 auto;
13
+ justify-content: space-between;
14
+ height: 100%;
15
+ color: #fff;
16
+ max-width: 98%;
17
+ }
18
+
19
+ .left {
20
+ gap: 8px;
21
+ height: 100%;
22
+ }
23
+
24
+ .module-info {
25
+ gap: 14px;
26
+ margin-right: 10px;
27
+ flex-shrink: 0;
28
+ }
29
+
30
+ .module-icon {
31
+ font-size: 27px;
32
+ line-height: 0;
33
+ }
34
+
35
+ .module-title {
36
+ font-size: 24px;
37
+ font-weight: bold;
38
+ min-width: 147px;
39
+ max-width: 300px;
40
+ white-space: nowrap;
41
+ overflow: hidden;
42
+ text-overflow: ellipsis;
43
+ }
44
+
45
+ .vr {
46
+ width: 1px;
47
+ height: 28px;
48
+ background-color: rgba(255, 255, 255, 85%);
49
+ flex-shrink: 0;
50
+ }
51
+
52
+ .menus {
53
+ //max-width: 82%;
54
+ height: 100%;
55
+ padding-block: 1px;
56
+ flex: 1 1 0;
57
+ min-width: 0;
58
+ padding-right: 30px;
59
+ }
60
+ }
61
+
62
+ .yue-second-menu-bar {
63
+ &.ant-menu-root {
64
+ background-color: transparent;
65
+ font-size: 18px;
66
+ height: 100%;
67
+ border-bottom: none;
68
+ gap: 4px;
69
+
70
+ & > li {
71
+ display: flex;
72
+ align-items: center;
73
+ justify-content: center;
74
+ }
75
+
76
+ .ant-menu-submenu-title {
77
+ height: 100%;
78
+ display: flex;
79
+ align-items: center;
80
+ justify-content: center;
81
+ }
82
+
83
+ .ant-menu-title-content {
84
+ height: 34px;
85
+ line-height: 32px;
86
+ border-radius: 16px;
87
+ padding-inline: 16px;
88
+ min-width: 80px;
89
+ text-align: center;
90
+ }
91
+
92
+ .ant-menu-submenu-active,
93
+ .ant-menu-item-active {
94
+ .ant-menu-title-content {
95
+ background-color: rgba(255, 255, 255, 20%);
96
+ }
97
+ }
98
+
99
+ .ant-menu-submenu-selected,
100
+ .ant-menu-item-selected {
101
+ .ant-menu-title-content {
102
+ background-color: #fff;
103
+ }
104
+ }
105
+ }
106
+
107
+ &.ant-menu-submenu-popup {
108
+ // 横向菜单的样式
109
+ &.yue-second-menu-horizontal {
110
+ left: 0 !important;
111
+ padding: 0;
112
+ font-size: 18px;
113
+ //background-color: rgba(0, 0, 0, 45%);
114
+ background-color: rgba(4, 41, 131, 0.65);
115
+ border-radius: 0;
116
+ width: 100%;
117
+
118
+ .ant-menu-sub {
119
+ display: flex;
120
+ justify-content: center;
121
+ background-color: transparent;
122
+ border-radius: 0;
123
+ box-shadow: none;
124
+ }
125
+
126
+ .ant-menu-item {
127
+ width: max-content;
128
+ flex: unset;
129
+ color: #fff;
130
+ margin: 0;
131
+ border-radius: 0;
132
+ height: 60px;
133
+ line-height: 30px;
134
+ display: flex;
135
+ align-items: center;
136
+ padding-inline: 25px 18px;
137
+ flex-shrink: 0;
138
+ position: relative;
139
+
140
+ &::before {
141
+ content: '';
142
+ position: absolute;
143
+ left: 10px;
144
+ top: 50%;
145
+ transform: translateY(-50%);
146
+ width: 4px;
147
+ height: 4px;
148
+ border-radius: 50%;
149
+ background-color: rgba(255, 255, 255, 85%);
150
+ }
151
+ }
152
+
153
+ .ant-menu-item-active,
154
+ .ant-menu-item-selected {
155
+ background: linear-gradient(90deg, #17f1a1, #1a4bff);
156
+ }
157
+ }
158
+
159
+ // 竖向菜单的样式
160
+ &.yue-second-menu-vertical {
161
+ font-size: 17px;
162
+
163
+ .ant-menu-sub {
164
+ background: linear-gradient(
165
+ 135deg,
166
+ rgb(50, 205, 150),
167
+ rgb(73, 108, 236)
168
+ );
169
+ margin: -7px 0 0;
170
+ }
171
+
172
+ .ant-menu-item {
173
+ color: #fff;
174
+ position: relative;
175
+ border-radius: 0;
176
+ padding-inline: 28px 22px;
177
+ margin: 0;
178
+ width: max-content;
179
+ height: 46px;
180
+ line-height: 46px;
181
+ margin-block: 1px;
182
+ overflow: unset;
183
+
184
+ &::before {
185
+ content: '';
186
+ position: absolute;
187
+ left: 14px;
188
+ top: 50%;
189
+ transform: translateY(-50%);
190
+ width: 4px;
191
+ height: 4px;
192
+ border-radius: 50%;
193
+ background-color: rgba(255, 255, 255, 85%);
194
+ }
195
+
196
+ &::after {
197
+ content: '';
198
+ position: absolute;
199
+ left: 50%;
200
+ bottom: -1px;
201
+ width: 80%;
202
+ transform: translateX(-50%);
203
+ height: 1px;
204
+ background-color: rgba(255, 255, 255, 0.25);
205
+ z-index: 1;
206
+ }
207
+
208
+ &:last-child::after {
209
+ content: none;
210
+ }
211
+ }
212
+
213
+ .ant-menu-item-active,
214
+ .ant-menu-item-selected {
215
+ background: linear-gradient(90deg, #06a168, #2a50dc);
216
+ }
217
+
218
+ .ant-menu-item-selected {
219
+ color: #00ffca;
220
+
221
+ &::before {
222
+ background-color: #00ffca;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }