@lxzy/code-snippet 0.0.10 → 0.0.11
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/.opencode/commands/push-yw.md +1 -1
- package/package.json +1 -1
- package/routes/menu.ts +2 -0
- package/src/App.tsx +9 -1
- package/src/layouts/index.tsx +13 -2
- package/src/utils/getIcon.tsx +16 -0
package/package.json
CHANGED
package/routes/menu.ts
CHANGED
package/src/App.tsx
CHANGED
|
@@ -5,10 +5,18 @@ import history from '@/umi';
|
|
|
5
5
|
import BasicLayout from '@/layouts/index';
|
|
6
6
|
import routes from '../routes';
|
|
7
7
|
|
|
8
|
+
const pageModules = import.meta.glob('./pages/**/*.tsx');
|
|
9
|
+
|
|
8
10
|
const componentCache = {};
|
|
9
11
|
const loadComponent = (path) => {
|
|
10
12
|
if (!componentCache[path]) {
|
|
11
|
-
|
|
13
|
+
const factory: any =
|
|
14
|
+
pageModules[`./pages/${path}.tsx`] ||
|
|
15
|
+
pageModules[`./pages/${path}/index.tsx`];
|
|
16
|
+
if (!factory) {
|
|
17
|
+
throw new Error(`Page component not found: ${path}`);
|
|
18
|
+
}
|
|
19
|
+
componentCache[path] = lazy(factory);
|
|
12
20
|
}
|
|
13
21
|
return componentCache[path];
|
|
14
22
|
};
|
package/src/layouts/index.tsx
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import { Avatar, Dropdown, Menu, Space } from 'antd';
|
|
3
3
|
import ProLayout from '@ant-design/pro-layout';
|
|
4
4
|
import history from '@/umi';
|
|
5
5
|
import menuRoutes from '../../routes/menu';
|
|
6
|
+
import getIcon from '@/utils/getIcon';
|
|
6
7
|
|
|
7
8
|
const menuDataRender = (menuList) => {
|
|
8
9
|
return menuList.map((item) => {
|
|
9
10
|
const localItem = {
|
|
10
11
|
...item,
|
|
12
|
+
icon: item.icon ? getIcon(item.icon) : undefined,
|
|
11
13
|
children: item.children ? menuDataRender(item.children) : undefined,
|
|
12
14
|
};
|
|
13
15
|
return localItem;
|
|
@@ -16,6 +18,14 @@ const menuDataRender = (menuList) => {
|
|
|
16
18
|
|
|
17
19
|
const BasicLayout = (props) => {
|
|
18
20
|
const { children } = props;
|
|
21
|
+
const [location, setLocation] = useState(history.location);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const unlisten = history.listen((location) => {
|
|
25
|
+
setLocation(location);
|
|
26
|
+
});
|
|
27
|
+
return () => unlisten();
|
|
28
|
+
}, []);
|
|
19
29
|
|
|
20
30
|
return (
|
|
21
31
|
<ProLayout
|
|
@@ -24,9 +34,10 @@ const BasicLayout = (props) => {
|
|
|
24
34
|
layout="mix"
|
|
25
35
|
fixSiderbar={false}
|
|
26
36
|
fixedHeader
|
|
37
|
+
location={location}
|
|
27
38
|
route={{
|
|
28
39
|
path: '/',
|
|
29
|
-
routes: menuRoutes,
|
|
40
|
+
routes: menuDataRender(menuRoutes),
|
|
30
41
|
}}
|
|
31
42
|
menuItemRender={(item, dom) => (
|
|
32
43
|
<a onClick={() => history.push(item.path || '/')}>{dom}</a>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as Icons from '@ant-design/icons';
|
|
3
|
+
|
|
4
|
+
const getIcon = (name) => {
|
|
5
|
+
if (!name) return undefined;
|
|
6
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
7
|
+
const parts = name.split('-');
|
|
8
|
+
const baseName = parts.map(capitalize).join('');
|
|
9
|
+
const hasSuffix = name.endsWith('Filled') || name.endsWith('TwoTone');
|
|
10
|
+
const componentName = hasSuffix ? baseName : baseName + 'Outlined';
|
|
11
|
+
const IconComp = Icons[componentName];
|
|
12
|
+
if (!IconComp) return undefined;
|
|
13
|
+
return React.createElement(IconComp);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default getIcon;
|