| @@ -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 ( | |||
| <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}> | |||
| {/* 头部title二维码开始 */} | |||
| <View style={styles.title}> | |||
| <View style={styles.titleImagePlace}> | |||
| <Image source={require('./image/title.png')} resizeMode='center' style={styles.titleImage} /> | |||
| </View> | |||
| <ImageBackground source={require('./image/title-qrcode.png') } resizeMode='center' style={styles.titleQrcodeBonder} > | |||
| <View style={styles.titleQrcodePlacehold}></View> | |||
| <CachedImage source={{uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.titleQrcode} /> | |||
| <View style={styles.titleQrcodePlacehold}></View> | |||
| </ImageBackground> | |||
| </View> | |||
| {/* 券列表展示列表开始 */} | |||
| {this.getContentView()} | |||
| {/* 底部商场信息展示开始 */} | |||
| <View style={styles.bottom}> | |||
| <View style={styles.bottomLogoBackground}> | |||
| <CachedImage source={{ uri: this.state.baseInfo.imgUrlH}} resizeMode='contain' style={styles.bottomLogo} /> | |||
| </View> | |||
| <View style={styles.bottomQrcode1Background}> | |||
| <CachedImage source={{ uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.bottomQrcode1} /> | |||
| <Text style={styles.bottomQrcode1Str}>小程序</Text> | |||
| </View> | |||
| <View style={styles.bottomQrcode2Background}> | |||
| <CachedImage source={{ uri: this.state.baseInfo.imgQrcodeWemp}} resizeMode='center' style={styles.bottomQrcode2} /> | |||
| <Text style={styles.bottomQrcode1Str}>公众号</Text> | |||
| </View> | |||
| <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text> | |||
| </View> | |||
| </ImageBackground> | |||
| ); | |||
| } | |||
| render() { | |||
| if (this.state.progress) { | |||
| if (this.state.updating) { | |||
| return this.getUpdateView(); | |||
| } | |||
| return ( | |||
| <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}> | |||
| {/* 头部title二维码开始 */} | |||
| <View style={styles.title}> | |||
| <View style={styles.titleImagePlace}> | |||
| <Image source={require('./image/title.png')} resizeMode='center' style={styles.titleImage} /> | |||
| </View> | |||
| <ImageBackground source={require('./image/title-qrcode.png') } resizeMode='center' style={styles.titleQrcodeBonder} > | |||
| <View style={styles.titleQrcodePlacehold}></View> | |||
| <Image source={{uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.titleQrcode} /> | |||
| <View style={styles.titleQrcodePlacehold}></View> | |||
| </ImageBackground> | |||
| </View> | |||
| {/* 券列表展示列表开始 */} | |||
| {this.getContentView()} | |||
| {/* 底部商场信息展示开始 */} | |||
| <View style={styles.bottom}> | |||
| <View style={styles.bottomLogoBackground}> | |||
| <Image source={{ uri: this.state.baseInfo.imgUrlH}} resizeMode='contain' style={styles.bottomLogo} /> | |||
| </View> | |||
| <View style={styles.bottomQrcode1Background}> | |||
| <Image source={{ uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.bottomQrcode1} /> | |||
| <Text style={styles.bottomQrcode1Str}>小程序</Text> | |||
| </View> | |||
| <View style={styles.bottomQrcode2Background}> | |||
| <Image source={{ uri: this.state.baseInfo.imgQrcodeWemp}} resizeMode='center' style={styles.bottomQrcode2} /> | |||
| <Text style={styles.bottomQrcode1Str}>公众号</Text> | |||
| </View> | |||
| <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text> | |||
| </View> | |||
| </ImageBackground> | |||
| ); | |||
| return getAdView(); | |||
| } | |||
| } | |||
| } | |||
| const styles = StyleSheet.create({ | |||
| updatePage:{ | |||