Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
icon支持本地图片 (#585)
Browse files Browse the repository at this point in the history
* icon支持本地图片

* 抽离是否是图片链接判断
  • Loading branch information
douxc authored Jul 22, 2020
1 parent d3cd549 commit 28fa344
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/SiderMenu/BaseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MenuMode, MenuProps } from 'antd/es/menu';
import { MenuTheme } from 'antd/es/menu/MenuContext';
import defaultSettings, { PureSettings } from '../defaultSettings';
import { getSelectedMenuKeys } from './SiderMenuUtils';
import { isUrl, getOpenKeysFromMenuData } from '../utils/utils';
import { isUrl, getOpenKeysFromMenuData, isImg } from '../utils/utils';

import {
MenuDataItem,
Expand Down Expand Up @@ -73,7 +73,7 @@ let IconFont = createFromIconfontCN({
// icon: <Icon type="setting" />,
const getIcon = (icon?: string | React.ReactNode): React.ReactNode => {
if (typeof icon === 'string' && icon !== '') {
if (isUrl(icon)) {
if (isUrl(icon) || isImg(icon)) {
return (
<Icon
component={() => (
Expand Down
5 changes: 5 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const isBrowser = () =>
typeof window.document !== 'undefined' &&
!isNode;

/** 判断是否是图片链接 */
export function isImg(path: string): boolean {
return /\w.(png|jpg|jpeg|svg|webp|gif|bmp)$/i.test(path);
}

export function guid() {
return 'xxxxxxxx'.replace(/[xy]/g, (c) => {
// eslint-disable-next-line no-bitwise
Expand Down

0 comments on commit 28fa344

Please sign in to comment.