import React from 'react'; import {Layout, AsideNav, Spinner, NotFound} from 'amis-ui'; import {eachTree, TreeArray, TreeItem} from 'amis-core'; import { HashRouter as Router, Route, Redirect, Switch, Link, NavLink } from 'react-router-dom'; const pages: TreeArray = [ { label: '常规', children: [ { label: '按钮', path: '/basic/button', component: React.lazy(() => import('./basic/Button')) } ] }, { label: '表单', children: [ { label: '受控表单', path: '/form/controlled-form', component: React.lazy(() => import('./form/ControlledForm')) }, { label: 'InputTable', path: '/form/input-table', component: React.lazy(() => import('./form/InputTable')) }, { label: 'Combo', path: '/form/combo', component: React.lazy(() => import('./form/Combo')) } ] }, { label: '弹框', children: [ { label: 'PickContainer', path: '/modal/pick-conatiner', component: React.lazy(() => import('./modal/PickerContainer')) }, { label: 'ConfirmBox', path: '/modal/confirm-box', component: React.lazy(() => import('./modal/ConfirmBox')) } ] } ]; function getPath(path: string) { return path ? (path[0] === '/' ? path : `/${path}`) : ''; } function isActive(link: any, location: any) { return !!(link.path && getPath(link.path) === location.pathname); } export function navigations2route( navigations: any, additionalProperties?: any ) { let routes: any = []; navigations.forEach((root: any) => { root.children && eachTree(root.children, (item: any) => { if (item.path && item.component) { routes.push( additionalProperties ? ( ( )} /> ) : ( ) ); } }); }); return routes; } export default function App() { function renderAside() { return ( ({ ...item, children: item.children ? item.children.map((item: any) => ({ ...item, className: 'is-top' })) : [] }))} renderLink={({ link, active, toggleExpand, classnames: cx, depth }: any) => { let children = []; if (link.children && link.children.length) { children.push( toggleExpand(link, e)} > ); } link.badge && children.push( {link.badge} ); if (link.icon) { children.push( ); } children.push( {link.label} ); return link.path ? ( /^https?\:/.test(link.path) ? ( {children} ) : ( {children} ) ) : ( toggleExpand(link) : undefined}> {children} ); }} isActive={(link: any) => isActive(link, location)} /> ); } return (
amis-ui 示例
} aside={renderAside()} > } > {navigations2route(pages)} } />
); }