| @@ -1,13 +1,10 @@ | |||||
| import React, { Component } from 'react'; | import React, { Component } from 'react'; | ||||
| import { | import { | ||||
| Platform, | |||||
| StyleSheet, | StyleSheet, | ||||
| Text, | Text, | ||||
| View, | View, | ||||
| Image, | Image, | ||||
| Dimensions, | |||||
| TouchableOpacity, | |||||
| ImageBackground, | ImageBackground, | ||||
| } from 'react-native'; | } from 'react-native'; | ||||
| @@ -19,9 +16,6 @@ import DeviceInfo from "react-native-device-info"; | |||||
| import * as Animatable from 'react-native-animatable'; | import * as Animatable from 'react-native-animatable'; | ||||
| // 取得屏幕的宽高Dimensions | |||||
| const { width, height } = Dimensions.get('window'); | |||||
| contentItemDefault = { | contentItemDefault = { | ||||
| coverImg:'', | coverImg:'', | ||||
| qrcode:[], | qrcode:[], | ||||
| @@ -45,23 +39,21 @@ export default class MyPage extends Component { | |||||
| constructor(props) { | constructor(props) { | ||||
| super(props); | super(props); | ||||
| this.state = { | this.state = { | ||||
| baseInfo: baseInfoDefault, | baseInfo: baseInfoDefault, | ||||
| adDataList:[], | adDataList:[], | ||||
| contentItem1:contentItemDefault, | contentItem1:contentItemDefault, | ||||
| contentItem2:contentItemDefault, | contentItem2:contentItemDefault, | ||||
| contentItem3:contentItemDefault, | contentItem3:contentItemDefault, | ||||
| syncMessage: "INIT" , | |||||
| progress: { | |||||
| receivedBytes:0, | |||||
| totalBytes:0 | |||||
| }, | |||||
| macAddress: "NULL", | |||||
| text:'', | text:'', | ||||
| restartAllowed: true , | |||||
| syncMessage: "syncMessage" , | |||||
| progress: false, | |||||
| macAddress: "NULL" | |||||
| versionInfo:'UNKNOWN' | |||||
| }; | }; | ||||
| DeviceInfo.getMACAddress().then(mac=>{this.setState({macAddress:mac})}) | DeviceInfo.getMACAddress().then(mac=>{this.setState({macAddress:mac})}) | ||||
| DeviceInfo.getIPAddress().then(mac=>{this.setState({macAddress:mac})}) | DeviceInfo.getIPAddress().then(mac=>{this.setState({macAddress:mac})}) | ||||
| @@ -102,45 +94,7 @@ codePushStatusDidChange(syncStatus) { | |||||
| this.setState({ progress }); | this.setState({ progress }); | ||||
| } | } | ||||
| // 允许重启后更新 | |||||
| toggleAllowRestart() { | |||||
| this.state.restartAllowed | |||||
| ? CodePush.disallowRestart() | |||||
| : CodePush.allowRestart(); | |||||
| this.setState({ restartAllowed: !this.state.restartAllowed }); | |||||
| } | |||||
| // 获取更新数据 | |||||
| getUpdateMetadata() { | |||||
| CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) | |||||
| .then((metadata: LocalPackage) => { | |||||
| this.setState({ syncMessage: metadata ? JSON.stringify(metadata) : "Running binary version", progress: false }); | |||||
| }, (error: any) => { | |||||
| this.setState({ syncMessage: "Error: " + error, progress: false }); | |||||
| }); | |||||
| } | |||||
| /** Update is downloaded silently, and applied on restart (recommended) 自动更新,一键操作 */ | |||||
| sync() { | |||||
| CodePush.sync( | |||||
| {}, | |||||
| this.codePushStatusDidChange.bind(this), | |||||
| this.codePushDownloadDidProgress.bind(this) | |||||
| ); | |||||
| } | |||||
| /** Update pops a confirmation dialog, and then immediately reboots the app 一键更新,加入的配置项 */ | |||||
| syncImmediate() { | |||||
| CodePush.sync( | |||||
| { installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true }, | |||||
| this.codePushStatusDidChange.bind(this), | |||||
| this.codePushDownloadDidProgress.bind(this) | |||||
| ); | |||||
| } | |||||
| getAdDataList() { | |||||
| getAdDataList() { | |||||
| HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=5') | HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=5') | ||||
| .then(result => { | .then(result => { | ||||
| this.setState({ | this.setState({ | ||||
| @@ -150,32 +104,56 @@ getAdDataList() { | |||||
| contentItem1 : this.state.adDataList[0]}); | contentItem1 : this.state.adDataList[0]}); | ||||
| }) | }) | ||||
| .catch(error => console.error(error)) | .catch(error => console.error(error)) | ||||
| } | |||||
| } | |||||
| getBaseInfo() { | |||||
| getBaseInfo() { | |||||
| HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/info?deviceId=11%3AAA%3A33%3ABB%3A44') | HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/info?deviceId=11%3AAA%3A33%3ABB%3A44') | ||||
| .then(result => { | .then(result => { | ||||
| this.setState({ | this.setState({ | ||||
| baseInfo:result.data}); | baseInfo:result.data}); | ||||
| }) | }) | ||||
| .catch(error => console.error(error)) | .catch(error => console.error(error)) | ||||
| } | |||||
| } | |||||
| componentDidMount() { | componentDidMount() { | ||||
| CodePush.allowRestart(); | |||||
| CodePush.sync( | |||||
| { installMode: CodePush.InstallMode.IMMEDIATE, | |||||
| dialog:{} }, | |||||
| this.codePushStatusDidChange.bind(this), | |||||
| this.codePushDownloadDidProgress.bind(this) | |||||
| ); | |||||
| CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) | |||||
| .then((metadata: LocalPackage) => { | |||||
| this.setState({ versionInfo: metadata ? metadata.appVersion + "-" + metadata.label : "Unknown"}); | |||||
| }, (error: any) => { | |||||
| this.setState({ versionInfo: "Unknown"}); | |||||
| }); | |||||
| this.getBaseInfo() | this.getBaseInfo() | ||||
| this.getAdDataList() | this.getAdDataList() | ||||
| } | } | ||||
| render() { | render() { | ||||
| let progressView; | |||||
| if (this.state.progress) { | if (this.state.progress) { | ||||
| progressView = ( | |||||
| <Text>{this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received</Text> | |||||
| 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'} | |||||
| {this.state.text} | |||||
| </Text> | |||||
| ); | |||||
| return ( | |||||
| <Text style={styles.updatePage}>{this.state.syncMessage}{'\n'} | |||||
| {this.state.text} | |||||
| </Text> | |||||
| ); | ); | ||||
| } | |||||
| } | |||||
| return ( | return ( | ||||
| <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}> | <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}> | ||||
| @@ -303,7 +281,7 @@ render() { | |||||
| </View> | </View> | ||||
| <Image source={{ uri: this.state.baseInfo.imgQrcodeWeapp, cache: 'force-cache'}} resizeMode='center' style={styles.bottomQrcode1} /> | <Image source={{ uri: this.state.baseInfo.imgQrcodeWeapp, cache: 'force-cache'}} resizeMode='center' style={styles.bottomQrcode1} /> | ||||
| <Image source={{ uri: this.state.baseInfo.imgQrcodeWeapp, cache: 'force-cache'}} resizeMode='center' style={styles.bottomQrcode2} /> | <Image source={{ uri: this.state.baseInfo.imgQrcodeWeapp, cache: 'force-cache'}} resizeMode='center' style={styles.bottomQrcode2} /> | ||||
| <Text style={styles.bottomPlacehold}>{this.state.text}</Text> | |||||
| <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text> | |||||
| </View> | </View> | ||||
| </ImageBackground> | </ImageBackground> | ||||
| @@ -313,6 +291,18 @@ render() { | |||||
| } | } | ||||
| const styles = StyleSheet.create({ | const styles = StyleSheet.create({ | ||||
| updatePage:{ | |||||
| flex: 2, | |||||
| width:'100%', | |||||
| height:'100%', | |||||
| backgroundColor:'yellow', | |||||
| textAlign :'center', | |||||
| textAlignVertical:'center', | |||||
| fontSize: 24, | |||||
| color: 'green' | |||||
| }, | |||||
| //layer background | //layer background | ||||
| background:{ | background:{ | ||||
| @@ -415,7 +405,11 @@ render() { | |||||
| flex: 8, | flex: 8, | ||||
| width:'100%', | width:'100%', | ||||
| height:'100%', | height:'100%', | ||||
| backgroundColor:'transparent' | |||||
| backgroundColor:'transparent', | |||||
| textAlign :'right', | |||||
| textAlignVertical:'bottom', | |||||
| fontSize: 10, | |||||
| color : 'gray' | |||||
| }, | }, | ||||
| //layer content item | //layer content item | ||||
| @@ -591,4 +585,5 @@ render() { | |||||
| textDecorationLine: 'line-through', | textDecorationLine: 'line-through', | ||||
| color : 'gray' | color : 'gray' | ||||
| }, | }, | ||||
| }); | }); | ||||