Skip to content

Commit

Permalink
fix: 修复icon版本问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Sep 25, 2024
1 parent 06b19c8 commit 1fdcce3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
10 changes: 4 additions & 6 deletions packages/admin/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { Menu } from 'antd';
import type { MenuProps, MenuTheme } from 'antd';
Expand Down Expand Up @@ -29,15 +29,13 @@ const MenuComponent: React.FC = () => {
const getTreeMenu = (menuList: IMenuItem[], treeList: MenuItem[] = []) => {
menuList.forEach((item) => {
if (item.type === 1 && item.status === 1) {
const iconComp = Icons[item.icon as keyof typeof Icons];
const iconsList: { [key: string]: any } = Icons;
if (item.buttons?.length || !item.children) {
const path = `/project/${env}/${projectId}/${item.page_id || 0}`;
return treeList.push(getMenuItem(item.name, path, <Icon component={iconComp as React.ForwardRefExoticComponent<any>} />));
return treeList.push(getMenuItem(item.name, path, React.createElement(iconsList[item.icon])));
}
const path = `/project/${env}/${projectId}/${item.id}`;
treeList.push(
getMenuItem(item.name, path, <Icon component={iconComp as React.ForwardRefExoticComponent<any>} />, getTreeMenu(item.children || [])),
);
treeList.push(getMenuItem(item.name, path, React.createElement(iconsList[item.icon]), getTreeMenu(item.children || [])));
}
});
return treeList;
Expand Down
23 changes: 11 additions & 12 deletions packages/editor/src/packages/Basic/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useImperativeHandle, forwardRef } from 'react';
import Icon, * as Icons from '@ant-design/icons';
import * as Icons from '@ant-design/icons';
import { ComponentType } from '@/packages/types';
/**
*
Expand Down Expand Up @@ -35,18 +35,17 @@ const MImage = (
const handleClick = () => {
onClick?.();
};
const iconComp = Icons[config.props.icon as keyof typeof Icons];

const iconsList: { [key: string]: any } = Icons;
return (
visible && (
<Icon
component={iconComp as React.ForwardRefExoticComponent<any>}
style={config.style}
{...config.props}
data-id={id}
data-type={type}
onClick={handleClick}
/>
)
visible &&
React.createElement(iconsList[config.props.icon], {
style: config.style,
...config.props,
'data-id': id,
'data-type': type,
onClick: handleClick,
})
);
};
export default forwardRef(MImage);
2 changes: 1 addition & 1 deletion packages/editor/src/packages/Basic/Icon/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
// 组件事件
events: [
{
value: 'handleClick',
value: 'onClick',
name: '点击事件',
},
],
Expand Down
11 changes: 8 additions & 3 deletions packages/materials/Basic/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useImperativeHandle, forwardRef } from 'react';
import Icon, * as Icons from '@ant-design/icons';
import * as Icons from '@ant-design/icons';
import { ComponentType } from '../../types';
/**
*
Expand Down Expand Up @@ -34,9 +34,14 @@ const MIcon = (
onClick?.();
};

const iconComp = Icons[config.props.icon as keyof typeof Icons];
const iconsList: { [key: string]: any } = Icons;
return (
visible && <Icon component={iconComp as React.ForwardRefExoticComponent<any>} style={config.style} {...config.props} onClick={handleClick} />
visible &&
React.createElement(iconsList[config.props.icon], {
style: config.style,
...config.props,
onClick: handleClick,
})
);
};
export default forwardRef(MIcon);

0 comments on commit 1fdcce3

Please sign in to comment.