@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.
@@ -4,5 +4,5 @@ agent: build
4
4
  model: opencode/mimo-v2.5-free
5
5
  ---
6
6
 
7
- 修改 package.json 里的 version 字段,版本号加 1
7
+ 修改 package.json 里的 version 字段,版本号根据 patch bump 规则加 1
8
8
  执行`pnpm pub`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lxzy/code-snippet",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "files": [
5
5
  "*",
6
6
  "!dist",
package/routes/menu.ts CHANGED
@@ -3,10 +3,12 @@ export default [
3
3
  path: '/home',
4
4
  name: '首页',
5
5
  component: 'home',
6
+ icon: 'smile',
6
7
  },
7
8
  {
8
9
  path: '/activityCenter',
9
10
  name: '活动中心',
11
+ icon: 'sound',
10
12
  routes: [
11
13
  {
12
14
  path: '/activityCenter/activitySystemManagement',
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
- componentCache[path] = lazy(() => import(`./pages/${path}`));
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
  };
@@ -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;