@lxzy/code-snippet 0.0.11 → 0.0.13
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 +1 -1
- package/routes/menu.ts +6 -0
- package/src/App.tsx +24 -5
- package/src/layouts/index.tsx +18 -9
- package/src/pages/home.tsx +3 -1
- package/src/pages/login.tsx +5 -0
package/package.json
CHANGED
package/routes/menu.ts
CHANGED
package/src/App.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { Suspense, lazy } from 'react';
|
|
2
|
-
import { Switch, Route, Redirect } from 'react-router-dom';
|
|
2
|
+
import { Switch, Route, Redirect, useHistory, useLocation } from 'react-router-dom';
|
|
3
3
|
import { Router } from 'react-router-dom';
|
|
4
4
|
import history from '@/umi';
|
|
5
5
|
import BasicLayout from '@/layouts/index';
|
|
@@ -21,6 +21,28 @@ const loadComponent = (path) => {
|
|
|
21
21
|
return componentCache[path];
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
const parseQuery = (search) => {
|
|
25
|
+
if (!search) return {};
|
|
26
|
+
const params = new URLSearchParams(search);
|
|
27
|
+
const query = {};
|
|
28
|
+
for (const [key, value] of params) {
|
|
29
|
+
query[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return query;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const RouteWrapper = ({ componentPath }) => {
|
|
35
|
+
const routeHistory = useHistory();
|
|
36
|
+
const routeLocation = useLocation();
|
|
37
|
+
const Component = loadComponent(componentPath);
|
|
38
|
+
return (
|
|
39
|
+
<Component
|
|
40
|
+
history={routeHistory}
|
|
41
|
+
location={{ ...routeLocation, query: parseQuery(routeLocation.search) }}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
24
46
|
const App = () => {
|
|
25
47
|
return (
|
|
26
48
|
<Router history={history}>
|
|
@@ -37,10 +59,7 @@ const App = () => {
|
|
|
37
59
|
key={route.path || i}
|
|
38
60
|
path={route.path}
|
|
39
61
|
exact={route.path !== '/404'}
|
|
40
|
-
render={() => {
|
|
41
|
-
const Component = loadComponent(route.component);
|
|
42
|
-
return <Component />;
|
|
43
|
-
}}
|
|
62
|
+
render={() => <RouteWrapper componentPath={route.component} />}
|
|
44
63
|
/>
|
|
45
64
|
),
|
|
46
65
|
)}
|
package/src/layouts/index.tsx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react';
|
|
2
|
-
import { Avatar, Dropdown, Menu, Space } from 'antd';
|
|
3
1
|
import ProLayout from '@ant-design/pro-layout';
|
|
4
2
|
import history from '@/umi';
|
|
5
3
|
import menuRoutes from '../../routes/menu';
|
|
6
4
|
import getIcon from '@/utils/getIcon';
|
|
5
|
+
import { useLocation } from 'react-router-dom';
|
|
7
6
|
|
|
8
7
|
const menuDataRender = (menuList) => {
|
|
9
8
|
return menuList.map((item) => {
|
|
@@ -18,18 +17,28 @@ const menuDataRender = (menuList) => {
|
|
|
18
17
|
|
|
19
18
|
const BasicLayout = (props) => {
|
|
20
19
|
const { children } = props;
|
|
21
|
-
const
|
|
20
|
+
const location = useLocation();
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const isLayoutFalse = (routes, pathname) => {
|
|
23
|
+
for (const route of routes) {
|
|
24
|
+
if (pathname === route.path || pathname.startsWith(route.path + '/')) {
|
|
25
|
+
if (route.layout === false) return true;
|
|
26
|
+
}
|
|
27
|
+
if (route.routes) {
|
|
28
|
+
if (isLayoutFalse(route.routes, pathname)) return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (isLayoutFalse(menuRoutes, location.pathname)) {
|
|
35
|
+
return <>{children}</>;
|
|
36
|
+
}
|
|
29
37
|
|
|
30
38
|
return (
|
|
31
39
|
<ProLayout
|
|
32
40
|
title="管理平台"
|
|
41
|
+
// pure
|
|
33
42
|
logo={false}
|
|
34
43
|
layout="mix"
|
|
35
44
|
fixSiderbar={false}
|
package/src/pages/home.tsx
CHANGED