diff --git a/src/components/IconFont/index.js b/src/components/IconFont/index.js new file mode 100644 index 0000000000000000000000000000000000000000..0b99dec3a7996eca278585cc961e0683b5d1cbcd --- /dev/null +++ b/src/components/IconFont/index.js @@ -0,0 +1,7 @@ +import { Icon } from 'antd'; +import { iconfontUrl as scriptUrl } from '../../defaultSettings'; + +// 使用: +// import IconFont from '@/components/IconFont'; +// +export default Icon.createFromIconfontCN({ scriptUrl }); diff --git a/src/components/SiderMenu/BaseMenu.js b/src/components/SiderMenu/BaseMenu.js index 10a0eb768a84ba505e305a1e5672bc777f276134..6c8c7022219e552b1b5696c16e50eac0070ad052 100644 --- a/src/components/SiderMenu/BaseMenu.js +++ b/src/components/SiderMenu/BaseMenu.js @@ -6,18 +6,23 @@ import { urlToList } from '../_utils/pathTools'; import { getMenuMatches } from './SiderMenuUtils'; import { isUrl } from '@/utils/utils'; import styles from './index.less'; +import IconFont from '@/components/IconFont'; const { SubMenu } = Menu; // Allow menu.js config icon as string or ReactNode // icon: 'setting', +// icon: 'icon-geren' #For Iconfont , // icon: 'http://demo.com/icon.png', // icon: , const getIcon = icon => { - if (typeof icon === 'string' && isUrl(icon)) { - return icon} />; - } if (typeof icon === 'string') { + if (isUrl(icon)) { + return icon} />; + } + if (icon.startsWith('icon-')) { + return ; + } return ; } return icon; diff --git a/src/defaultSettings.js b/src/defaultSettings.js index dfdb53419e16535a2e9ca432f0a7baaf8eeefe2e..4ba7eb390c49069b68053d9823f194a76f99391d 100644 --- a/src/defaultSettings.js +++ b/src/defaultSettings.js @@ -11,4 +11,8 @@ module.exports = { }, title: 'Ant Design Pro', pwa: true, + // your iconfont Symbol Scrip Url + // eg://at.alicdn.com/t/font_1039637_btcrd5co4w.js + // 注意:如果需要图标多色,Iconfont图标项目里要进行批量去色处理 + iconfontUrl: '', };