@allahjs/umi-plugin-layout-lite 0.1.0 → 0.1.1
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 +2 -0
- package/dist/Layout.js +20 -22
- package/dist/runtime.js +4 -25
- package/package.json +4 -4
- /package/dist/{index.js → index.cjs} +0 -0
package/README.md
CHANGED
package/dist/Layout.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var proComponents = require('@ant-design/pro-components');
|
|
7
|
-
var antd = require('antd');
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useLocation, useNavigate, useAppData, useModel, matchRoutes, Outlet, Link, history } from '@umijs/max';
|
|
4
|
+
import { ProLayout } from '@ant-design/pro-components';
|
|
5
|
+
import { Result, Button, Spin } from 'antd';
|
|
8
6
|
|
|
9
7
|
const Exception = props => {
|
|
10
8
|
var _a, _b;
|
|
11
9
|
return ((!props.route && (props.noFound || props.notFound)) ||
|
|
12
10
|
(((_a = props.route) === null || _a === void 0 ? void 0 : _a.unaccessible) &&
|
|
13
11
|
(props.unAccessible || props.noAccessible)) ||
|
|
14
|
-
((!props.route || ((_b = props.route) === null || _b === void 0 ? void 0 : _b.unaccessible)) && (
|
|
12
|
+
((!props.route || ((_b = props.route) === null || _b === void 0 ? void 0 : _b.unaccessible)) && (jsx(Result, { status: props.route ? '403' : '404', title: props.route ? '403' : '404', subTitle: props.route ? '抱歉,你无权访问该页面' : '抱歉,你访问的页面不存在', extra: jsx(Button, { type: "primary", onClick: () => history.push('/'), children: "\u8FD4\u56DE\u9996\u9875" }) }))) ||
|
|
15
13
|
props.children);
|
|
16
14
|
};
|
|
17
15
|
function getRightRenderContent(opts) {
|
|
@@ -19,7 +17,7 @@ function getRightRenderContent(opts) {
|
|
|
19
17
|
return opts.runtimeConfig.rightRender(opts.initialState, opts.setInitialState, opts.runtimeConfig);
|
|
20
18
|
}
|
|
21
19
|
if (opts.loading) {
|
|
22
|
-
return
|
|
20
|
+
return jsx(Spin, { size: "small", style: { marginLeft: 8, marginRight: 8 } });
|
|
23
21
|
}
|
|
24
22
|
return null;
|
|
25
23
|
}
|
|
@@ -62,10 +60,10 @@ const mapRoutes = (routes) => {
|
|
|
62
60
|
});
|
|
63
61
|
};
|
|
64
62
|
function LayoutLite(props) {
|
|
65
|
-
const location =
|
|
66
|
-
const navigate =
|
|
67
|
-
const { clientRoutes, pluginManager } =
|
|
68
|
-
const initialInfo =
|
|
63
|
+
const location = useLocation();
|
|
64
|
+
const navigate = useNavigate();
|
|
65
|
+
const { clientRoutes, pluginManager } = useAppData();
|
|
66
|
+
const initialInfo = useModel('@@initialState') || {
|
|
69
67
|
initialState: undefined,
|
|
70
68
|
loading: false,
|
|
71
69
|
setInitialState: null,
|
|
@@ -81,7 +79,7 @@ function LayoutLite(props) {
|
|
|
81
79
|
const userConfig = {};
|
|
82
80
|
const newRoutes = filterRoutes(clientRoutes.filter((route) => route.id === 'layout-lite'), route => (route.isLayout && route.id !== 'layout-lite') || !!route.isWrapper);
|
|
83
81
|
const route = mapRoutes(newRoutes)[0];
|
|
84
|
-
const matchedRoute =
|
|
82
|
+
const matchedRoute = useMemo(() => { var _a, _b, _c; return (_c = (_b = (_a = matchRoutes((route === null || route === void 0 ? void 0 : route.children) || [], location.pathname)) === null || _a === void 0 ? void 0 : _a.pop) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.route; }, [route, location.pathname]);
|
|
85
83
|
const renderRightActions = (layoutProps) => {
|
|
86
84
|
const dom = getRightRenderContent({
|
|
87
85
|
runtimeConfig,
|
|
@@ -100,7 +98,7 @@ function LayoutLite(props) {
|
|
|
100
98
|
}
|
|
101
99
|
return dom;
|
|
102
100
|
};
|
|
103
|
-
return (
|
|
101
|
+
return (jsx(ProLayout, { route: route, location: location, title: runtimeConfig.title || 'layout-lite', menu: { locale: runtimeConfig.locale }, onMenuHeaderClick: event => {
|
|
104
102
|
event.stopPropagation();
|
|
105
103
|
event.preventDefault();
|
|
106
104
|
navigate('/');
|
|
@@ -109,19 +107,19 @@ function LayoutLite(props) {
|
|
|
109
107
|
return defaultDom;
|
|
110
108
|
}
|
|
111
109
|
if (menuItemProps.path && location.pathname !== menuItemProps.path) {
|
|
112
|
-
return (
|
|
110
|
+
return (jsx(Link, { to: menuItemProps.path.replace('/*', ''), target: menuItemProps.target, children: defaultDom }));
|
|
113
111
|
}
|
|
114
112
|
return defaultDom;
|
|
115
113
|
}, itemRender: (currentRoute, _, routes) => {
|
|
116
114
|
const label = currentRoute.title || currentRoute.breadcrumbName;
|
|
117
115
|
const lastRoute = routes[routes.length - 1];
|
|
118
116
|
if (lastRoute && (lastRoute.path === currentRoute.path || lastRoute.linkPath === currentRoute.path)) {
|
|
119
|
-
return
|
|
117
|
+
return jsx("span", { children: label });
|
|
120
118
|
}
|
|
121
|
-
return
|
|
122
|
-
}, actionsRender: renderRightActions, ...runtimeConfig, children:
|
|
123
|
-
? runtimeConfig.childrenRender(
|
|
124
|
-
:
|
|
119
|
+
return jsx(Link, { to: currentRoute.path || '/', children: label });
|
|
120
|
+
}, actionsRender: renderRightActions, ...runtimeConfig, children: jsx(Exception, { route: matchedRoute, noFound: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.noFound, notFound: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.notFound, unAccessible: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.unAccessible, noAccessible: runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.noAccessible, children: runtimeConfig.childrenRender
|
|
121
|
+
? runtimeConfig.childrenRender(jsx(Outlet, {}), props)
|
|
122
|
+
: jsx(Outlet, {}) }) }));
|
|
125
123
|
}
|
|
126
124
|
|
|
127
|
-
|
|
125
|
+
export { LayoutLite as default };
|
package/dist/runtime.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var Icons = require('@ant-design/icons');
|
|
5
|
-
|
|
6
|
-
function _interopNamespaceDefault(e) {
|
|
7
|
-
var n = Object.create(null);
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var Icons__namespace = /*#__PURE__*/_interopNamespaceDefault(Icons);
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as Icons from '@ant-design/icons';
|
|
24
3
|
|
|
25
4
|
function formatIcon(name) {
|
|
26
5
|
return name
|
|
@@ -34,11 +13,11 @@ function patchRoutes({ routes }) {
|
|
|
34
13
|
if (!icon || typeof icon !== 'string')
|
|
35
14
|
return;
|
|
36
15
|
const iconName = formatIcon(icon);
|
|
37
|
-
const IconComponent =
|
|
16
|
+
const IconComponent = Icons[iconName] || Icons[`${iconName}Outlined`];
|
|
38
17
|
if (IconComponent) {
|
|
39
18
|
routes[key].icon = React.createElement(IconComponent);
|
|
40
19
|
}
|
|
41
20
|
});
|
|
42
21
|
}
|
|
43
22
|
|
|
44
|
-
|
|
23
|
+
export { patchRoutes };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allahjs/umi-plugin-layout-lite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A lightweight Umi layout plugin with ProLayout and rightContentRender compatibility.",
|
|
5
5
|
"repository": "https://github.com/allah-prime/umi-plugin-layout-lite",
|
|
6
|
-
"main": "dist/index.
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
|
-
"import": "./dist/index.
|
|
16
|
-
"require": "./dist/index.
|
|
15
|
+
"import": "./dist/index.cjs",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
File without changes
|