@antdp/basic-layouts
入口公共界面
安装
$ npm i @antdp/basic-layouts
参数
import React from 'react';
import { IntlShape } from 'react-intl/lib/src/types';
export interface HandleMenuProps {
intlLanguage?: IntlShape;
routers: RouterMenu[];
isTOPLEFT?: boolean;
isCheckAuth?: boolean;
}
export interface RouterMenu {
path?: string;
key?: string;
name?: string;
icon?: string;
locale?: string;
side?: boolean;
index?: boolean;
component?: React.ReactNode;
redirect?: string;
redirectTo?: string;
hideInMenu?: boolean;
routes?: RouterMenu[];
children?: RouterMenu[];
order?: number;
oPath?: string;
}
export interface BasicLayoutsProps {
logo?: string;
projectName?: React.ReactNode;
children?: React.ReactNode;
intlLanguage?: IntlShape;
topRightMenu?: {
icon?: React.ReactNode;
title?: React.ReactNode;
link?: string;
divider?: boolean;
onClick?: () => void;
}[];
bodyPadding?: number;
topRightLanguage?: React.ReactNode;
siderWidth?: number;
profile?: {
avatar?: string;
name?: string;
};
}
基本使用
import BasicLayout from '@antdp/basic-layouts';
export default (props) => {
return (
<BasicLayout
{...props}
projectName="Ant Design Pro"
/>
)
};
菜单国际化设置
import BasicLayout from '@antdp/basic-layouts';
import { useIntl,SelectLang } from '@umijs/max';
const Demo = (props) => {
return (
<BasicLayout
{...props}
projectName="Ant Design Pro"
intlLanguage={useIntl()}
topRightLanguage={<SelectLang />}
/>
)
};
export default Demo
使用useLayouts
获取数据
import { useLayouts } from '@antdp/basic-layouts';
export interface LayoutsContextType extends UseLayoutsProps {
HandleMenu: HandleMenu;
collapsed: boolean;
setCollapsed: React.Dispatch<React.SetStateAction<boolean>>;
}
HandleMenu类方法
interface HandleMenu {
authMenus: any[] = []
parentMenu: RouterMenu[] = []
parentflatMenu: RouterMenu[] = []
childParent: Map<string, string> = new Map([])
childMenu: Map<string, RouterMenu[]> = new Map([])
flatMenu: RouterMenu[] = []
flatAllMenu: RouterMenu[] = []
intlLanguage?: IntlShape;
routers: RouterMenu[] = []
checkAuthMenus: RouterMenu[] = []
pathToParentMenus: Map<string, RouterMenu[]> = new Map([])
isCheckAuth?: boolean = false
isTOPLEFT?: boolean = false
preParentPath?: string = ''
prePath?: string = ''
checkAuth(path: string): boolean;
initAuth(routers: RouterMenu[], isParent: boolean): RouterMenu[]
initLanguage(menus: RouterMenu[], parentLocale: string): void
initFlat(menus?: RouterMenu[], parentMenu?: RouterMenu[]): void
handelSiderMenu(menus?: RouterMenu[], isSider?: boolean, parentPath?: string): void
getTopMenus(menus?: RouterMenu[], index?: number): RouterMenu[]
getBreadcrumb(path: string): RouterMenu[]
getSiderMenus(path: string): RouterMenu[]
getParentPath(path: string): string
getToPath(path: string): string | false | undefined
getPathItem(path: string): RouterMenu | undefined
}