@teamias/pro-layout 0.0.18 → 0.0.19
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/dist/markdowns/example1/BasicProLayoutBusiness/index.js +9 -4
- package/dist/markdowns/example1/BasicProLayoutBusiness/pages/PlaceholderElement.d.ts +1 -0
- package/dist/markdowns/example1/BasicProLayoutBusiness/pages/PlaceholderElement.js +17 -0
- package/dist/markdowns/example1/MenuItemDemo/index.d.ts +2 -0
- package/dist/markdowns/example1/MenuItemDemo/index.js +248 -0
- package/dist/pro-layout/components/KeepAlive/KeepAliveClass.d.ts +2 -2
- package/dist/pro-layout/components/Menu/index.js +16 -10
- package/dist/pro-layout/core/index.js +4 -1
- package/dist/pro-layout/types/index.d.ts +12 -0
- package/dist/pro-layout/utils/menu.d.ts +2 -2
- package/dist/pro-layout/utils/menu.js +9 -1
- package/dist/pro-layout-business/components/MenuItem.d.ts +9 -0
- package/dist/pro-layout-business/components/MenuItem.js +113 -0
- package/dist/pro-layout-business/hooks/use-service.d.ts +5 -1
- package/dist/pro-layout-business/hooks/use-service.js +6 -0
- package/dist/pro-layout-business/index.d.ts +2 -1
- package/dist/pro-layout-business/index.js +2 -1
- package/package.json +1 -1
|
@@ -3,12 +3,13 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
|
|
|
3
3
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
4
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
5
|
import { getLocalStorageItem } from "../../../pro-layout/utils";
|
|
6
|
-
import { LOCAL_STORAGE, ProLayoutBusiness } from "../../..";
|
|
6
|
+
import { LOCAL_STORAGE, MenuItem, ProLayoutBusiness } from "../../..";
|
|
7
7
|
import { RexProConfigProvider } from '@teamias/rex-design';
|
|
8
8
|
import { message } from 'antd';
|
|
9
9
|
import { useEffect } from 'react';
|
|
10
10
|
import ReactDom from 'react-dom';
|
|
11
11
|
import { MemoryRouter } from 'react-router-dom';
|
|
12
|
+
import { PlaceholderElement } from "./pages/PlaceholderElement";
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
var BasicProLayout = function BasicProLayout() {
|
|
14
15
|
return /*#__PURE__*/_jsx(RexProConfigProvider, {
|
|
@@ -67,9 +68,13 @@ var BasicProLayout = function BasicProLayout() {
|
|
|
67
68
|
projectId: "2"
|
|
68
69
|
// pageComponentMap={pageComponentMap}
|
|
69
70
|
,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
renderMenuItem: function renderMenuItem(item, type) {
|
|
72
|
+
return /*#__PURE__*/_jsx(MenuItem, {
|
|
73
|
+
item: item,
|
|
74
|
+
type: type
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
placeholderElement: /*#__PURE__*/_jsx(PlaceholderElement, {})
|
|
73
78
|
})
|
|
74
79
|
})
|
|
75
80
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PlaceholderElement: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useLayoutContext } from "../../../..";
|
|
2
|
+
import { useLocation } from 'react-router-dom';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
export var PlaceholderElement = function PlaceholderElement() {
|
|
6
|
+
var location = useLocation();
|
|
7
|
+
var layoutContext = useLayoutContext();
|
|
8
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
9
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
10
|
+
children: location.pathname
|
|
11
|
+
}), /*#__PURE__*/_jsxs("pre", {
|
|
12
|
+
children: ["permissions: ", JSON.stringify(layoutContext.permissions, null, 2)]
|
|
13
|
+
}), /*#__PURE__*/_jsxs("pre", {
|
|
14
|
+
children: ["permissionsRaw: ", JSON.stringify(layoutContext.permissionsRaw, null, 2)]
|
|
15
|
+
})]
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,248 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
import { LayoutContextProvide, MenuItem, useLayoutContext } from "../../..";
|
|
6
|
+
import { RexProConfigProvider } from '@teamias/rex-design';
|
|
7
|
+
import { ConfigProvider, Menu, Space, Tag } from 'antd';
|
|
8
|
+
import zhCN from 'antd/locale/zh_CN';
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
import ReactDom from 'react-dom';
|
|
11
|
+
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
|
|
12
|
+
|
|
13
|
+
// 模拟菜单数据
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
var mockMenuItems = [{
|
|
17
|
+
key: '/home',
|
|
18
|
+
label: '首页',
|
|
19
|
+
raw: {
|
|
20
|
+
id: '1',
|
|
21
|
+
title: '首页',
|
|
22
|
+
routing: '/home',
|
|
23
|
+
menu_type: 'menu'
|
|
24
|
+
},
|
|
25
|
+
paths: ['home'],
|
|
26
|
+
'data-menu-id': '',
|
|
27
|
+
'data-key': ''
|
|
28
|
+
}, {
|
|
29
|
+
key: '/user',
|
|
30
|
+
label: '用户管理',
|
|
31
|
+
raw: {
|
|
32
|
+
id: '2',
|
|
33
|
+
title: '用户管理',
|
|
34
|
+
routing: '/user',
|
|
35
|
+
menu_type: 'menu'
|
|
36
|
+
},
|
|
37
|
+
paths: ['user'],
|
|
38
|
+
'data-menu-id': '',
|
|
39
|
+
'data-key': ''
|
|
40
|
+
}, {
|
|
41
|
+
key: '/settings',
|
|
42
|
+
label: '系统设置',
|
|
43
|
+
raw: {
|
|
44
|
+
id: '3',
|
|
45
|
+
title: '系统设置',
|
|
46
|
+
routing: '/settings',
|
|
47
|
+
menu_type: 'menu'
|
|
48
|
+
},
|
|
49
|
+
paths: ['settings'],
|
|
50
|
+
'data-menu-id': '',
|
|
51
|
+
'data-key': ''
|
|
52
|
+
}];
|
|
53
|
+
|
|
54
|
+
// 模拟权限数据
|
|
55
|
+
var mockPermissions = {
|
|
56
|
+
'/home': {
|
|
57
|
+
data: [{
|
|
58
|
+
node_id: ['1'],
|
|
59
|
+
code: 'home:view',
|
|
60
|
+
title: '查看首页'
|
|
61
|
+
}, {
|
|
62
|
+
node_id: ['2'],
|
|
63
|
+
code: 'home:edit',
|
|
64
|
+
title: '编辑首页'
|
|
65
|
+
}]
|
|
66
|
+
},
|
|
67
|
+
'/user': {
|
|
68
|
+
data: [{
|
|
69
|
+
node_id: ['3'],
|
|
70
|
+
code: 'user:view',
|
|
71
|
+
title: '查看用户'
|
|
72
|
+
}, {
|
|
73
|
+
node_id: ['4'],
|
|
74
|
+
code: 'user:add',
|
|
75
|
+
title: '添加用户'
|
|
76
|
+
}, {
|
|
77
|
+
node_id: ['5'],
|
|
78
|
+
code: 'user:delete',
|
|
79
|
+
title: '删除用户'
|
|
80
|
+
}]
|
|
81
|
+
},
|
|
82
|
+
'/settings': {
|
|
83
|
+
data: [{
|
|
84
|
+
node_id: ['6'],
|
|
85
|
+
code: 'settings:view',
|
|
86
|
+
title: '查看设置'
|
|
87
|
+
}, {
|
|
88
|
+
node_id: ['7'],
|
|
89
|
+
code: 'settings:edit',
|
|
90
|
+
title: '修改设置'
|
|
91
|
+
}]
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// 页面内容组件
|
|
96
|
+
var PageContent = function PageContent(_ref) {
|
|
97
|
+
var _disabledReload, _location$state;
|
|
98
|
+
var title = _ref.title;
|
|
99
|
+
var location = useLocation();
|
|
100
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
101
|
+
style: {
|
|
102
|
+
padding: 16,
|
|
103
|
+
background: '#f5f5f5',
|
|
104
|
+
borderRadius: 4
|
|
105
|
+
},
|
|
106
|
+
children: [/*#__PURE__*/_jsx("h3", {
|
|
107
|
+
children: title
|
|
108
|
+
}), /*#__PURE__*/_jsxs("p", {
|
|
109
|
+
children: ["\u5F53\u524D\u8DEF\u5F84: ", location.pathname]
|
|
110
|
+
}), /*#__PURE__*/_jsxs("p", {
|
|
111
|
+
style: {
|
|
112
|
+
color: '#666',
|
|
113
|
+
fontSize: 12
|
|
114
|
+
},
|
|
115
|
+
children: ["\uD83D\uDCA1 state.disabledReload: ", String((_disabledReload = (_location$state = location.state) === null || _location$state === void 0 ? void 0 : _location$state.disabledReload) !== null && _disabledReload !== void 0 ? _disabledReload : 'undefined')]
|
|
116
|
+
})]
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// 权限展示组件
|
|
121
|
+
var PermissionDisplay = function PermissionDisplay() {
|
|
122
|
+
var _layoutContext$permis, _layoutContext$permis2;
|
|
123
|
+
var layoutContext = useLayoutContext() || {};
|
|
124
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
125
|
+
style: {
|
|
126
|
+
marginTop: 16
|
|
127
|
+
},
|
|
128
|
+
children: [/*#__PURE__*/_jsx("h4", {
|
|
129
|
+
children: "\u5F53\u524D\u9875\u9762\u6743\u9650\uFF1A"
|
|
130
|
+
}), /*#__PURE__*/_jsx(Space, {
|
|
131
|
+
wrap: true,
|
|
132
|
+
children: ((layoutContext === null || layoutContext === void 0 || (_layoutContext$permis = layoutContext.permissions) === null || _layoutContext$permis === void 0 ? void 0 : _layoutContext$permis.length) || 0) > 0 ? layoutContext === null || layoutContext === void 0 || (_layoutContext$permis2 = layoutContext.permissions) === null || _layoutContext$permis2 === void 0 ? void 0 : _layoutContext$permis2.map(function (code) {
|
|
133
|
+
return /*#__PURE__*/_jsx(Tag, {
|
|
134
|
+
color: "blue",
|
|
135
|
+
children: code
|
|
136
|
+
}, code);
|
|
137
|
+
}) : /*#__PURE__*/_jsx("span", {
|
|
138
|
+
style: {
|
|
139
|
+
color: '#999'
|
|
140
|
+
},
|
|
141
|
+
children: "\u6682\u65E0\u6743\u9650\u6570\u636E"
|
|
142
|
+
})
|
|
143
|
+
})]
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// 自定义菜单项(使用内置 MenuItem)
|
|
148
|
+
var CustomMenuWithMenuItem = function CustomMenuWithMenuItem() {
|
|
149
|
+
var location = useLocation();
|
|
150
|
+
var selectedKeys = [location.pathname];
|
|
151
|
+
return /*#__PURE__*/_jsx(Menu, {
|
|
152
|
+
mode: "horizontal",
|
|
153
|
+
selectedKeys: selectedKeys,
|
|
154
|
+
items: mockMenuItems.map(function (item) {
|
|
155
|
+
return {
|
|
156
|
+
key: item.key,
|
|
157
|
+
label: /*#__PURE__*/_jsx(MenuItem, {
|
|
158
|
+
item: item,
|
|
159
|
+
type: "menu"
|
|
160
|
+
})
|
|
161
|
+
};
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
var MenuItemDemo = function MenuItemDemo() {
|
|
166
|
+
return /*#__PURE__*/_jsx(ConfigProvider, {
|
|
167
|
+
locale: zhCN,
|
|
168
|
+
children: /*#__PURE__*/_jsx(RexProConfigProvider, {
|
|
169
|
+
value: {
|
|
170
|
+
apiClient: function () {
|
|
171
|
+
var _apiClient = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, params) {
|
|
172
|
+
var path;
|
|
173
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
174
|
+
while (1) switch (_context.prev = _context.next) {
|
|
175
|
+
case 0:
|
|
176
|
+
path = (params === null || params === void 0 ? void 0 : params.path) || '/home';
|
|
177
|
+
return _context.abrupt("return", mockPermissions[path] || {
|
|
178
|
+
data: []
|
|
179
|
+
});
|
|
180
|
+
case 2:
|
|
181
|
+
case "end":
|
|
182
|
+
return _context.stop();
|
|
183
|
+
}
|
|
184
|
+
}, _callee);
|
|
185
|
+
}));
|
|
186
|
+
function apiClient(_x, _x2) {
|
|
187
|
+
return _apiClient.apply(this, arguments);
|
|
188
|
+
}
|
|
189
|
+
return apiClient;
|
|
190
|
+
}()
|
|
191
|
+
},
|
|
192
|
+
children: /*#__PURE__*/_jsx(LayoutContextProvide, {
|
|
193
|
+
basename: "/",
|
|
194
|
+
projectId: "demo",
|
|
195
|
+
userInfo: {
|
|
196
|
+
id: '1',
|
|
197
|
+
username: 'demo-user'
|
|
198
|
+
},
|
|
199
|
+
children: /*#__PURE__*/_jsx(MemoryRouter, {
|
|
200
|
+
initialEntries: ['/home'],
|
|
201
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
202
|
+
style: {
|
|
203
|
+
padding: 20
|
|
204
|
+
},
|
|
205
|
+
children: /*#__PURE__*/_jsxs(Space, {
|
|
206
|
+
direction: "vertical",
|
|
207
|
+
size: "large",
|
|
208
|
+
style: {
|
|
209
|
+
width: '100%'
|
|
210
|
+
},
|
|
211
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
212
|
+
children: [/*#__PURE__*/_jsx("h4", {
|
|
213
|
+
children: "\u4F7F\u7528\u5185\u7F6E MenuItem \u7EC4\u4EF6\uFF1A"
|
|
214
|
+
}), /*#__PURE__*/_jsx(CustomMenuWithMenuItem, {})]
|
|
215
|
+
}), /*#__PURE__*/_jsxs(Routes, {
|
|
216
|
+
children: [/*#__PURE__*/_jsx(Route, {
|
|
217
|
+
path: "/home",
|
|
218
|
+
element: /*#__PURE__*/_jsx(PageContent, {
|
|
219
|
+
title: "\u9996\u9875"
|
|
220
|
+
})
|
|
221
|
+
}), /*#__PURE__*/_jsx(Route, {
|
|
222
|
+
path: "/user",
|
|
223
|
+
element: /*#__PURE__*/_jsx(PageContent, {
|
|
224
|
+
title: "\u7528\u6237\u7BA1\u7406"
|
|
225
|
+
})
|
|
226
|
+
}), /*#__PURE__*/_jsx(Route, {
|
|
227
|
+
path: "/settings",
|
|
228
|
+
element: /*#__PURE__*/_jsx(PageContent, {
|
|
229
|
+
title: "\u7CFB\u7EDF\u8BBE\u7F6E"
|
|
230
|
+
})
|
|
231
|
+
})]
|
|
232
|
+
}), /*#__PURE__*/_jsx(PermissionDisplay, {})]
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
export default (function () {
|
|
241
|
+
useEffect(function () {
|
|
242
|
+
var dom = document.getElementById('pro-layout');
|
|
243
|
+
ReactDom.render( /*#__PURE__*/_jsx(MenuItemDemo, {}), dom);
|
|
244
|
+
}, []);
|
|
245
|
+
return /*#__PURE__*/_jsx("div", {
|
|
246
|
+
id: "pro-layout"
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -17,7 +17,7 @@ export declare class KeepAliveClass {
|
|
|
17
17
|
updateAllComponent(type?: 'all' | 'pagesHook' | 'context'): Promise<void>;
|
|
18
18
|
/** 获取页面数据 */
|
|
19
19
|
getPages(): (import("react-router-dom").Location & {
|
|
20
|
-
pageStatus:
|
|
20
|
+
pageStatus: 200 | 403 | 404;
|
|
21
21
|
pageTitle: string;
|
|
22
22
|
intlMenuConfig?: {
|
|
23
23
|
id: string;
|
|
@@ -45,7 +45,7 @@ export declare class KeepAliveClass {
|
|
|
45
45
|
useLifeCycle: (callback: IPageLifeCycleCallback) => void;
|
|
46
46
|
/** 获取缓存页面数组 */
|
|
47
47
|
useKeepAlivePages: () => (import("react-router-dom").Location & {
|
|
48
|
-
pageStatus:
|
|
48
|
+
pageStatus: 200 | 403 | 404;
|
|
49
49
|
pageTitle: string;
|
|
50
50
|
intlMenuConfig?: {
|
|
51
51
|
id: string;
|
|
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
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; }
|
|
11
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; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import { useUpdateEffect } from 'ahooks';
|
|
13
|
+
import { useDebounceFn, useUpdateEffect } from 'ahooks';
|
|
14
14
|
import { Menu as AntdMenu, Tabs, theme } from 'antd';
|
|
15
15
|
import React, { useLayoutEffect, useRef, useState } from 'react';
|
|
16
16
|
import { useLocation } from 'react-router-dom';
|
|
@@ -40,8 +40,14 @@ export var Menu = function Menu(_ref) {
|
|
|
40
40
|
state = _useRef.current;
|
|
41
41
|
var _useState = useState({}),
|
|
42
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
-
|
|
44
|
-
var
|
|
43
|
+
updateRaw = _useState2[1];
|
|
44
|
+
var hasRightMenu = state.actives.length && (menuData === null || menuData === void 0 || (_menuData$rootChildre = menuData.rootChildrenMap[state.cacheActives[0] || state.actives.at(-1) || '']) === null || _menuData$rootChildre === void 0 ? void 0 : _menuData$rootChildre.length);
|
|
45
|
+
var update = useDebounceFn(function () {
|
|
46
|
+
return updateRaw({});
|
|
47
|
+
}, {
|
|
48
|
+
wait: 0,
|
|
49
|
+
leading: true
|
|
50
|
+
}).run;
|
|
45
51
|
|
|
46
52
|
/** 匹配 */
|
|
47
53
|
var matchPath = function matchPath() {
|
|
@@ -56,11 +62,9 @@ export var Menu = function Menu(_ref) {
|
|
|
56
62
|
paths.push("/".concat(arr.slice(0, len).join('/')));
|
|
57
63
|
len--;
|
|
58
64
|
}
|
|
59
|
-
state.actives = paths;
|
|
65
|
+
state.actives = paths.length ? paths : ['/'];
|
|
60
66
|
state.cacheActives = [];
|
|
61
|
-
|
|
62
|
-
// console.log(paths);
|
|
63
|
-
update({});
|
|
67
|
+
update();
|
|
64
68
|
};
|
|
65
69
|
useLayoutEffect(function () {
|
|
66
70
|
matchPath();
|
|
@@ -70,7 +74,7 @@ export var Menu = function Menu(_ref) {
|
|
|
70
74
|
}, [pathname]);
|
|
71
75
|
if (layoutContext.hideMenu) return /*#__PURE__*/_jsx(_Fragment, {});
|
|
72
76
|
return /*#__PURE__*/_jsx(MenuContent, {
|
|
73
|
-
"data-aside-width": collapsed ? minAsideWidth :
|
|
77
|
+
"data-aside-width": collapsed ? minAsideWidth : hasRightMenu ? asideWidth : minAsideWidth,
|
|
74
78
|
"data-min-aside-width": minAsideWidth,
|
|
75
79
|
style: {
|
|
76
80
|
height: height,
|
|
@@ -113,13 +117,15 @@ export var Menu = function Menu(_ref) {
|
|
|
113
117
|
});
|
|
114
118
|
}),
|
|
115
119
|
onTabClick: function onTabClick(e) {
|
|
120
|
+
// console.log('左侧菜单点击', e);
|
|
121
|
+
|
|
116
122
|
state.cacheActives = [e];
|
|
117
123
|
state.actives = [e];
|
|
118
|
-
update(
|
|
124
|
+
update();
|
|
119
125
|
}
|
|
120
126
|
}), /*#__PURE__*/_jsx("div", {
|
|
121
127
|
className: "custom-menu-box",
|
|
122
|
-
children:
|
|
128
|
+
children: hasRightMenu ? /*#__PURE__*/_jsx(AntdMenu, {
|
|
123
129
|
mode: "inline"
|
|
124
130
|
// defaultSelectedKeys={['231']}
|
|
125
131
|
,
|
|
@@ -35,6 +35,7 @@ var InlineProLayout = function InlineProLayout(_ref) {
|
|
|
35
35
|
projectTitle = _ref.projectTitle,
|
|
36
36
|
loginBgImg = _ref.loginBgImg,
|
|
37
37
|
coverPageContent = _ref.coverPageContent,
|
|
38
|
+
renderMenuItem = _ref.renderMenuItem,
|
|
38
39
|
renderTopRightContent = _ref.renderTopRightContent,
|
|
39
40
|
requestUserInfoMenuData = _ref.requestUserInfoMenuData,
|
|
40
41
|
renderSelectLang = _ref.renderSelectLang,
|
|
@@ -59,7 +60,7 @@ var InlineProLayout = function InlineProLayout(_ref) {
|
|
|
59
60
|
_context.next = 6;
|
|
60
61
|
return layoutContext.updateData({
|
|
61
62
|
userInfo: res.userInfo,
|
|
62
|
-
routeMenu: handleMenuData(res.menuData)
|
|
63
|
+
routeMenu: handleMenuData(res.menuData, renderMenuItem)
|
|
63
64
|
});
|
|
64
65
|
case 6:
|
|
65
66
|
_context.next = 11;
|
|
@@ -213,6 +214,7 @@ export var ProLayout = function ProLayout(_ref4) {
|
|
|
213
214
|
placeholderElement = _ref4.placeholderElement,
|
|
214
215
|
coverPageContent = _ref4.coverPageContent,
|
|
215
216
|
hideMenu = _ref4.hideMenu,
|
|
217
|
+
renderMenuItem = _ref4.renderMenuItem,
|
|
216
218
|
renderTopRightContent = _ref4.renderTopRightContent,
|
|
217
219
|
renderSelectLang = _ref4.renderSelectLang,
|
|
218
220
|
requestUserInfoMenuData = _ref4.requestUserInfoMenuData,
|
|
@@ -233,6 +235,7 @@ export var ProLayout = function ProLayout(_ref4) {
|
|
|
233
235
|
placeholderElement: placeholderElement,
|
|
234
236
|
hideMenu: hideMenu,
|
|
235
237
|
children: /*#__PURE__*/_jsx(InlineProLayout, {
|
|
238
|
+
renderMenuItem: renderMenuItem,
|
|
236
239
|
renderSelectLang: renderSelectLang,
|
|
237
240
|
renderTopRightContent: renderTopRightContent,
|
|
238
241
|
projectTitle: projectTitle,
|
|
@@ -35,6 +35,8 @@ export interface IProLayoutProps extends Pick<TLayoutContext, 'hideMenu' | 'proj
|
|
|
35
35
|
/** 公共内容 */
|
|
36
36
|
common?: ReactNode;
|
|
37
37
|
};
|
|
38
|
+
/** 自定义渲染菜单项 */
|
|
39
|
+
renderMenuItem?: (item: TMenuData, type: 'menu' | 'dir') => ReactNode;
|
|
38
40
|
/** 覆盖页面内容 */
|
|
39
41
|
coverPageContent?: ReactNode;
|
|
40
42
|
/** 渲染多语言选择控件 */
|
|
@@ -84,6 +86,8 @@ export type TLayoutContext = {
|
|
|
84
86
|
hideMenu?: boolean;
|
|
85
87
|
/** 当前用户权限 */
|
|
86
88
|
permissions?: string[];
|
|
89
|
+
/** 当前用户权限(原始数据) */
|
|
90
|
+
permissionsRaw?: TApiPermission[];
|
|
87
91
|
/** 当前用户菜单 */
|
|
88
92
|
routeMenu?: {
|
|
89
93
|
allKeys: Record<string, true>;
|
|
@@ -159,6 +163,14 @@ export type TApiMenuManagement = {
|
|
|
159
163
|
/** 菜单类型 */
|
|
160
164
|
menu_type: 'dir' | 'menu' | 'button';
|
|
161
165
|
};
|
|
166
|
+
export type TApiPermission = {
|
|
167
|
+
/** 权限编码 */
|
|
168
|
+
code: string;
|
|
169
|
+
/** 权限名称 */
|
|
170
|
+
title: string;
|
|
171
|
+
/** 关联节点ID */
|
|
172
|
+
node_id: string[];
|
|
173
|
+
};
|
|
162
174
|
export type TApiUserInfo = {
|
|
163
175
|
/** 用户名 */
|
|
164
176
|
username?: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { TApiMenuManagement, TMenuData } from '../types';
|
|
1
|
+
import { IProLayoutProps, TApiMenuManagement, TMenuData } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* 处理数据菜单数据
|
|
4
4
|
*/
|
|
5
|
-
export declare const handleMenuData: (topData?: TApiMenuManagement[]) => {
|
|
5
|
+
export declare const handleMenuData: (topData?: TApiMenuManagement[], renderMenuItem?: IProLayoutProps['renderMenuItem']) => {
|
|
6
6
|
allKeys: Record<string, true>;
|
|
7
7
|
rawData: TApiMenuManagement[];
|
|
8
8
|
home: TMenuData;
|
|
@@ -13,6 +13,9 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
*/
|
|
14
14
|
export var handleMenuData = function handleMenuData() {
|
|
15
15
|
var topData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
16
|
+
var renderMenuItem
|
|
17
|
+
// pageComponentMap: TLayoutContext['pageComponentMap'],
|
|
18
|
+
= arguments.length > 1 ? arguments[1] : undefined;
|
|
16
19
|
// const item = {
|
|
17
20
|
// label: data.name,
|
|
18
21
|
// };
|
|
@@ -62,7 +65,7 @@ export var handleMenuData = function handleMenuData() {
|
|
|
62
65
|
// menu类型 或 静态数据 都进行收集
|
|
63
66
|
if (old.menu_type === 'menu') {
|
|
64
67
|
// 菜单页面收集
|
|
65
|
-
item.label = /*#__PURE__*/_jsxs(_Fragment, {
|
|
68
|
+
item.label = (renderMenuItem === null || renderMenuItem === void 0 ? void 0 : renderMenuItem(item, 'menu')) || /*#__PURE__*/_jsxs(_Fragment, {
|
|
66
69
|
children: [item.label, /*#__PURE__*/_jsx(Link, {
|
|
67
70
|
to: item.key,
|
|
68
71
|
state: {
|
|
@@ -77,6 +80,11 @@ export var handleMenuData = function handleMenuData() {
|
|
|
77
80
|
// if (typeof item.raw.pageStatus === undefined || item.raw.pageStatus === 0) {
|
|
78
81
|
// item.raw.pageStatus = routeComponentMap.pageComponentMap[item['data-key']] ? 2 : 1;
|
|
79
82
|
// }
|
|
83
|
+
} else {
|
|
84
|
+
// 目录类型
|
|
85
|
+
item.label = (renderMenuItem === null || renderMenuItem === void 0 ? void 0 : renderMenuItem(item, 'dir')) || /*#__PURE__*/_jsx(_Fragment, {
|
|
86
|
+
children: item.label
|
|
87
|
+
});
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
// 递归
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ProLayout } from "../../pro-layout/core";
|
|
2
|
+
import { GetProps } from 'antd';
|
|
3
|
+
import { FC } from 'react';
|
|
4
|
+
export declare const MenuItem: FC<IProps>;
|
|
5
|
+
interface IProps {
|
|
6
|
+
item: Parameters<NonNullable<GetProps<typeof ProLayout>['renderMenuItem']>>[0];
|
|
7
|
+
type: Parameters<NonNullable<GetProps<typeof ProLayout>['renderMenuItem']>>[1];
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
import { useLayoutContext } from "../../pro-layout/context";
|
|
6
|
+
import { useDebounceEffect } from 'ahooks';
|
|
7
|
+
import { Link, useLocation } from 'react-router-dom';
|
|
8
|
+
import { useService } from "../hooks/use-service";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
var cachedPermissionsApi = function () {
|
|
13
|
+
var cache = {};
|
|
14
|
+
return /*#__PURE__*/function () {
|
|
15
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, path) {
|
|
16
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
17
|
+
while (1) switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
if (!cache[path]) {
|
|
20
|
+
_context.next = 4;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
_context.next = 3;
|
|
24
|
+
return cache[path];
|
|
25
|
+
case 3:
|
|
26
|
+
return _context.abrupt("return", _context.sent);
|
|
27
|
+
case 4:
|
|
28
|
+
_context.prev = 4;
|
|
29
|
+
cache[path] = api(path);
|
|
30
|
+
_context.next = 8;
|
|
31
|
+
return cache[path];
|
|
32
|
+
case 8:
|
|
33
|
+
return _context.abrupt("return", _context.sent);
|
|
34
|
+
case 11:
|
|
35
|
+
_context.prev = 11;
|
|
36
|
+
_context.t0 = _context["catch"](4);
|
|
37
|
+
cache[path] = null;
|
|
38
|
+
return _context.abrupt("return", {
|
|
39
|
+
data: []
|
|
40
|
+
});
|
|
41
|
+
case 15:
|
|
42
|
+
case "end":
|
|
43
|
+
return _context.stop();
|
|
44
|
+
}
|
|
45
|
+
}, _callee, null, [[4, 11]]);
|
|
46
|
+
}));
|
|
47
|
+
return function (_x, _x2) {
|
|
48
|
+
return _ref.apply(this, arguments);
|
|
49
|
+
};
|
|
50
|
+
}();
|
|
51
|
+
}();
|
|
52
|
+
export var MenuItem = function MenuItem(_ref2) {
|
|
53
|
+
var item = _ref2.item,
|
|
54
|
+
type = _ref2.type;
|
|
55
|
+
var service = useService();
|
|
56
|
+
var location = useLocation();
|
|
57
|
+
var layoutContext = useLayoutContext();
|
|
58
|
+
var label = item.raw.title;
|
|
59
|
+
var updateMenuPermission = /*#__PURE__*/function () {
|
|
60
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path) {
|
|
61
|
+
var _res$data;
|
|
62
|
+
var res;
|
|
63
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
64
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
65
|
+
case 0:
|
|
66
|
+
layoutContext.updateData({
|
|
67
|
+
permissions: [],
|
|
68
|
+
permissionsRaw: []
|
|
69
|
+
});
|
|
70
|
+
_context2.next = 3;
|
|
71
|
+
return cachedPermissionsApi(service.getPagePermissionsApi, path);
|
|
72
|
+
case 3:
|
|
73
|
+
res = _context2.sent;
|
|
74
|
+
layoutContext.updateData({
|
|
75
|
+
permissions: (res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.map(function (ii) {
|
|
76
|
+
return ii.code;
|
|
77
|
+
})) || [],
|
|
78
|
+
permissionsRaw: (res === null || res === void 0 ? void 0 : res.data) || []
|
|
79
|
+
});
|
|
80
|
+
case 5:
|
|
81
|
+
case "end":
|
|
82
|
+
return _context2.stop();
|
|
83
|
+
}
|
|
84
|
+
}, _callee2);
|
|
85
|
+
}));
|
|
86
|
+
return function updateMenuPermission(_x3) {
|
|
87
|
+
return _ref3.apply(this, arguments);
|
|
88
|
+
};
|
|
89
|
+
}();
|
|
90
|
+
|
|
91
|
+
// 监听页面变化,更新权限数据
|
|
92
|
+
useDebounceEffect(function () {
|
|
93
|
+
if (item.key === location.pathname) {
|
|
94
|
+
updateMenuPermission(location.pathname);
|
|
95
|
+
}
|
|
96
|
+
}, [location], {
|
|
97
|
+
wait: 16
|
|
98
|
+
});
|
|
99
|
+
if (type === 'menu') {
|
|
100
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
101
|
+
children: [label, /*#__PURE__*/_jsx(Link, {
|
|
102
|
+
to: item.key,
|
|
103
|
+
state: {
|
|
104
|
+
disabledReload: true
|
|
105
|
+
}
|
|
106
|
+
})]
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
110
|
+
children: label
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TApiMenuManagement, TApiUserInfo } from "../..";
|
|
1
|
+
import { TApiMenuManagement, TApiPermission, TApiUserInfo } from "../..";
|
|
2
2
|
export declare const useService: () => {
|
|
3
3
|
/** 登录接口 */
|
|
4
4
|
loginApi: (params: {
|
|
@@ -33,4 +33,8 @@ export declare const useService: () => {
|
|
|
33
33
|
}>;
|
|
34
34
|
/** 切换角色接口 */
|
|
35
35
|
toggleJobApi: (model_id: string, job_id: number) => Promise<unknown>;
|
|
36
|
+
/** 获取页面权限 */
|
|
37
|
+
getPagePermissionsApi: (path: string) => Promise<{
|
|
38
|
+
data: TApiPermission[];
|
|
39
|
+
}>;
|
|
36
40
|
};
|
|
@@ -59,6 +59,12 @@ export var useService = function useService() {
|
|
|
59
59
|
model_id: model_id,
|
|
60
60
|
job_id: job_id
|
|
61
61
|
});
|
|
62
|
+
},
|
|
63
|
+
/** 获取页面权限 */
|
|
64
|
+
getPagePermissionsApi: function getPagePermissionsApi(path) {
|
|
65
|
+
return packageApiClient('/grpc/menu/event', {
|
|
66
|
+
path: path
|
|
67
|
+
});
|
|
62
68
|
}
|
|
63
69
|
};
|
|
64
70
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ProLayout } from "..";
|
|
2
2
|
import { GetProps } from 'antd';
|
|
3
3
|
import { FC } from 'react';
|
|
4
|
+
import { MenuItem } from './components/MenuItem';
|
|
4
5
|
import { RoleSelect } from './components/RoleSelect';
|
|
5
6
|
export declare const ProLayoutBusiness: FC<IProLayoutBusinessProps>;
|
|
6
|
-
export { RoleSelect };
|
|
7
|
+
export { MenuItem, RoleSelect };
|
|
7
8
|
type IProLayoutBusinessProps = Omit<GetProps<typeof ProLayout>, 'renderTopRightContent' | 'requestUserInfoMenuData' | 'onLogin' | 'onLogout'>;
|
|
@@ -14,6 +14,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
14
14
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
15
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
16
|
import { ProLayoutMemo } from "./..";
|
|
17
|
+
import { MenuItem } from "./components/MenuItem";
|
|
17
18
|
import { RoleSelect } from "./components/RoleSelect";
|
|
18
19
|
import { useService } from "./hooks/use-service";
|
|
19
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -83,4 +84,4 @@ export var ProLayoutBusiness = function ProLayoutBusiness(props) {
|
|
|
83
84
|
}
|
|
84
85
|
}));
|
|
85
86
|
};
|
|
86
|
-
export { RoleSelect };
|
|
87
|
+
export { MenuItem, RoleSelect };
|