From 72ee2b8e96b7eacef361e7aaaf34e71607ce2893 Mon Sep 17 00:00:00 2001 From: hupeng Date: Mon, 25 Mar 2019 12:27:06 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=98=BE=E7=A4=BA][=E4=BF=AE=E5=A4=8D]:?= =?UTF-8?q?=E6=97=A0=E5=B9=BF=E5=91=8A=E6=97=B6=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/App.js b/App.js index 4bd6627..0bd9586 100644 --- a/App.js +++ b/App.js @@ -47,7 +47,8 @@ var errorMsg = { ERR_MAC_GET:'设备编号获取错误', ERR_START_AD:'广告播放系统错误', ERR_DATA_GET:'广告数据获取错误', - ERR_HEARTBEAT:'设备心跳数据错误' + ERR_HEARTBEAT:'设备心跳数据错误', + ERR_NO_DATA:'暂无优惠信息' } var animationThemes = [ // 滑入 @@ -223,49 +224,48 @@ codePushStatusDidChange(syncStatus) { }) .catch(error => { - this.setState({ errorMessage : error}); + this.setState({ errorMessage : error.message}); }) } + showErrMsg(errMsg) { + this.setState({contentDisplayStatus: false}) + this.setState({errorMessage : errMsg}); + } + getAdDataList() { 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({contentDisplayStatus: false}) - this.setState({errorMessage : result.message+'\n'+this.state.macAddress}); + this.showErrMsg(result.message+'\n'+this.state.macAddress); } else if (result.data.list) { this.setState({adDataList : result.data.list}); if (this.updateContent()) { this.setState({contentDisplayStatus: true}) } else { - this.setState({errorMessage : errorMsg.ERR_NO_DATA}); + this.showErrMsg(errorMsg.ERR_NO_DATA); } } else { - this.setState({contentDisplayStatus: false}) - this.setState({errorMessage : errorMsg.ERR_DATA_GET}); +  this.showErrMsg(errorMsg.ERR_DATA_GET); } }) .catch(error => { - this.setState({contentDisplayStatus: false}) - this.setState({errorMessage : error.message}); + this.showErrMsg(error.message); }) } getBaseInfo() { HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/info?deviceId='+encodeURIComponent(this.state.macAddress)) .then(result => { if (result.code != 200) { - this.setState({contentDisplayStatus: false}) - this.setState({errorMessage : result.message+'\n'+this.state.macAddress}); + this.showErrMsg(result.message+'\n'+this.state.macAddress); } else if (result.data) { this.setState({baseInfo:result.data}); } else { - this.setState({contentDisplayStatus: false}) - this.setState({errorMessage : errorMsg.ERR_DATA_GET}); + this.showErrMsg(errorMsg.ERR_DATA_GET); } }) .catch(error => { - this.setState({contentDisplayStatus: false}) - this.setState({errorMessage : error.message}); + this.showErrMsg(error.message); }) } @@ -279,16 +279,14 @@ componentDidMount() { this.setState({macAddress : this.testMac}) this.startAd() } else { - this.setState({ contentDisplayStatus: false}) - this.setState({ errorMessage : errorMsg.ERR_MAC_GET}); + this.showErrMsg(errorMsg.ERR_MAC_GET); } } else { this.setState({macAddress : mac}) this.startAd() } }).catch(e => { - this.setState({ contentDisplayStatus: false}) - this.setState({ errorMessage : errorMsg.ERR_START_AD}); + this.showErrMsg(errorMsg.ERR_START_AD); }) }