1 | var __rest = this && this.__rest || function (s, e) {
|
2 | var t = {};
|
3 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
4 | if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
5 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
6 | }
|
7 | return t;
|
8 | };
|
9 | import { useMemo } from 'react';
|
10 | function route2item(route) {
|
11 | const {
|
12 | breadcrumbName,
|
13 | children
|
14 | } = route,
|
15 | rest = __rest(route, ["breadcrumbName", "children"]);
|
16 | const clone = Object.assign({
|
17 | title: breadcrumbName
|
18 | }, rest);
|
19 | if (children) {
|
20 | clone.menu = {
|
21 | items: children.map(_a => {
|
22 | var {
|
23 | breadcrumbName: itemBreadcrumbName
|
24 | } = _a,
|
25 | itemProps = __rest(_a, ["breadcrumbName"]);
|
26 | return Object.assign(Object.assign({}, itemProps), {
|
27 | title: itemBreadcrumbName
|
28 | });
|
29 | })
|
30 | };
|
31 | }
|
32 | return clone;
|
33 | }
|
34 | export default function useItems(items, routes) {
|
35 | return useMemo(() => {
|
36 | if (items) {
|
37 | return items;
|
38 | }
|
39 | if (routes) {
|
40 | return routes.map(route2item);
|
41 | }
|
42 | return null;
|
43 | }, [items, routes]);
|
44 | } |
\ | No newline at end of file |