-
Notifications
You must be signed in to change notification settings - Fork 11
/
App.tsx
117 lines (104 loc) · 3.21 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import * as React from 'react';
import {
Route,
Switch,
BrowserRouter as Router
} from "react-router-dom";
import {
ToastComponent,
AlertComponent
} from 'amis';
import QsMan from 'qsman';
// css
import 'font-awesome/css/font-awesome.css';
import 'bootstrap/dist/css/bootstrap.css';
import 'amis/lib/themes/default.css';
import 'react-datetime/css/react-datetime.css';
import 'cropperjs/dist/cropper.css';
import 'video-react/dist/video-react.css';
import './polyfill';
import AMisRenderer from './AMisRenderer';
import InfoPageSchema from './info-page-schema';
import loadSchema from './load-schema';
// 扩展
// 主题
import '../ext/theme.less';
// 验证规则
import '../ext/validations';
// 覆盖渲染器的默认值
import '../ext/renderer-defaults';
// AMIS 自定义组件
import '../ext/amis-components/Demo';
import '../ext/amis-components/Wysiwyg';
// 获取默认的环境模式
import getDefaultMode from '../ext/get-default-mode';
import {
getMainDomain
} from '../ext/util';
interface AppState {
schema: any
}
var qsParam = new QsMan(window.location.search).getObject();
// 自动识别环境模式
if (!qsParam._mode) {
qsParam._mode = getDefaultMode();
}
try {
window.document.domain = getMainDomain(window.location.hostname);
} catch (error) {
console.warn('document.domain 设置失败', error);
}
export default class App extends React.Component {
state:AppState = {
schema: new InfoPageSchema('正在加载页面配置', '', '', ' ')
};
constructor(props:any) {
super(props);
}
componentWillMount() {
this.loadSchema();
}
loadSchema() {
if (qsParam._schema) {
loadSchema(qsParam._schema).then((schema) => {
// @ts-ignore
if (schema.title) {
// @ts-ignore
document.title = schema.title;
}
this.setState({
schema: schema
});
});
} else {
this.setState({
schema: new InfoPageSchema('没有提供页面的配置', 'URL 中必须传入<code>_schema</code>参数, 以指定页面的配置')
});
}
}
render() {
var schema = this.state.schema;
var env = schema.definitions?.env?.[qsParam._mode] || {};
return (
<Router>
<div>
<ToastComponent key="toast" position="top-center" />
<AlertComponent key="alert" />
<Switch>
<Route path="/" render={(routeProps) => {
return (
<AMisRenderer {...routeProps}
schema={schema}
data={{
_qsParam: qsParam,
_definitions: schema.definitions,
_env: env
}} />
);
}} />
</Switch>
</div>
</Router>
);
}
}