From 8f360c937117ef4d21ee2e060965a13076e3dc78 Mon Sep 17 00:00:00 2001 From: hupeng Date: Mon, 5 Aug 2019 14:20:18 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=BD=91=E7=BB=9C][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BD=91=E7=BB=9C=E8=8E=B7=E5=8F=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 125 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 56 deletions(-) diff --git a/App.js b/App.js index c6987f2..4c9c941 100644 --- a/App.js +++ b/App.js @@ -22,26 +22,6 @@ import * as Animatable from 'react-native-animatable'; import {CachedImage,ImageCache} from "react-native-img-cache"; var testMac = 'FF:FF:FF:FF:FF:FF' -var contentItemDefault = { - type:0, - subType:0, - qrcode:[], - target:{ - coverImg:'', - title:'', - subTitle:'', - priceStr:'', - salePriceStr:'', - remark:'', - } -} - -var baseInfoDefault = { - imgUrlH:'', - imgQrcodeWeapp:'', - imgQrcodeWemp:'' -} - var curAdIndex = 0; var errorMsg = { ERR_MAC_GET:'设备编号获取错误', @@ -94,11 +74,20 @@ var heartConfig = { var requestFailedCount = 0; var versionInfo = ''; + +let codePushOptions = { + //设置检查更新的频率 + //ON_APP_RESUME APP恢复到前台的时候 + //ON_APP_START APP开启的时候 + //MANUAL 手动检查 + checkFrequency : CodePush.CheckFrequency.ON_APP_START +}; + export default class MyPage extends Component { constructor(props) { super(props); this.state = { - baseInfo: baseInfoDefault, + baseInfo: null, contentItem0:null, contentItem1:null, contentItem2:null, @@ -118,23 +107,24 @@ export default class MyPage extends Component { //更新函数 async codePushUpdate() { - CodePush.allowRestart(); - CodePush.sync( - - { mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE, - installMode: CodePush.InstallMode.IMMEDIATE}, - this.codePushStatusDidChange.bind(this), - this.codePushDownloadDidProgress.bind(this) - ); - CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) - .then((metadata: LocalPackage) => { - this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode}); - versionInfo = this.state.versionInfo; - }, (error: any) => { - this.setState({ versionInfo: "Unknown"}); - versionInfo = this.state.versionInfo; - }); + await CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) + .then((metadata: LocalPackage) => { + this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode}); + versionInfo = this.state.versionInfo; + }, (error: any) => { + this.setState({ versionInfo: "Unknown"}); + versionInfo = this.state.versionInfo; + }); + await CodePush.disallowRestart(); + await CodePush.sync( + { mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE, + installMode: CodePush.InstallMode.IMMEDIATE}, + this.codePushStatusDidChange.bind(this), + this.codePushDownloadDidProgress.bind(this) + ); + await CodePush.allowRestart(); + } @@ -196,7 +186,7 @@ codePushStatusDidChange(syncStatus) { return true; } - async hbRequest() { + hbRequest() { return HttpUtils.post(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/heartbeat?deviceId=' + encodeURIComponent(this.state.macAddress), @@ -245,7 +235,7 @@ codePushStatusDidChange(syncStatus) { this.setState({errorMessage : errMsg}); } - async getAdDataList(first) { + getAdDataList(first) { HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/list?deviceId=' + encodeURIComponent(this.state.macAddress) @@ -254,7 +244,6 @@ codePushStatusDidChange(syncStatus) { if (result.code != 200) { this.showErrMsg(result.message+'\n'+this.state.macAddress); } else if (result.data.list) { - ImageCache.get().clear(); adDataList = result.data.list; if (this.updateContent()) { this.setState({contentDisplayStatus: true}) @@ -275,7 +264,7 @@ codePushStatusDidChange(syncStatus) { } }) } - async getBaseInfo() { + getBaseInfo() { HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/info?deviceId=' + encodeURIComponent(this.state.macAddress)) @@ -295,7 +284,7 @@ codePushStatusDidChange(syncStatus) { } componentDidMount() { - await this.codePushUpdate(); + this.codePushUpdate(); DeviceInfo.getMACAddress().then((mac)=>{ if (mac=='' || mac==null ) { @@ -314,28 +303,28 @@ componentDidMount() { }) } -componentDidUnmount(){ +componentWillUnmount(){ if (timer) clearTimeout(timer) } -routine() { +async routine() { hbRequestCount -=1; getAdDataCount -=1; pageChangeCount -=1; try { if (getAdDataCount<=0) { - await this.getAdDataList(false) + this.getAdDataList(false) getAdDataCount = heartConfig.dataRefreshInterval } else if (hbRequestCount<=0) { - await this.hbRequest() + this.hbRequest() hbRequestCount = heartConfig.heartbeatInterval } if (pageChangeCount <= 0) { //页面切换间隔 - if (this.state.contentDisplayStatus) { + if (this.state.contentDisplayStatus && this.state.baseInfo) { this.setState({ contentDisplayStatus: false}) if (this.updateContent()) { this.setState({ contentDisplayStatus: true}) @@ -343,6 +332,8 @@ routine() { } else { await this.getBaseInfo() await this.getAdDataList(true) + getAdDataCount = heartConfig.dataRefreshInterval + hbRequestCount = heartConfig.heartbeatInterval } pageChangeCount = heartConfig.pageChangeInterval } @@ -356,9 +347,9 @@ routine() { } startAd() { - hbRequestCount = heartConfig.heartbeatInterval; - getAdDataCount = heartConfig.dataRefreshInterval; - pageChangeCount = heartConfig.pageChangeInterval; + hbRequestCount = 0; + getAdDataCount = 0; + pageChangeCount = 0; this.routine(); } @@ -473,6 +464,7 @@ getUpdateView() { } getAdView(){ + if (this.state.baseInfo) { return ( {/* 头部title二维码开始 */} @@ -482,7 +474,7 @@ getAdView(){ - + @@ -491,20 +483,41 @@ getAdView(){ {/* 底部商场信息展示开始 */} - + - + 小程序 - + 公众号 {this.state.versionInfo} - ); + );} + else { + return ( + + {/* 头部title二维码开始 */} + + + {/* 券列表展示列表开始 */} + {this.getContentView()} + {/* 底部商场信息展示开始 */} + + + + + + + + {this.state.versionInfo} + + + ); + } } @@ -513,7 +526,7 @@ render() { if (this.state.updating) { return this.getUpdateView(); } - return getAdView(); + return this.getAdView(); } }