/** * @file entry of this example. * @author fex */ import React from 'react'; import {createRoot} from 'react-dom/client'; 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'; import Doc from './examples/component/Doc'; function MDComponent(fN: () => Promise<{default: {raw: string}}>) { return React.lazy(() => fN().then(ret => ({default: () => })) ); } const pages: TreeArray = [ { label: '面板模版', children: [ { label: '基础', path: '/basic', component: MDComponent(() => import('./examples/route/Basic.md')) }, { label: '公式', path: '/formula', component: MDComponent(() => import('./examples/route/Formula.md')) } ] } ]; 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 function Main() { 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: any[] = []; 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 ( } > import('./examples/App'))} exact path="/" />
编辑器面板示例
回到编辑器 } aside={renderAside()} > } > {navigations2route(pages)} } />
); } export function bootstrap(mountTo: HTMLElement, initalState: any) { const root = createRoot(mountTo); root.render(
); }