| @@ -43,12 +43,34 @@ var baseInfoDefault = { | |||||
| } | } | ||||
| var curAdIndex = 0; | var curAdIndex = 0; | ||||
| var errorMsg = { | var errorMsg = { | ||||
| ERR_MAC_GET:'设备编号获取错误', | 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 { | export default class MyPage extends Component { | ||||
| constructor(props) { | constructor(props) { | ||||
| @@ -59,12 +81,15 @@ export default class MyPage extends Component { | |||||
| contentItem0:null, | contentItem0:null, | ||||
| contentItem1:null, | contentItem1:null, | ||||
| contentItem2:null, | contentItem2:null, | ||||
| animationTheme:{}, | |||||
| heartConfig:{ | |||||
| heartbeatInterval:1000*60*5, | |||||
| dataRefreshInterval:1000*60*60, | |||||
| pageChangeInterval:1000*10, | |||||
| }, | |||||
| contentDisplayStatus:false, | contentDisplayStatus:false, | ||||
| syncMessage: "初始化..." , | syncMessage: "初始化..." , | ||||
| errorMessage: '加载中...', | errorMessage: '加载中...', | ||||
| progress: { | progress: { | ||||
| receivedBytes:0, | receivedBytes:0, | ||||
| totalBytes:0 | totalBytes:0 | ||||
| @@ -103,8 +128,6 @@ codePushStatusDidChange(syncStatus) { | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| codePushDownloadDidProgress(progress) { | codePushDownloadDidProgress(progress) { | ||||
| this.setState({ progress }); | this.setState({ progress }); | ||||
| } | } | ||||
| @@ -112,7 +135,7 @@ codePushStatusDidChange(syncStatus) { | |||||
| updateContent() { | updateContent() { | ||||
| if (this.state.adDataList.length <=0) | if (this.state.adDataList.length <=0) | ||||
| return false; | return false; | ||||
| if (curAdIndex >= this.state.adDataList.length) { | if (curAdIndex >= this.state.adDataList.length) { | ||||
| curAdIndex = 0 | curAdIndex = 0 | ||||
| } | } | ||||
| @@ -138,8 +161,37 @@ codePushStatusDidChange(syncStatus) { | |||||
| +encodeURIComponent(this.state.macAddress), | +encodeURIComponent(this.state.macAddress), | ||||
| {version:this.state.versionInfo}) | {version:this.state.versionInfo}) | ||||
| .then(result => { | .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 => { | .catch(error => { | ||||
| this.setState({ errorMessage : ERR_HEARTBEAT}); | |||||
| }) | }) | ||||
| } | } | ||||
| @@ -165,7 +217,7 @@ codePushStatusDidChange(syncStatus) { | |||||
| }) | }) | ||||
| } | } | ||||
| // | |||||
| getBaseInfo() { | getBaseInfo() { | ||||
| HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/info?deviceId='+encodeURIComponent(this.state.macAddress)) | HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/info?deviceId='+encodeURIComponent(this.state.macAddress)) | ||||
| .then(result => { | .then(result => { | ||||
| @@ -200,37 +252,34 @@ componentDidMount() { | |||||
| }, (error: any) => { | }, (error: any) => { | ||||
| this.setState({ versionInfo: "Unknown"}); | 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.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() { | startAd() { | ||||
| this.getBaseInfo() | this.getBaseInfo() | ||||
| this.hbRequest() | |||||
| this.getAdDataList() | this.getAdDataList() | ||||
| setInterval( | setInterval( | ||||
| ()=>{ | ()=>{ | ||||
| if (this.state.contentDisplayStatus) { | if (this.state.contentDisplayStatus) { | ||||
| this.setState({ contentDisplayStatus: false}) | this.setState({ contentDisplayStatus: false}) | ||||
| if (this.updateContent()) { | if (this.updateContent()) { | ||||
| this.setState({ contentDisplayStatus: true}) | this.setState({ contentDisplayStatus: true}) | ||||
| } | } | ||||
| } else { | } else { | ||||
| @@ -238,26 +287,31 @@ startAd() { | |||||
| this.getAdDataList() | this.getAdDataList() | ||||
| } | } | ||||
| }, | }, | ||||
| 1000*10, //10秒更新一下页面 | |||||
| //页面切换间隔 | |||||
| this.state.heartConfig.pageChangeInterval | |||||
| // 1000*10, //10秒更新一下页面 | |||||
| ); | ); | ||||
| setInterval( | setInterval( | ||||
| ()=>{ | ()=>{ | ||||
| this.getAdDataList() | this.getAdDataList() | ||||
| }, | }, | ||||
| 1000*60*60, //1小时一次 | |||||
| // 数据获取间隔 | |||||
| this.state.heartConfig.dataRefreshInterval | |||||
| // 1000*60*60, //1小时一次 | |||||
| ); | ); | ||||
| setInterval( | setInterval( | ||||
| ()=>{ | ()=>{ | ||||
| this.hbRequest() | this.hbRequest() | ||||
| }, | }, | ||||
| 1000*60*5, //5分钟一次 | |||||
| // 心跳间隔 | |||||
| this.state.heartConfig.heartbeatInterval | |||||
| // 1000*60*5, //5分钟一次 | |||||
| ); | ); | ||||
| } | } | ||||
| getContentViewItemUplayer(contentItem) { | getContentViewItemUplayer(contentItem) { | ||||
| if (contentItem.type == 0) { | if (contentItem.type == 0) { | ||||
| if (contentItem.subType == 2) | if (contentItem.subType == 2) | ||||
| return (<Image source={require('./image/timed.png')} resizeMode='center' style={styles.contentItemUpLayer} /> ) | return (<Image source={require('./image/timed.png')} resizeMode='center' style={styles.contentItemUpLayer} /> ) | ||||
| if (contentItem.subType == 6) | if (contentItem.subType == 6) | ||||
| @@ -320,7 +374,6 @@ getContentViewItem(contentItem, annomation) { | |||||
| <View style={styles.contentItemTopDetail}> | <View style={styles.contentItemTopDetail}> | ||||
| {/* 券的title */} | {/* 券的title */} | ||||
| <Text style={styles.contentItemTopDetailTitle} numberOfLines={2} ellipsizeMode="tail">{contentItem.target.title}</Text> | <Text style={styles.contentItemTopDetailTitle} numberOfLines={2} ellipsizeMode="tail">{contentItem.target.title}</Text> | ||||
| {/* <Text style={styles.contentItemTopDetailTitle} numberOfLines={2} ellipsizeMode="tail">你好世界你好你是你好宿舍熟话说术后</Text> */} | |||||
| {/* <Text style={styles.contentItemTopDetailRemark} numberOfLines={1} ellipsizeMode="tail">{contentItem.target.remark}</Text> */} | {/* <Text style={styles.contentItemTopDetailRemark} numberOfLines={1} ellipsizeMode="tail">{contentItem.target.remark}</Text> */} | ||||
| <View style={styles.contentItemTopDetailPrice}> | <View style={styles.contentItemTopDetailPrice}> | ||||
| {/* 售价 */} | {/* 售价 */} | ||||
| @@ -351,9 +404,9 @@ getContentViewItem(contentItem, annomation) { | |||||
| getContentView() { | getContentView() { | ||||
| if (this.state.contentDisplayStatus) { | if (this.state.contentDisplayStatus) { | ||||
| return (<View style={styles.content}> | return (<View style={styles.content}> | ||||
| {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)} | |||||
| </View>) | </View>) | ||||
| }else{ | }else{ | ||||
| return ( | return ( | ||||
| @@ -408,6 +461,8 @@ render() { | |||||
| <Text style={styles.bottomQrcode1Str}>公众号</Text> | <Text style={styles.bottomQrcode1Str}>公众号</Text> | ||||
| </View> | </View> | ||||
| <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text> | <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text> | ||||
| {/* <Text style={styles.bottomPlacehold}>{this.state.heartConfig}</Text> */} | |||||
| </View> | </View> | ||||
| </ImageBackground> | </ImageBackground> | ||||
| ); | ); | ||||