Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hocgin committed Sep 21, 2024
1 parent 9dc0cc5 commit aa93088
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/_utils/kit.ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { message, Tree, TreeSelect, Upload } from 'antd';
import { StructKit } from '@/_utils';
import { FileInfo, TreeNode } from '@/_types';
import * as ICONS from '@ant-design/icons';
import * as Icons from '@ant-design/icons';
import { BuildOutlined } from '@ant-design/icons';

export default class UIKit {
public static COLUMN_PREFIX = 'hui.';
Expand Down Expand Up @@ -32,10 +33,14 @@ export default class UIKit {
public static getIcon(name?: string | JSX.Element): JSX.Element {
if (!name || typeof name === 'object') return name as any;
const IconMap: Record<string, any> = {
default: ICONS['BuildOutlined'],
// @ts-ignore
default: <BuildOutlined />,
};
let Element = IconMap[name];
return React.createElement(Element ?? ICONS[name], {});
let element = IconMap[name];
if (element) {
return element;
}
return <Iconfont icon={name} />;
}

/**
Expand Down Expand Up @@ -179,3 +184,13 @@ export default class UIKit {
return meetType && meetSize;
};
}

const Iconfont = (props) => {
//这里传入的props是一个对象,里面有icon属性,值是antd图标的名字
const { icon } = props;
let iconObj = Icons[icon];
if (!iconObj) {
return <></>;
}
return React.createElement(iconObj);
};

0 comments on commit aa93088

Please sign in to comment.