|
|
@@ -3,11 +3,11 @@ import Container from './Layout.js';
|
|
|
import Title from '../src/Title/Title.jsx';
|
|
|
import FixedBox from '../src/FixedBox/FixedBox.jsx';
|
|
|
import DateFormatter from '../utils/DateTimeUtils.js';
|
|
|
-import {converter} from './converter.js';
|
|
|
+import { converter } from './converter.js';
|
|
|
import RenderUtils from '../utils/RenderUtils.js';
|
|
|
import URL from '../constants/url.json';
|
|
|
|
|
|
-import tempdata from '../data/cc.json';
|
|
|
+// import tempdata from '../data/cc.json';
|
|
|
|
|
|
class Factory extends React.Component {
|
|
|
|
|
|
@@ -15,22 +15,23 @@ class Factory extends React.Component {
|
|
|
super(props);
|
|
|
this.index = 0;
|
|
|
this.state = {
|
|
|
+ titleHeight: 50
|
|
|
};
|
|
|
}
|
|
|
|
|
|
getModelConfig(mid) {
|
|
|
let me = this;
|
|
|
- fetch(URL.path+mid, {
|
|
|
+ fetch(URL.path + mid, {
|
|
|
method: 'POST',
|
|
|
credentials: 'include'
|
|
|
}).then(function (response) {
|
|
|
return (response.json())
|
|
|
}).then((json) => {
|
|
|
let instance = json.instance;
|
|
|
- if(!me.state.instance) {
|
|
|
+ if (!me.state.instance) {
|
|
|
me.setState({
|
|
|
instance: instance
|
|
|
- },me.setRefresh);
|
|
|
+ }, me.setRefresh);
|
|
|
}
|
|
|
return json.data[0];
|
|
|
}).then(function (modelconfig) {
|
|
|
@@ -42,15 +43,16 @@ class Factory extends React.Component {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- setTitleHeight() {
|
|
|
+ getTitleHeight() {
|
|
|
let titleEl = document.getElementsByClassName('rc-title');
|
|
|
let titleHeight = titleEl.length > 0 ? titleEl[0].offsetHeight : 50;
|
|
|
- this.titleHeight = titleHeight || 0;
|
|
|
+ titleHeight = titleHeight || 0;
|
|
|
+ return titleHeight;
|
|
|
}
|
|
|
|
|
|
setRefresh() {
|
|
|
let { instance } = this.state;
|
|
|
- if(!instance) {return;}
|
|
|
+ if (!instance) { return; }
|
|
|
let codes = instance.templateCodes;
|
|
|
let display = instance.display;
|
|
|
let next = {
|
|
|
@@ -67,7 +69,7 @@ class Factory extends React.Component {
|
|
|
};
|
|
|
// 刷新
|
|
|
if (refresh.current) {
|
|
|
- if(refresh.current.enable) {
|
|
|
+ if (refresh.current.enable) {
|
|
|
this.refreshThis = setInterval(function () {
|
|
|
this.getModelConfig(this.props.code[0] + '?templateCode=' + codes[this.index]);
|
|
|
}.bind(this), refresh.current.interval * 1000 || 10000)
|
|
|
@@ -75,69 +77,70 @@ class Factory extends React.Component {
|
|
|
}
|
|
|
// 切换
|
|
|
if (refresh.next) {
|
|
|
- if(refresh.next.enable) {
|
|
|
+ if (refresh.next.enable) {
|
|
|
this.refreshNext = setInterval(function () {
|
|
|
- if(this.index == codes.length-1) {
|
|
|
+ if (this.index == codes.length - 1) {
|
|
|
this.index = 0;
|
|
|
- }else {
|
|
|
- this.index ++;
|
|
|
+ } else {
|
|
|
+ this.index++;
|
|
|
}
|
|
|
- }.bind(this), refresh.next.interval * 1000 || 30000)
|
|
|
+ }.bind(this), refresh.next.interval * 1000 || 30000)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
- this.setTitleHeight();
|
|
|
}
|
|
|
|
|
|
componentWillMount() {
|
|
|
- let {code} = this.props;
|
|
|
- // this.getModelConfig(code[0]);
|
|
|
- this.setState({
|
|
|
- model: converter(tempdata.data[0]),
|
|
|
- });
|
|
|
+ let { code } = this.props;
|
|
|
+ this.getModelConfig(code[0]);
|
|
|
+ // this.setState({
|
|
|
+ // model: converter(tempdata.data[0]),
|
|
|
+ // });
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
+ this.setState({
|
|
|
+ titleHeight: this.getTitleHeight()
|
|
|
+ });
|
|
|
}
|
|
|
componentWillUnmount() {
|
|
|
- if(this.refreshThis) {
|
|
|
- if(this.refreshThis.interval > 0) {
|
|
|
+ if (this.refreshThis) {
|
|
|
+ if (this.refreshThis.interval > 0) {
|
|
|
window.clearInterval(this.refreshThis);
|
|
|
}
|
|
|
}
|
|
|
- if(this.refreshNext) {
|
|
|
- if(this.refreshNext.interval > 0) {
|
|
|
+ if (this.refreshNext) {
|
|
|
+ if (this.refreshNext.interval > 0) {
|
|
|
window.clearInterval(this.refreshNext);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
- console.log('1');
|
|
|
- this.setTitleHeight();
|
|
|
+ this.setState({
|
|
|
+ titleHeight: this.getTitleHeight()
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
- if(!this.state.model){
|
|
|
+ if (!this.state.model) {
|
|
|
return <div></div>
|
|
|
}
|
|
|
- let {model} = this.state;
|
|
|
- let titleHeight = this.titleHeight || 0;
|
|
|
- console.log(titleHeight);
|
|
|
- const {title, content, fixedbox} = model;
|
|
|
- let titleConfig = title ? (title.config || {height: 0}) : {height: 0};
|
|
|
+ let { titleHeight, model } = this.state;
|
|
|
+ const { title, content, fixedbox } = model;
|
|
|
+ let titleConfig = title;
|
|
|
let items = [];
|
|
|
- if(fixedbox) {
|
|
|
- items = fixedbox.items || [];
|
|
|
+ if (fixedbox) {
|
|
|
+ items = fixedbox.items || [];
|
|
|
}
|
|
|
return (
|
|
|
<div>
|
|
|
<Title static={this.props.static} {...titleConfig} />
|
|
|
<Container static={this.props.static} items={content.items} rowHeight={(window.innerHeight - titleHeight) / 10} />
|
|
|
{items.map((item, index) => {
|
|
|
- return <FixedBox key={`${index}`} static={this.props.static} titleHeight={titleHeight} {...item}/>;
|
|
|
+ return <FixedBox key={`${index}`} static={this.props.static} titleHeight={titleHeight} {...item} />;
|
|
|
})}
|
|
|
</div>
|
|
|
);
|