import React from 'react'; import NotFound from '../../src/components/404'; import Layout from '../../src/components/Layout'; import AsideNav from '../../src/components/AsideNav'; import { AlertComponent, Button, Drawer, ToastComponent } from '../../src/components/index'; import {eachTree, mapTree} from '../../src/utils/helper'; import {Icon} from '../../src/components/icons'; import '../../src/locale/en-US'; import { Router, Route, IndexRoute, browserHistory, hashHistory, Link, Redirect, withRouter } from 'react-router'; import Select from '../../src/components/Select'; import DocSearch from './DocSearch'; import Doc from './Doc'; import DocNavCN from './DocNavCN'; import Example, {examples} from './Example'; import CssDocs, {cssDocs} from './CssDocs'; import CSSDocs from './CssDocs'; declare const _hmt: any; let ExamplePathPrefix = '/examples'; let DocPathPrefix = '/docs'; let ContextPath = ''; if (process.env.NODE_ENV === 'production') { ExamplePathPrefix = ''; DocPathPrefix = ''; ContextPath = '/amis'; } export function getContextPath() { return ContextPath; } const themes = [ { label: '默认主题', ns: 'a-', value: 'default' }, { label: '百度云舍', ns: 'cxd-', value: 'cxd' }, { label: 'Dark', ns: 'dark-', value: 'dark' } ]; const locales = [ { label: '中文', value: 'zh-CN' }, { label: 'English', value: 'en-US' } ]; const viewModes = [ { label: '桌面端', value: 'pc' }, { label: '移动端', value: 'mobile' } ]; function getPath(path) { return path ? path[0] === '/' ? ContextPath + path : `${ContextPath}/${path}` : ''; } class BackTop extends React.PureComponent { state = { show: false }; componentDidMount() { document.addEventListener('scroll', this.handleScroll.bind(this)); } componentWillUnmount() { document.removeEventListener('scroll', this.handleScroll.bind(this)); } handleScroll(e) { this.setState({ show: e.target.scrollingElement?.scrollTop > 350 }); } render() { return (
scrollTo({top: 0})} >
); } } // @ts-ignore @withRouter // @ts-ignore export class App extends React.PureComponent<{ location: Location; }> { state = { viewMode: localStorage.getItem('viewMode') || 'pc', offScreen: false, folded: false, headerVisible: true, themeIndex: 0, themes: themes, theme: themes.find(item => item?.value === localStorage.getItem('theme')) || themes[0], locale: localStorage.getItem('locale') ? localStorage.getItem('locale').replace('zh-cn', 'zh-CN') : '', navigations: [] }; constructor(props) { super(props); this.setNavigations = this.setNavigations.bind(this); } componentDidUpdate(preProps, preState) { const props = this.props; if (preState.theme.value !== this.state.theme.value) { [].slice .call(document.querySelectorAll('link[title]')) .forEach((item: HTMLLinkElement) => { const theme = item.getAttribute('title'); item.disabled = theme !== this.state.theme.value; }); const body = document.querySelector('body'); body.classList.remove(preState.theme.value); body.classList.add(this.state.theme.value); } if (props.location.pathname !== preProps.location.pathname) { this.setState( { offScreen: false }, () => window.scrollTo(0, 0) ); _hmt && _hmt.push(['_trackPageview', props.location.pathname]); } } setNavigations(items) { this.setState({ navigations: items }); } renderHeader(docPage = true) { const location = this.props.location; const theme = this.state.theme; if (location.pathname === '/edit') { return (
AMis 可视化编辑器
); } return ( <>
this.setState({offScreen: !this.state.offScreen})} className={`${theme.ns}Layout-offScreen-btn ${ docPage ? 'DocLayout-offScreen-btn' : '' } pull-right visible-xs`} >
{docPage ? (
) : (
AMIS 示例
)}
{docPage ? null : ( )}
{ this.setState({theme}); localStorage.setItem('theme', `${theme.value}`); document .querySelector('body') .classList[theme.value === 'dark' ? 'add' : 'remove']('dark'); }} />