|
|
@@ -19,7 +19,7 @@ import DeviceInfo from "react-native-device-info"; |
|
|
|
|
|
|
|
import * as Animatable from 'react-native-animatable'; |
|
|
|
|
|
|
|
var testMac = '11:AA:33:BB:44' |
|
|
|
var testMac = 'FF:FF:FF:FF:FF:FF' |
|
|
|
|
|
|
|
var contentItemDefault = { |
|
|
|
type:0, |
|
|
@@ -44,8 +44,8 @@ var baseInfoDefault = { |
|
|
|
var curAdIndex = 0; |
|
|
|
|
|
|
|
var errorMsg = { |
|
|
|
ERR_MAC_GET:'MAC地址获取错误', |
|
|
|
ERR_DATA_GET:'数据获取错误' |
|
|
|
ERR_MAC_GET:'设备编号获取错误', |
|
|
|
ERR_DATA_GET:'广告数据获取错误' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@@ -62,8 +62,8 @@ export default class MyPage extends Component { |
|
|
|
|
|
|
|
contentDisplayStatus:false, |
|
|
|
|
|
|
|
syncMessage: "Init" , |
|
|
|
errorMessage: 'Loading...', |
|
|
|
syncMessage: "初始化..." , |
|
|
|
errorMessage: '加载中...', |
|
|
|
|
|
|
|
progress: { |
|
|
|
receivedBytes:0, |
|
|
@@ -110,6 +110,9 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
} |
|
|
|
|
|
|
|
updateContent() { |
|
|
|
if (this.state.adDataList.length <=0) |
|
|
|
return false; |
|
|
|
|
|
|
|
if (curAdIndex >= this.state.adDataList.length) { |
|
|
|
curAdIndex = 0 |
|
|
|
} |
|
|
@@ -127,6 +130,7 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
this.setState({contentItem2:null}); |
|
|
|
|
|
|
|
curAdIndex+=3 |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
hbRequest() { |
|
|
@@ -140,50 +144,49 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
} |
|
|
|
|
|
|
|
getAdDataList() { |
|
|
|
HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/list?deviceId='+encodeURIComponent(this.state.macAddress)+'&pageNum=1&pageSize=1000') |
|
|
|
.then(result => { |
|
|
|
HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/list?deviceId='+encodeURIComponent(this.state.macAddress)+'&pageNum=1&pageSize=1000') |
|
|
|
.then((result) => { |
|
|
|
if (result.code != 200) { |
|
|
|
this.setState({errorMessage : result.message}); |
|
|
|
this.setState({contentDisplayStatus: false}) |
|
|
|
} |
|
|
|
if (result.data.list) { |
|
|
|
this.setState({errorMessage : result.message+'\n'+this.state.macAddress}); |
|
|
|
} else if (result.data.list) { |
|
|
|
this.setState({adDataList : result.data.list}); |
|
|
|
this.updateContent(); |
|
|
|
if (this.updateContent()) { |
|
|
|
this.setState({contentDisplayStatus: true}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.setState({errorMessage : errorMsg.ERR_DATA_GET}); |
|
|
|
this.setState({contentDisplayStatus: false}) |
|
|
|
this.setState({errorMessage : errorMsg.ERR_DATA_GET}); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
console.error(error) |
|
|
|
this.setState({errorMessage : error}); |
|
|
|
this.setState({contentDisplayStatus: false}) |
|
|
|
this.setState({errorMessage : error.message}); |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 => { |
|
|
|
if (result.code != 200) { |
|
|
|
this.setState({errorMessage : result.message}); |
|
|
|
this.setState({contentDisplayStatus: false}) |
|
|
|
} |
|
|
|
if (result.data) { |
|
|
|
this.setState({errorMessage : result.message+'\n'+this.state.macAddress}); |
|
|
|
} else if (result.data) { |
|
|
|
this.setState({baseInfo:result.data}); |
|
|
|
} |
|
|
|
else { |
|
|
|
this.setState({errorMessage : errorMsg.ERR_DATA_GET}); |
|
|
|
} else { |
|
|
|
this.setState({contentDisplayStatus: false}) |
|
|
|
this.setState({errorMessage : errorMsg.ERR_DATA_GET}); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
console.error(error) |
|
|
|
this.setState({errorMessage : error}); |
|
|
|
this.setState({contentDisplayStatus: false}) |
|
|
|
this.setState({errorMessage : error.message}); |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
CodePush.allowRestart(); |
|
|
|
CodePush.sync( |
|
|
@@ -199,34 +202,46 @@ 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}); |
|
|
|
}) |
|
|
|
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}) |
|
|
|
this.startAd() |
|
|
|
} |
|
|
|
this.setState({ contentDisplayStatus: true}) |
|
|
|
}).catch(e => { |
|
|
|
this.setState({ contentDisplayStatus: false}) |
|
|
|
this.setState({ errorMessage : errorMsg.ERR_MAC_GET}); |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
startAd(mac) { |
|
|
|
startAd() { |
|
|
|
this.getBaseInfo() |
|
|
|
this.getAdDataList() |
|
|
|
setInterval( |
|
|
|
()=>{ |
|
|
|
this.setState({ contentDisplayStatus: false}) |
|
|
|
this.updateContent(); |
|
|
|
this.setState({ contentDisplayStatus: true}) |
|
|
|
if (this.state.contentDisplayStatus) { |
|
|
|
this.setState({ contentDisplayStatus: false}) |
|
|
|
if (this.updateContent()) { |
|
|
|
this.setState({ contentDisplayStatus: true}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.getBaseInfo() |
|
|
|
this.getAdDataList() |
|
|
|
} |
|
|
|
}, |
|
|
|
1000*10, //10秒更新一下页面 |
|
|
|
); |
|
|
|
setInterval( |
|
|
|
()=>{ |
|
|
|
this.setState({ contentDisplayStatus: false}) |
|
|
|
this.getAdDataList() |
|
|
|
this.setState({ contentDisplayStatus: true}) |
|
|
|
}, |
|
|
|
1000*60*60, //1小时一次 |
|
|
|
); |
|
|
|