diff --git a/App.js b/App.js index 6123477..11cf0f7 100644 --- a/App.js +++ b/App.js @@ -17,6 +17,8 @@ import DeviceInfo from "react-native-device-info"; import * as Animatable from 'react-native-animatable'; contentItemDefault = { + type:0, + subType:0, qrcode:[], target:{ coverImg:'', @@ -36,6 +38,14 @@ baseInfoDefault = { curAdIndex = 0; +testMac = '11:AA:33:BB:44' + +errorMsg = { + ERR_MAC_GET:'MAC地址获取错误', + ERR_DATA_GET:'数据获取错误' + +} + export default class MyPage extends Component { constructor(props) { @@ -47,20 +57,18 @@ export default class MyPage extends Component { contentItem1:null, contentItem2:null, - contentDisplayStatus:true, + contentDisplayStatus:false, syncMessage: "INIT" , + errorMessage: 'Loading...', + progress: { receivedBytes:0, totalBytes:0 }, - macAddress: "NULL", - - text:'', + macAddress: '', versionInfo:'UNKNOWN' }; - DeviceInfo.getMACAddress().then(mac=>{this.setState({macAddress:mac})}) - DeviceInfo.getIPAddress().then(mac=>{this.setState({macAddress:mac})}) } // 监听更新状态 @@ -118,22 +126,58 @@ codePushStatusDidChange(syncStatus) { curAdIndex+=3 } + hbRequest() { + HttpUtils.post('https://mall.youlane.cn/api/wxDeviceScreenAd/heartbeat?deviceId=' + +encodeURIComponent(this.state.macAddress), + {version:this.state.versionInfo}) + .then(result => { + }) + .catch(error => { + }) + } + getAdDataList() { - HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=30') + HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId='+encodeURIComponent(this.state.macAddress)+'&pageNum=1&pageSize=1000') .then(result => { - this.setState({adDataList : result.data.list}); - this.updateContent(); - }) - .catch(error => console.error(error)) + if (result.code != 200) { + this.setState({errorMessage : result.message}); + this.setState({contentDisplayStatus: false}) + } + if (result.data.list) { + this.setState({adDataList : result.data.list}); + this.updateContent(); + } else { + this.setState({errorMessage : errorMsg.ERR_DATA_GET}); + this.setState({contentDisplayStatus: false}) + } + }) + .catch(error => { + console.error(error) + this.setState({errorMessage : error}); + this.setState({contentDisplayStatus: false}) + }) } getBaseInfo() { - HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/info?deviceId=11%3AAA%3A33%3ABB%3A44') + HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/info?deviceId='+encodeURIComponent(this.state.macAddress)) .then(result => { - this.setState({ - baseInfo:result.data}); + if (result.code != 200) { + this.setState({errorMessage : result.message}); + this.setState({contentDisplayStatus: false}) + } + if (result.data) { + this.setState({baseInfo:result.data}); + } + else { + this.setState({errorMessage : errorMsg.ERR_DATA_GET}); + this.setState({contentDisplayStatus: false}) + } + }) + .catch(error => { + console.error(error) + this.setState({errorMessage : error}); + this.setState({contentDisplayStatus: false}) }) - .catch(error => console.error(error)) } @@ -152,32 +196,56 @@ componentDidMount() { this.setState({ versionInfo: "Unknown"}); }); + DeviceInfo.getMACAddress().then(mac=>{ + if (mac=='') { + this.startAd(testMac) + } else { + this.startAd(mac) + } + this.setState({ contentDisplayStatus: true}) + }).catch(e => { + this.setState({errorMessage : errorMsg.ERR_MAC_GET}); + }) +} + +startAd(mac) { this.getBaseInfo() this.getAdDataList() - setInterval( ()=>{ this.setState({ contentDisplayStatus: false}) this.updateContent(); this.setState({ contentDisplayStatus: true}) }, - 1000 * 10, //10秒更新一下页面 + 1000*10, //10秒更新一下页面 ); setInterval( ()=>{ this.setState({ contentDisplayStatus: false}) - this.updateContent(); + this.getAdDataList() this.setState({ contentDisplayStatus: true}) }, 1000*60*60, //1小时一次 ); + setInterval( + ()=>{ + this.hbRequest() + }, + 1000*60*5, //5分钟一次 + ); + } getContentViewItemUplayer(contentItem) { - if (contentItem.target.type == 8) - return ( ) - else if (contentItem.target.type == 9) - return ( ) + if (contentItem.type == 0) { + + if (contentItem.subType == 2) + return ( ) + if (contentItem.subType == 6) + return ( ) + if (contentItem.subType == 7) + return ( ) + } } getContentViewItem(contentItem, annomation) { @@ -186,6 +254,7 @@ getContentViewItem(contentItem, annomation) { ) + actionText = '扫码领取'; if (contentItem.target.type == 8) @@ -244,7 +313,9 @@ getContentView() { {this.getContentViewItem(this.state.contentItem2,"slideInRight")} ) }else{ - return ( + return ( + + {this.state.errorMessage} ) } } @@ -255,13 +326,11 @@ render() { if (this.state.progress.totalBytes > 0) return ( {this.state.syncMessage}{'\n'} - {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'} - {this.state.text} + {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'} ); return ( - {this.state.syncMessage}{'\n'} - {this.state.text} + {this.state.syncMessage} ); } @@ -309,15 +378,13 @@ render() { flex: 2, width:'100%', height:'100%', - backgroundColor:'yellow', + backgroundColor:'transparent', textAlign :'center', textAlignVertical:'center', fontSize: 24, - color: 'green' + color: 'darkblue' }, - - //layer background background:{ flex: 1, @@ -390,7 +457,7 @@ render() { //layer bottom bottomLogoBackground: { flex: 3, - borderRadius:10, + borderRadius:6, marginTop: 10, marginBottom: 10, backgroundColor:'white' @@ -486,7 +553,7 @@ render() { contentItemUpLayer:{ width:80, - height:60, + height:58, position:'absolute', backgroundColor:'transparent' }, @@ -553,6 +620,7 @@ render() { fontSize: 10, fontWeight : 'bold' }, + contentItemBottomPlacehold:{ flex: 6, paddingLeft: 10, @@ -561,6 +629,7 @@ render() { height:'100%', backgroundColor:'transparent', }, + contentItemBottomAction:{ flex: 5, width:'100%', @@ -593,6 +662,7 @@ render() { fontSize: 10, color : 'gray' }, + contentItemTopDetailPrice:{ flex: 2, width:'100%', @@ -608,6 +678,7 @@ render() { flexDirection: 'row', backgroundColor:'transparent', }, + contentItemTopDetailCurPriceStr:{ backgroundColor:'transparent', textAlign :'left', diff --git a/image/groupbuy.png b/image/groupbuy.png index c1e689e..5807f8b 100644 Binary files a/image/groupbuy.png and b/image/groupbuy.png differ diff --git a/image/timed.png b/image/timed.png new file mode 100644 index 0000000..b359dc3 Binary files /dev/null and b/image/timed.png differ