import IconAll, { ALL_ICON_KEYS, IconType, IIconAllProps } from '@icon-park/react/es/all' import React, { Fragment } from 'react' import * as AntIcons from '@ant-design/icons/es/icons' import { IconComponentProps } from '@ant-design/icons/es/components/Icon' export function Icon(props: Partial) { const { type, ...other } = props const AntIcon = AntIcons[type as keyof typeof AntIcons] if (AntIcon) { return } //如果是http或https链接,直接返回图片 if (type && (type.startsWith('http') || type.startsWith('https') || type.startsWith('data:image'))) { // @ts-ignore 没有办法把所有的属性都传递给img return icon } if (ALL_ICON_KEYS.indexOf(type as IconType) < 0) { return null } return ( ) } // eslint-disable-next-line react-refresh/only-export-components export const getIcon = (type: string, props?: Partial) => { if(React.isValidElement(type)){ return type } //判断是否为json格式 if (type && type.startsWith('{') && type.endsWith('}')) { try { const obj = JSON.parse(type) type = obj.type props = obj } catch (e) { /* empty */ } } return } export default Icon