From 4c3342297927ae861fdb9e21fc99b0f15a763e61 Mon Sep 17 00:00:00 2001 From: meo <18801474720@163.com> Date: Thu, 21 Mar 2019 15:58:32 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=95=B0=E6=8D=AE=E5=8A=A8=E6=80=81=E5=8C=96]?= =?UTF-8?q?=E4=BF=AE=E6=94=B9]:[=E4=BF=AE=E6=94=B9=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=8A=A8=E6=80=81=E5=8C=96]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 131 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 38 deletions(-) diff --git a/App.js b/App.js index 518c257..b646204 100644 --- a/App.js +++ b/App.js @@ -43,12 +43,34 @@ var baseInfoDefault = { } var curAdIndex = 0; - var errorMsg = { ERR_MAC_GET:'设备编号获取错误', - ERR_DATA_GET:'广告数据获取错误' - + ERR_START_AD:'广告播放系统错误', + ERR_DATA_GET:'广告数据获取错误', + ERR_HEARTBEAT:'设备心跳数据错误' } +var animationThemes = [ + { + first:"slideInDown", + second:"slideInLeft", + third:"slideInRight" + }, + { + first:"fadeInDownBig", + second:"fadeInLeftBig", + third:"fadeInRightBig" + }, + { + first:"zoomInDown", + second:"zoomInLeft", + third:"zoomInRight" + }, + { + first:"bounceInDown", + second:"bounceInLeft", + third:"bounceInRight" + } +] export default class MyPage extends Component { constructor(props) { @@ -59,12 +81,15 @@ export default class MyPage extends Component { contentItem0:null, contentItem1:null, contentItem2:null, - + animationTheme:{}, + heartConfig:{ + heartbeatInterval:1000*60*5, + dataRefreshInterval:1000*60*60, + pageChangeInterval:1000*10, + }, contentDisplayStatus:false, - syncMessage: "初始化..." , errorMessage: '加载中...', - progress: { receivedBytes:0, totalBytes:0 @@ -103,8 +128,6 @@ codePushStatusDidChange(syncStatus) { break; } } - - codePushDownloadDidProgress(progress) { this.setState({ progress }); } @@ -112,7 +135,7 @@ codePushStatusDidChange(syncStatus) { updateContent() { if (this.state.adDataList.length <=0) return false; - + if (curAdIndex >= this.state.adDataList.length) { curAdIndex = 0 } @@ -138,8 +161,37 @@ codePushStatusDidChange(syncStatus) { +encodeURIComponent(this.state.macAddress), {version:this.state.versionInfo}) .then(result => { + this.setState({ + // heartConfig:{ + // heartbeatInterval:JSON.parse(result.data.config).heartbeatInterval, + // dataRefreshInterval:JSON.parse(result.data.config).dataRefreshInterval, + // pageChangeInterval:JSON.parse(result.data.config).pageChangeInterval + // } + }) + // 动画 + this.setState({ + animationTheme:animationThemes[2] + }) + // if(JSON.parse(result.data.config).animationThem == 0){ + // this.setState({ + // animationTheme:animationThemes[0] + // }) + // }else if(JSON.parse(result.data.config).animationThem == 1){ + // this.setState({ + // animationTheme:animationThemes[1] + // }) + // }else if(JSON.parse(result.data.config).animationThem == 2){ + // this.setState({ + // animationTheme:animationThemes[2] + // }) + // }else if(JSON.parse(result.data.config).animationThem == 3){ + // this.setState({ + // animationTheme:animationThemes[3] + // }) + // } }) .catch(error => { + this.setState({ errorMessage : ERR_HEARTBEAT}); }) } @@ -165,7 +217,7 @@ codePushStatusDidChange(syncStatus) { }) } - // + getBaseInfo() { HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/info?deviceId='+encodeURIComponent(this.state.macAddress)) .then(result => { @@ -200,37 +252,34 @@ componentDidMount() { }, (error: any) => { this.setState({ versionInfo: "Unknown"}); }); - - DeviceInfo.getMACAddress().then((mac)=>{ - if (mac=='') { - if (NativeModules.BuildConfig.buildType == 'debug') { - this.setState({macAddress : this.testMac}) - this.startAd() - } else { - this.setState({ contentDisplayStatus: false}) - this.setState({ errorMessage : errorMsg.ERR_MAC_GET}); - } - } else { - this.setState({macAddress : mac}) + DeviceInfo.getMACAddress().then((mac)=>{ + if (mac=='' || mac==null ) { + if (NativeModules.BuildConfig.buildType == 'debug') { + this.setState({macAddress : this.testMac}) this.startAd() - } - this.setState({ contentDisplayStatus: true}) - }).catch(e => { - this.setState({ contentDisplayStatus: false}) - this.setState({ errorMessage : errorMsg.ERR_MAC_GET}); - }) + } else { + this.setState({ contentDisplayStatus: false}) + this.setState({ errorMessage : errorMsg.ERR_MAC_GET}); + } + } else { + this.setState({macAddress : mac}) + this.startAd() + } + }).catch(e => { + this.setState({ contentDisplayStatus: false}) + this.setState({ errorMessage : errorMsg.ERR_START_AD}); + }) } startAd() { this.getBaseInfo() + this.hbRequest() this.getAdDataList() setInterval( ()=>{ if (this.state.contentDisplayStatus) { - this.setState({ contentDisplayStatus: false}) if (this.updateContent()) { - this.setState({ contentDisplayStatus: true}) } } else { @@ -238,26 +287,31 @@ startAd() { this.getAdDataList() } }, - 1000*10, //10秒更新一下页面 + //页面切换间隔 + this.state.heartConfig.pageChangeInterval + // 1000*10, //10秒更新一下页面 ); setInterval( ()=>{ this.getAdDataList() }, - 1000*60*60, //1小时一次 + // 数据获取间隔 + this.state.heartConfig.dataRefreshInterval + // 1000*60*60, //1小时一次 ); setInterval( ()=>{ this.hbRequest() }, - 1000*60*5, //5分钟一次 + // 心跳间隔 + this.state.heartConfig.heartbeatInterval + // 1000*60*5, //5分钟一次 ); } getContentViewItemUplayer(contentItem) { if (contentItem.type == 0) { - if (contentItem.subType == 2) return ( ) if (contentItem.subType == 6) @@ -320,7 +374,6 @@ getContentViewItem(contentItem, annomation) { {/* 券的title */} {contentItem.target.title} - {/* 你好世界你好你是你好宿舍熟话说术后 */} {/* {contentItem.target.remark} */} {/* 售价 */} @@ -351,9 +404,9 @@ getContentViewItem(contentItem, annomation) { getContentView() { if (this.state.contentDisplayStatus) { return ( - {this.getContentViewItem(this.state.contentItem0,"slideInDown")} - {this.getContentViewItem(this.state.contentItem1,"slideInLeft")} - {this.getContentViewItem(this.state.contentItem2,"slideInRight")} + {this.getContentViewItem(this.state.contentItem0,this.state.animationTheme.first)} + {this.getContentViewItem(this.state.contentItem1,this.state.animationTheme.second)} + {this.getContentViewItem(this.state.contentItem2,this.state.animationTheme.third)} ) }else{ return ( @@ -408,6 +461,8 @@ render() { 公众号 {this.state.versionInfo} + {/* {this.state.heartConfig} */} + );