/** * @file 引擎入口 * @author dongtiancheng */ import * as React from 'react'; import { BasicConfig } from './Container/types'; import { IsDefined, IsString } from 'class-validator'; import * as PropsTypes from 'prop-types'; import { createChild } from '../util/createChild'; import * as URL from 'url'; import * as querystring from 'querystring'; export type RCREOptions = { /** * 启动0.15.0版本之前的container数据合并策略 */ oldNestContainerCompatible?: boolean; }; export class PageProps { @IsString() title?: string; @IsDefined() body: BasicConfig[] | BasicConfig | string; // 外部注入的全局对象 global?: Object; // 调试模式 debug: boolean; // 报错的信息语言 lang: string; options?: RCREOptions; } class Page extends React.Component { static defaultProps = { title: '', debug: false, global: {}, lang: 'zh_CN', options: {} }; static childContextTypes = { $global: PropsTypes.object, $location: PropsTypes.object, $query: PropsTypes.object, debug: PropsTypes.bool, lang: PropsTypes.string, options: PropsTypes.object }; static getLocationService() { let $location = URL.parse(location.href); let $query = {}; if ($location.query && typeof $location.query === 'string') { $query = querystring.parse($location.query); } return { $location, $query }; } constructor(props: PageProps) { super(props); } getChildContext() { let { $location, $query } = Page.getLocationService(); return { $global: this.props.global, $location, $query, debug: this.props.debug }; } render() { let body; if (!Array.isArray(this.props.body)) { return

body props is not array

; } body = this.props.body.map((item, index) => { return createChild(item, { info: item, key: index, options: this.props.options }); }); let pageHeader = this.props.title ? (

{this.props.title}

) : ''; return (
{pageHeader}
{body}
); } } export default Page;