diff --git a/App.js b/App.js
index ebf02d0..c6987f2 100644
--- a/App.js
+++ b/App.js
@@ -77,6 +77,8 @@ var animationThemes = [
}
]
+var timer = null;
+
var hbRequestCount
var getAdDataCount
var pageChangeCount
@@ -108,13 +110,14 @@ export default class MyPage extends Component {
receivedBytes:0,
totalBytes:0
},
+ updating:true,
macAddress: '',
versionInfo:'未知'
};
}
//更新函数
-codePushUpdate() {
+async codePushUpdate() {
CodePush.allowRestart();
CodePush.sync(
@@ -151,22 +154,23 @@ codePushStatusDidChange(syncStatus) {
this.setState({ syncMessage: "安装更新" });
break;
case CodePush.SyncStatus.UP_TO_DATE:
- this.setState({ syncMessage: "已更新到最新程序", progress: false });
+ this.setState({ syncMessage: "已更新到最新程序", updating: false });
break;
case CodePush.SyncStatus.UPDATE_IGNORED:
- this.setState({ syncMessage: "更新被取消", progress: false });
+ this.setState({ syncMessage: "更新被取消", updating: false });
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
- this.setState({ syncMessage: "更新已安装,重启应用后生效", progress: false });
+ this.setState({ syncMessage: "更新已安装,重启应用后生效", updating: false });
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
- this.setState({ syncMessage: "未知错误", progress: false });
+ this.setState({ syncMessage: "未知错误", updating: false });
break;
}
}
codePushDownloadDidProgress(progress) {
this.setState({ progress });
}
+
// 列表滚动
updateContent() {
if (adDataList.length <=0)
@@ -192,7 +196,7 @@ codePushStatusDidChange(syncStatus) {
return true;
}
- hbRequest() {
+ async hbRequest() {
return HttpUtils.post(NativeModules.BuildConfig.apiHost
+ 'api/wxDeviceScreenAd/heartbeat?deviceId='
+ encodeURIComponent(this.state.macAddress),
@@ -241,7 +245,7 @@ codePushStatusDidChange(syncStatus) {
this.setState({errorMessage : errMsg});
}
- getAdDataList(first) {
+ async getAdDataList(first) {
HttpUtils.get(NativeModules.BuildConfig.apiHost
+ 'api/wxDeviceScreenAd/list?deviceId='
+ encodeURIComponent(this.state.macAddress)
@@ -271,7 +275,7 @@ codePushStatusDidChange(syncStatus) {
}
})
}
- getBaseInfo() {
+ async getBaseInfo() {
HttpUtils.get(NativeModules.BuildConfig.apiHost
+ 'api/wxDeviceScreenAd/info?deviceId='
+ encodeURIComponent(this.state.macAddress))
@@ -291,7 +295,7 @@ codePushStatusDidChange(syncStatus) {
}
componentDidMount() {
- this.codePushUpdate();
+ await this.codePushUpdate();
DeviceInfo.getMACAddress().then((mac)=>{
if (mac=='' || mac==null ) {
@@ -310,6 +314,12 @@ componentDidMount() {
})
}
+componentDidUnmount(){
+ if (timer)
+ clearTimeout(timer)
+}
+
+
routine() {
hbRequestCount -=1;
getAdDataCount -=1;
@@ -317,10 +327,10 @@ routine() {
try {
if (getAdDataCount<=0) {
- this.getAdDataList(false)
+ await this.getAdDataList(false)
getAdDataCount = heartConfig.dataRefreshInterval
} else if (hbRequestCount<=0) {
- this.hbRequest()
+ await this.hbRequest()
hbRequestCount = heartConfig.heartbeatInterval
}
@@ -331,8 +341,8 @@ routine() {
this.setState({ contentDisplayStatus: true})
}
} else {
- this.getBaseInfo()
- this.getAdDataList(true)
+ await this.getBaseInfo()
+ await this.getAdDataList(true)
}
pageChangeCount = heartConfig.pageChangeInterval
}
@@ -340,23 +350,16 @@ routine() {
this.setState({ versionInfo: versionInfo+'[E]'});
}
- setTimeout(()=>{
+ timer = setTimeout(()=>{
this.routine();
},1000);
}
-async startAd() {
- this.getBaseInfo()
- this.getAdDataList(true)
- this.hbRequest()
-
+startAd() {
hbRequestCount = heartConfig.heartbeatInterval;
- getAdDataCount =heartConfig.dataRefreshInterval;
- pageChangeCount =heartConfig.pageChangeInterval;
-
- setTimeout(()=>{
- this.routine();
- },1000);
+ getAdDataCount = heartConfig.dataRefreshInterval;
+ pageChangeCount = heartConfig.pageChangeInterval;
+ this.routine();
}
getContentViewItemUplayer(contentItem) {
@@ -469,46 +472,50 @@ getUpdateView() {
);
}
+getAdView(){
+ return (
+
+ {/* 头部title二维码开始 */}
+
+
+
+
+
+
+
+
+
+
+ {/* 券列表展示列表开始 */}
+ {this.getContentView()}
+ {/* 底部商场信息展示开始 */}
+
+
+
+
+
+
+ 小程序
+
+
+
+ 公众号
+
+ {this.state.versionInfo}
+
+
+ );
+
+}
+
render() {
- if (this.state.progress) {
+ if (this.state.updating) {
return this.getUpdateView();
}
-
- return (
-
- {/* 头部title二维码开始 */}
-
-
-
-
-
-
-
-
-
-
- {/* 券列表展示列表开始 */}
- {this.getContentView()}
- {/* 底部商场信息展示开始 */}
-
-
-
-
-
-
- 小程序
-
-
-
- 公众号
-
- {this.state.versionInfo}
-
-
- );
+ return getAdView();
}
- }
+}
const styles = StyleSheet.create({
updatePage:{