Переглянути джерело

[网络][修改]:优化网络获取数据的方式

tags/jenkins-front-end-screenad-188-v104
hupeng 5 роки тому
джерело
коміт
79512a4e6f
1 змінених файлів з 67 додано та 60 видалено
  1. +67
    -60
      App.js

+ 67
- 60
App.js Переглянути файл

@@ -77,6 +77,8 @@ var animationThemes = [
} }
] ]


var timer = null;

var hbRequestCount var hbRequestCount
var getAdDataCount var getAdDataCount
var pageChangeCount var pageChangeCount
@@ -108,13 +110,14 @@ export default class MyPage extends Component {
receivedBytes:0, receivedBytes:0,
totalBytes:0 totalBytes:0
}, },
updating:true,
macAddress: '', macAddress: '',
versionInfo:'未知' versionInfo:'未知'
}; };
} }


//更新函数 //更新函数
codePushUpdate() {
async codePushUpdate() {
CodePush.allowRestart(); CodePush.allowRestart();
CodePush.sync( CodePush.sync(
@@ -151,22 +154,23 @@ codePushStatusDidChange(syncStatus) {
this.setState({ syncMessage: "安装更新" }); this.setState({ syncMessage: "安装更新" });
break; break;
case CodePush.SyncStatus.UP_TO_DATE: case CodePush.SyncStatus.UP_TO_DATE:
this.setState({ syncMessage: "已更新到最新程序", progress: false });
this.setState({ syncMessage: "已更新到最新程序", updating: false });
break; break;
case CodePush.SyncStatus.UPDATE_IGNORED: case CodePush.SyncStatus.UPDATE_IGNORED:
this.setState({ syncMessage: "更新被取消", progress: false });
this.setState({ syncMessage: "更新被取消", updating: false });
break; break;
case CodePush.SyncStatus.UPDATE_INSTALLED: case CodePush.SyncStatus.UPDATE_INSTALLED:
this.setState({ syncMessage: "更新已安装,重启应用后生效", progress: false });
this.setState({ syncMessage: "更新已安装,重启应用后生效", updating: false });
break; break;
case CodePush.SyncStatus.UNKNOWN_ERROR: case CodePush.SyncStatus.UNKNOWN_ERROR:
this.setState({ syncMessage: "未知错误", progress: false });
this.setState({ syncMessage: "未知错误", updating: false });
break; break;
} }
} }
codePushDownloadDidProgress(progress) { codePushDownloadDidProgress(progress) {
this.setState({ progress }); this.setState({ progress });
} }

// 列表滚动 // 列表滚动
updateContent() { updateContent() {
if (adDataList.length <=0) if (adDataList.length <=0)
@@ -192,7 +196,7 @@ codePushStatusDidChange(syncStatus) {
return true; return true;
} }
hbRequest() {
async hbRequest() {
return HttpUtils.post(NativeModules.BuildConfig.apiHost return HttpUtils.post(NativeModules.BuildConfig.apiHost
+ 'api/wxDeviceScreenAd/heartbeat?deviceId=' + 'api/wxDeviceScreenAd/heartbeat?deviceId='
+ encodeURIComponent(this.state.macAddress), + encodeURIComponent(this.state.macAddress),
@@ -241,7 +245,7 @@ codePushStatusDidChange(syncStatus) {
this.setState({errorMessage : errMsg}); this.setState({errorMessage : errMsg});
} }


getAdDataList(first) {
async getAdDataList(first) {
HttpUtils.get(NativeModules.BuildConfig.apiHost HttpUtils.get(NativeModules.BuildConfig.apiHost
+ 'api/wxDeviceScreenAd/list?deviceId=' + 'api/wxDeviceScreenAd/list?deviceId='
+ encodeURIComponent(this.state.macAddress) + encodeURIComponent(this.state.macAddress)
@@ -271,7 +275,7 @@ codePushStatusDidChange(syncStatus) {
} }
}) })
} }
getBaseInfo() {
async getBaseInfo() {
HttpUtils.get(NativeModules.BuildConfig.apiHost HttpUtils.get(NativeModules.BuildConfig.apiHost
+ 'api/wxDeviceScreenAd/info?deviceId=' + 'api/wxDeviceScreenAd/info?deviceId='
+ encodeURIComponent(this.state.macAddress)) + encodeURIComponent(this.state.macAddress))
@@ -291,7 +295,7 @@ codePushStatusDidChange(syncStatus) {
} }


componentDidMount() { componentDidMount() {
this.codePushUpdate();
await this.codePushUpdate();


DeviceInfo.getMACAddress().then((mac)=>{ DeviceInfo.getMACAddress().then((mac)=>{
if (mac=='' || mac==null ) { if (mac=='' || mac==null ) {
@@ -310,6 +314,12 @@ componentDidMount() {
}) })
} }


componentDidUnmount(){
if (timer)
clearTimeout(timer)
}


routine() { routine() {
hbRequestCount -=1; hbRequestCount -=1;
getAdDataCount -=1; getAdDataCount -=1;
@@ -317,10 +327,10 @@ routine() {


try { try {
if (getAdDataCount<=0) { if (getAdDataCount<=0) {
this.getAdDataList(false)
await this.getAdDataList(false)
getAdDataCount = heartConfig.dataRefreshInterval getAdDataCount = heartConfig.dataRefreshInterval
} else if (hbRequestCount<=0) { } else if (hbRequestCount<=0) {
this.hbRequest()
await this.hbRequest()
hbRequestCount = heartConfig.heartbeatInterval hbRequestCount = heartConfig.heartbeatInterval
} }


@@ -331,8 +341,8 @@ routine() {
this.setState({ contentDisplayStatus: true}) this.setState({ contentDisplayStatus: true})
} }
} else { } else {
this.getBaseInfo()
this.getAdDataList(true)
await this.getBaseInfo()
await this.getAdDataList(true)
} }
pageChangeCount = heartConfig.pageChangeInterval pageChangeCount = heartConfig.pageChangeInterval
} }
@@ -340,23 +350,16 @@ routine() {
this.setState({ versionInfo: versionInfo+'[E]'}); this.setState({ versionInfo: versionInfo+'[E]'});
} }


setTimeout(()=>{
timer = setTimeout(()=>{
this.routine(); this.routine();
},1000); },1000);
} }


async startAd() {
this.getBaseInfo()
this.getAdDataList(true)
this.hbRequest()
startAd() {
hbRequestCount = heartConfig.heartbeatInterval; hbRequestCount = heartConfig.heartbeatInterval;
getAdDataCount =heartConfig.dataRefreshInterval;
pageChangeCount =heartConfig.pageChangeInterval;

setTimeout(()=>{
this.routine();
},1000);
getAdDataCount = heartConfig.dataRefreshInterval;
pageChangeCount = heartConfig.pageChangeInterval;
this.routine();
} }


getContentViewItemUplayer(contentItem) { 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() { render() {


if (this.state.progress) {
if (this.state.updating) {
return this.getUpdateView(); 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({ const styles = StyleSheet.create({
updatePage:{ updatePage:{


Завантаження…
Відмінити
Зберегти