| @@ -81,21 +81,23 @@ var hbRequestCount | |||||
| var getAdDataCount | var getAdDataCount | ||||
| var pageChangeCount | var pageChangeCount | ||||
| var adDataList = [] | |||||
| var heartConfig = { | |||||
| heartbeatInterval:1000*10, | |||||
| dataRefreshInterval:1000*60*60, | |||||
| pageChangeInterval:1000*10, | |||||
| } | |||||
| export default class MyPage extends Component { | export default class MyPage extends Component { | ||||
| constructor(props) { | constructor(props) { | ||||
| super(props); | super(props); | ||||
| this.state = { | this.state = { | ||||
| baseInfo: baseInfoDefault, | baseInfo: baseInfoDefault, | ||||
| adDataList:[], | |||||
| contentItem0:null, | contentItem0:null, | ||||
| contentItem1:null, | contentItem1:null, | ||||
| contentItem2:null, | contentItem2:null, | ||||
| animationTheme:{}, | animationTheme:{}, | ||||
| heartConfig:{ | |||||
| heartbeatInterval:1000*10, | |||||
| dataRefreshInterval:1000*60*60, | |||||
| pageChangeInterval:1000*10, | |||||
| }, | |||||
| contentDisplayStatus:false, | contentDisplayStatus:false, | ||||
| syncMessage: "初始化..." , | syncMessage: "初始化..." , | ||||
| errorMessage: '加载中...', | errorMessage: '加载中...', | ||||
| @@ -160,22 +162,22 @@ codePushStatusDidChange(syncStatus) { | |||||
| } | } | ||||
| // 列表滚动 | // 列表滚动 | ||||
| updateContent() { | updateContent() { | ||||
| if (this.state.adDataList.length <=0) | |||||
| if (adDataList.length <=0) | |||||
| return false; | return false; | ||||
| if (curAdIndex >= this.state.adDataList.length) { | |||||
| if (curAdIndex >= adDataList.length) { | |||||
| curAdIndex = 0 | curAdIndex = 0 | ||||
| } | } | ||||
| this.setState({contentItem0:this.state.adDataList[curAdIndex]}); | |||||
| this.setState({contentItem0:adDataList[curAdIndex]}); | |||||
| if (curAdIndex + 1 < this.state.adDataList.length) | |||||
| this.setState({contentItem1:this.state.adDataList[curAdIndex+1]}); | |||||
| if (curAdIndex + 1 < adDataList.length) | |||||
| this.setState({contentItem1:adDataList[curAdIndex+1]}); | |||||
| else | else | ||||
| this.setState({contentItem1:null}); | this.setState({contentItem1:null}); | ||||
| if (curAdIndex + 2 < this.state.adDataList.length) | |||||
| this.setState({contentItem2:this.state.adDataList[curAdIndex+2]}); | |||||
| if (curAdIndex + 2 < adDataList.length) | |||||
| this.setState({contentItem2:adDataList[curAdIndex+2]}); | |||||
| else | else | ||||
| this.setState({contentItem2:null}); | this.setState({contentItem2:null}); | ||||
| @@ -190,13 +192,10 @@ codePushStatusDidChange(syncStatus) { | |||||
| .then(result => { | .then(result => { | ||||
| if (result.code == 200) { | if (result.code == 200) { | ||||
| let config = JSON.parse(result.data.config); | let config = JSON.parse(result.data.config); | ||||
| this.setState({ | |||||
| heartConfig:{ | |||||
| heartbeatInterval:config.heartbeatInterval, | |||||
| dataRefreshInterval:config.dataRefreshInterval, | |||||
| pageChangeInterval:config.pageChangeInterval | |||||
| } | |||||
| }) | |||||
| heartConfig.heartbeatInterval = config.heartbeatInterval | |||||
| heartConfig.dataRefreshInterval=config.dataRefreshInterval | |||||
| heartConfig.pageChangeInterval=config.pageChangeInterval | |||||
| // 动画划入 | // 动画划入 | ||||
| if(config.animationTheme == 0){ | if(config.animationTheme == 0){ | ||||
| this.setState({ | this.setState({ | ||||
| @@ -239,7 +238,7 @@ codePushStatusDidChange(syncStatus) { | |||||
| if (result.code != 200) { | if (result.code != 200) { | ||||
| this.showErrMsg(result.message+'\n'+this.state.macAddress); | this.showErrMsg(result.message+'\n'+this.state.macAddress); | ||||
| } else if (result.data.list) { | } else if (result.data.list) { | ||||
| this.setState({adDataList : result.data.list}); | |||||
| adDataList = result.data.list; | |||||
| if (this.updateContent()) { | if (this.updateContent()) { | ||||
| this.setState({contentDisplayStatus: true}) | this.setState({contentDisplayStatus: true}) | ||||
| } else { | } else { | ||||
| @@ -296,9 +295,9 @@ startAd() { | |||||
| this.getAdDataList() | this.getAdDataList() | ||||
| this.hbRequest() | this.hbRequest() | ||||
| hbRequestCount =this.state.heartConfig.heartbeatInterval; | |||||
| getAdDataCount =this.state.heartConfig.dataRefreshInterval; | |||||
| pageChangeCount =this.state.heartConfig.pageChangeInterval; | |||||
| hbRequestCount =heartConfig.heartbeatInterval; | |||||
| getAdDataCount =heartConfig.dataRefreshInterval; | |||||
| pageChangeCount =heartConfig.pageChangeInterval; | |||||
| setInterval(()=>{ | setInterval(()=>{ | ||||
| hbRequestCount -=1000; | hbRequestCount -=1000; | ||||
| @@ -314,17 +313,13 @@ startAd() { | |||||
| this.getBaseInfo() | this.getBaseInfo() | ||||
| this.getAdDataList() | this.getAdDataList() | ||||
| } | } | ||||
| pageChangeCount = this.state.heartConfig.pageChangeInterval | |||||
| } | |||||
| if (getAdDataCount<=0) { | |||||
| pageChangeCount = heartConfig.pageChangeInterval | |||||
| } else if (getAdDataCount<=0) { | |||||
| this.getAdDataList() | this.getAdDataList() | ||||
| getAdDataCount = this.state.heartConfig.dataRefreshInterval | |||||
| } | |||||
| if (hbRequestCount<=0) { | |||||
| getAdDataCount = heartConfig.dataRefreshInterval | |||||
| }else if (hbRequestCount<=0) { | |||||
| this.hbRequest() | this.hbRequest() | ||||
| hbRequestCount = this.state.heartConfig.heartbeatInterval | |||||
| hbRequestCount = heartConfig.heartbeatInterval | |||||
| } | } | ||||
| },1000) | },1000) | ||||
| } | } | ||||