|
@@ -5,16 +5,21 @@ import MessageBox from '../src/MsgBox/MessageBox.jsx';
|
|
|
import { converter } from './converter.js';
|
|
import { converter } from './converter.js';
|
|
|
import URL from '../constants/url.dev.json';
|
|
import URL from '../constants/url.dev.json';
|
|
|
import 'whatwg-fetch';
|
|
import 'whatwg-fetch';
|
|
|
|
|
+import { getThemeConfig, applyTheme } from './theme/applyTheme.js';
|
|
|
|
|
|
|
|
-import tempdata from '../data/testline.json';
|
|
|
|
|
|
|
+import tempdata from '../data/主题测试1.json';
|
|
|
|
|
|
|
|
class Factory extends React.Component {
|
|
class Factory extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
|
- this.dev = 'local';
|
|
|
|
|
|
|
+ this.dev = 'local ';
|
|
|
|
|
+ this.theme = 'blue';
|
|
|
|
|
+
|
|
|
this.index = 0;
|
|
this.index = 0;
|
|
|
this.state = {
|
|
this.state = {
|
|
|
|
|
+ theme: 'dark',
|
|
|
|
|
+ themeConfig: {},
|
|
|
titleHeight: 0,
|
|
titleHeight: 0,
|
|
|
error: null,
|
|
error: null,
|
|
|
firstRequestTime: new Date()
|
|
firstRequestTime: new Date()
|
|
@@ -28,6 +33,13 @@ class Factory extends React.Component {
|
|
|
credentials: 'include'
|
|
credentials: 'include'
|
|
|
}).then(function (response) {
|
|
}).then(function (response) {
|
|
|
return (response.json())
|
|
return (response.json())
|
|
|
|
|
+ }).then((json) => {
|
|
|
|
|
+ let theme = json.theme || 'dark';
|
|
|
|
|
+ me.setState({
|
|
|
|
|
+ theme: theme,
|
|
|
|
|
+ themeConfig: getThemeConfig(theme),
|
|
|
|
|
+ });
|
|
|
|
|
+ return json;
|
|
|
}).then((json) => {
|
|
}).then((json) => {
|
|
|
if(!json.instance) {
|
|
if(!json.instance) {
|
|
|
throw {message: json.message};
|
|
throw {message: json.message};
|
|
@@ -47,6 +59,11 @@ class Factory extends React.Component {
|
|
|
msg: null,
|
|
msg: null,
|
|
|
model: converter(modelconfig),
|
|
model: converter(modelconfig),
|
|
|
});
|
|
});
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ applyTheme(me.state.theme);
|
|
|
|
|
+ me.setState({
|
|
|
|
|
+ titleHeight: me.getTitleHeight(),
|
|
|
|
|
+ });
|
|
|
}).catch(function (ex) {
|
|
}).catch(function (ex) {
|
|
|
let message = ex.message;
|
|
let message = ex.message;
|
|
|
if(ex.name && ex.name == 'TypeError') {
|
|
if(ex.name && ex.name == 'TypeError') {
|
|
@@ -115,6 +132,8 @@ class Factory extends React.Component {
|
|
|
let { code, index } = this.props;
|
|
let { code, index } = this.props;
|
|
|
if(this.dev == 'local') {
|
|
if(this.dev == 'local') {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
|
|
+ theme: this.theme,
|
|
|
|
|
+ themeConfig: getThemeConfig(this.theme),
|
|
|
model: converter(tempdata.data[0]),
|
|
model: converter(tempdata.data[0]),
|
|
|
});
|
|
});
|
|
|
this.refreshNext = setInterval(function () {
|
|
this.refreshNext = setInterval(function () {
|
|
@@ -135,8 +154,9 @@ class Factory extends React.Component {
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
window.addEventListener('resize', this.onWindowResize.bind(this));
|
|
window.addEventListener('resize', this.onWindowResize.bind(this));
|
|
|
|
|
+ applyTheme(this.state.theme);
|
|
|
this.setState({
|
|
this.setState({
|
|
|
- titleHeight: this.getTitleHeight()
|
|
|
|
|
|
|
+ titleHeight: this.getTitleHeight(),
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
componentWillUnmount() {
|
|
componentWillUnmount() {
|
|
@@ -157,7 +177,7 @@ class Factory extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- let { titleHeight, model, msg } = this.state;
|
|
|
|
|
|
|
+ let { theme, themeConfig, titleHeight, model, msg } = this.state;
|
|
|
if (msg) {
|
|
if (msg) {
|
|
|
return <MessageBox static={this.props.static} titleHeight={titleHeight} msg={msg} />
|
|
return <MessageBox static={this.props.static} titleHeight={titleHeight} msg={msg} />
|
|
|
}
|
|
}
|
|
@@ -172,10 +192,13 @@ class Factory extends React.Component {
|
|
|
items = fixedbox.items || [];
|
|
items = fixedbox.items || [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let itemMargin = themeConfig.items ? (themeConfig.items.margin || [0, 0]) : [0, 0];
|
|
|
|
|
+ let containerHeight = window.innerHeight - titleHeight - (10 * itemMargin[1] + itemMargin[1]);
|
|
|
|
|
+ let rowHeight = containerHeight / 10;
|
|
|
return (
|
|
return (
|
|
|
- <div ref='body'>
|
|
|
|
|
|
|
+ <div ref='body' className={theme}>
|
|
|
<Title setTitleHeight={this.setTitleHeight.bind(this)} {...titleConfig} />
|
|
<Title setTitleHeight={this.setTitleHeight.bind(this)} {...titleConfig} />
|
|
|
- <Container items={content.items} rowHeight={(window.innerHeight - titleHeight) / 10} />
|
|
|
|
|
|
|
+ <Container theme={theme} themeConfig={themeConfig} items={content.items} rowHeight={rowHeight} margin={itemMargin}/>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|