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

icon支持本地图片 #585

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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