| @@ -106,6 +106,25 @@ export default class MyPage extends Component { | |||||
| versionInfo:'未知' | versionInfo:'未知' | ||||
| }; | }; | ||||
| } | } | ||||
| //更新函数 | |||||
| codePushUpdate() { | |||||
| CodePush.allowRestart(); | |||||
| CodePush.sync( | |||||
| { installMode: CodePush.InstallMode.IMMEDIATE}, | |||||
| this.codePushStatusDidChange.bind(this), | |||||
| this.codePushDownloadDidProgress.bind(this) | |||||
| ); | |||||
| CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) | |||||
| .then((metadata: LocalPackage) => { | |||||
| this.setState({ versionInfo: metadata ? metadata.appVersion +'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : "Unknown"}); | |||||
| }, (error: any) => { | |||||
| this.setState({ versionInfo: "Unknown"}); | |||||
| }); | |||||
| } | |||||
| // 监听更新状态 | // 监听更新状态 | ||||
| codePushStatusDidChange(syncStatus) { | codePushStatusDidChange(syncStatus) { | ||||
| switch(syncStatus) { | switch(syncStatus) { | ||||
| @@ -168,39 +187,42 @@ codePushStatusDidChange(syncStatus) { | |||||
| +encodeURIComponent(this.state.macAddress), | +encodeURIComponent(this.state.macAddress), | ||||
| {version:this.state.versionInfo}) | {version:this.state.versionInfo}) | ||||
| .then(result => { | .then(result => { | ||||
| let config = JSON.parse(result.data.config); | |||||
| this.setState({ | |||||
| heartConfig:{ | |||||
| heartbeatInterval:config.heartbeatInterval, | |||||
| dataRefreshInterval:config.dataRefreshInterval, | |||||
| pageChangeInterval:config.pageChangeInterval | |||||
| } | |||||
| }) | |||||
| // 动画划入 | |||||
| if(config.animationTheme == 0){ | |||||
| this.setState({ | |||||
| animationTheme:animationThemes[0] | |||||
| }) | |||||
| }else if(config.animationTheme == 1){ | |||||
| // 放大 | |||||
| if (result.code == 200) { | |||||
| let config = JSON.parse(result.data.config); | |||||
| this.setState({ | this.setState({ | ||||
| animationTheme:animationThemes[1] | |||||
| }) | |||||
| }else if(config.animationTheme == 2){ | |||||
| // 淡入 | |||||
| this.setState({ | |||||
| animationTheme:animationThemes[2] | |||||
| }) | |||||
| }else if(config.animationTheme == 3){ | |||||
| // 弹入 | |||||
| this.setState({ | |||||
| animationTheme:animationThemes[3] | |||||
| heartConfig:{ | |||||
| heartbeatInterval:config.heartbeatInterval, | |||||
| dataRefreshInterval:config.dataRefreshInterval, | |||||
| pageChangeInterval:config.pageChangeInterval | |||||
| } | |||||
| }) | }) | ||||
| // 动画划入 | |||||
| if(config.animationTheme == 0){ | |||||
| this.setState({ | |||||
| animationTheme:animationThemes[0] | |||||
| }) | |||||
| }else if(config.animationTheme == 1){ | |||||
| // 放大 | |||||
| this.setState({ | |||||
| animationTheme:animationThemes[1] | |||||
| }) | |||||
| }else if(config.animationTheme == 2){ | |||||
| // 淡入 | |||||
| this.setState({ | |||||
| animationTheme:animationThemes[2] | |||||
| }) | |||||
| }else if(config.animationTheme == 3){ | |||||
| // 弹入 | |||||
| this.setState({ | |||||
| animationTheme:animationThemes[3] | |||||
| }) | |||||
| } | |||||
| } else { | |||||
| //do nothing | |||||
| } | } | ||||
| }) | }) | ||||
| .catch(error => { | .catch(error => { | ||||
| console.warn(error) | |||||
| this.setState({ errorMessage : error}); | this.setState({ errorMessage : error}); | ||||
| }) | }) | ||||
| } | } | ||||
| @@ -247,19 +269,8 @@ codePushStatusDidChange(syncStatus) { | |||||
| } | } | ||||
| componentDidMount() { | componentDidMount() { | ||||
| CodePush.allowRestart(); | |||||
| CodePush.sync( | |||||
| { installMode: CodePush.InstallMode.IMMEDIATE}, | |||||
| this.codePushStatusDidChange.bind(this), | |||||
| this.codePushDownloadDidProgress.bind(this) | |||||
| ); | |||||
| this.codePushUpdate(); | |||||
| CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) | |||||
| .then((metadata: LocalPackage) => { | |||||
| this.setState({ versionInfo: metadata ? metadata.appVersion +'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : "Unknown"}); | |||||
| }, (error: any) => { | |||||
| this.setState({ versionInfo: "Unknown"}); | |||||
| }); | |||||
| DeviceInfo.getMACAddress().then((mac)=>{ | DeviceInfo.getMACAddress().then((mac)=>{ | ||||
| if (mac=='' || mac==null ) { | if (mac=='' || mac==null ) { | ||||
| if (NativeModules.BuildConfig.buildType == 'debug') { | if (NativeModules.BuildConfig.buildType == 'debug') { | ||||
| @@ -280,7 +291,6 @@ componentDidMount() { | |||||
| } | } | ||||
| startAd() { | startAd() { | ||||
| this.getBaseInfo() | this.getBaseInfo() | ||||
| this.getAdDataList() | this.getAdDataList() | ||||
| @@ -414,21 +424,24 @@ getContentView() { | |||||
| } | } | ||||
| } | } | ||||
| render() { | |||||
| if (this.state.progress) { | |||||
| if (this.state.progress.totalBytes > 0) | |||||
| return ( | |||||
| <Text style={styles.updatePage}>{this.state.syncMessage}{'\n'} | |||||
| {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'} | |||||
| </Text> | |||||
| ); | |||||
| getUpdateView() { | |||||
| if (this.state.progress.totalBytes > 0) | |||||
| return ( | return ( | ||||
| <Text style={styles.updatePage}>{this.state.syncMessage} | |||||
| <Text style={styles.updatePage}>{this.state.syncMessage}{'\n'} | |||||
| {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'} | |||||
| </Text> | </Text> | ||||
| ); | ); | ||||
| } | |||||
| return ( | |||||
| <Text style={styles.updatePage}>{this.state.syncMessage} | |||||
| </Text> | |||||
| ); | |||||
| } | |||||
| render() { | |||||
| if (this.state.progress) { | |||||
| this.getUpdateView(); | |||||
| } | |||||
| return ( | return ( | ||||
| <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}> | <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}> | ||||