|
-
- import React, { Component } from 'react';
- import {
- Platform,
- StyleSheet,
- Text,
- View,
- Image,
- Dimensions,
- TouchableOpacity,
- ImageBackground,
- } from 'react-native';
-
- //引用插件
- import Package from './package.json'
- import HttpUtils from './HttpUtils.js';
- import CodePush from "react-native-code-push";
- import DeviceInfo from "react-native-device-info";
-
- // 取得屏幕的宽高Dimensions
- const { width, height } = Dimensions.get('window');
-
- export default class MyPage extends Component {
-
- constructor(props) {
- super(props);
- this.state = {
-
- baseInfo: {
- imgUrlH:'',
- imgQrcodeWeapp:'',
- imgQrcodeWemp:''
- },
-
- adData:[],
-
- text:'',
- qrcode:[],
- restartAllowed: true ,
- syncMessage: "syncMessage" ,
- progress: false,
- macAddress: "NULL"
- };
- DeviceInfo.getMACAddress().then(mac=>{this.setState({macAddress:mac})})
- DeviceInfo.getIPAddress().then(mac=>{this.setState({macAddress:mac})})
- }
-
- // 监听更新状态
- codePushStatusDidChange(syncStatus) {
- switch(syncStatus) {
- case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
- this.setState({ syncMessage: "Checking for update." });
- break;
- case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
- this.setState({ syncMessage: "Downloading package." });
- break;
- case CodePush.SyncStatus.AWAITING_USER_ACTION:
- this.setState({ syncMessage: "Awaiting user action." });
- break;
- case CodePush.SyncStatus.INSTALLING_UPDATE:
- this.setState({ syncMessage: "Installing update." });
- break;
- case CodePush.SyncStatus.UP_TO_DATE:
- this.setState({ syncMessage: "App up to date.", progress: false });
- break;
- case CodePush.SyncStatus.UPDATE_IGNORED:
- this.setState({ syncMessage: "Update cancelled by user.", progress: false });
- break;
- case CodePush.SyncStatus.UPDATE_INSTALLED:
- this.setState({ syncMessage: "Update installed and will be applied on restart.", progress: false });
- break;
- case CodePush.SyncStatus.UNKNOWN_ERROR:
- this.setState({ syncMessage: "An unknown error occurred.", progress: false });
- break;
- }
- }
-
-
- codePushDownloadDidProgress(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)
- );
- }
-
-
- getTestData() {
- HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/list?deviceId=11%3AAA%3A33%3ABB%3A44&pageNum=1&pageSize=5')
- .then(result => {
- this.setState({
- adData: result.data.list});
- })
- .catch(error => console.error(error))
- }
-
- getBaseInfo() {
- HttpUtils.get('https://mall.youlane.cn/api/wxDeviceScreenAd/info?deviceId=11%3AAA%3A33%3ABB%3A44')
- .then(result => {
- this.setState({
- baseInfo:result.data});
- })
- .catch(error => console.error(error))
- }
-
-
- componentDidMount() {
- this.getBaseInfo()
- }
-
-
- render() {
- let progressView;
-
- if (this.state.progress) {
- progressView = (
- <Text>{this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received</Text>
- );
- }
-
- return (
- <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}>
-
- <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>
-
-
- <View style={styles.content}>
- <ImageBackground source={require('./image/item-background.png')} resizeMode='center' style={styles.contentItem} >
- </ImageBackground>
-
-
- <ImageBackground source={require('./image/item-background.png')} resizeMode='center' style={styles.contentItem} >
- </ImageBackground>
-
-
- <ImageBackground source={require('./image/item-background.png')} resizeMode='center' style={styles.contentItem} >
- </ImageBackground>
- </View>
-
- <View style={styles.bottom}>
- <Image source={{ uri: this.state.baseInfo.imgUrlH, cache: 'force-cache'}} resizeMode='center' style={styles.bottomLogo} />
- <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} />
- <Text style={styles.bottomPlacehold}>{this.state.text}</Text>
- </View>
-
- </ImageBackground>
- );
-
- }
- }
-
- const styles = StyleSheet.create({
-
- //layer background
- background:{
- flex: 1,
- width:'100%',
- height:'100%'
- },
-
- //layer top
- title:{
- flex: 6,
- flexDirection: 'row',
- alignItems: 'center',
- paddingLeft:16,
- paddingRight:16,
- backgroundColor:'transparent'
- },
-
- content:{
- flex: 18,
- flexDirection: 'column',
- alignItems: 'center',
- backgroundColor:'transparent'
- },
-
- bottom:{
- flex: 2,
- flexDirection: 'row',
- alignItems: 'center',
- paddingLeft:16,
- paddingRight:16,
- backgroundColor:'transparent'
- },
-
- //layer title
- titleImagePlace: {
- flex: 2,
- paddingTop: '20%',
- paddingLeft: '15%',
- alignItems: 'center',
- backgroundColor:'transparent'
- },
- titleImage: {
- width:'100%',
- height:'100%',
- flex: 1,
- backgroundColor:'transparent'
- },
-
- titleQrcodeBonder: {
- width:'100%',
- height:'100%',
- alignItems: 'center',
- flexDirection: 'column',
- flex: 1,
- backgroundColor:'transparent'
- },
-
- titleQrcodePlacehold: {
- flex: 2,
- backgroundColor:'blue'
- },
-
- titleQrcode: {
- flex: 2,
- width:'100%',
- height:'100%',
- backgroundColor:'transparent'
- },
-
- //layer bottom
- bottomLogo: {
- flex: 3,
- width:'100%',
- height:'100%',
- backgroundColor:'transparent'
- },
- bottomQrcode1: {
- flex: 1,
- width:'100%',
- height:'100%',
- marginLeft: 8,
- backgroundColor:'transparent'
- },
- bottomQrcode2: {
- flex: 1,
- width:'100%',
- height:'100%',
- marginLeft: 8,
- backgroundColor:'transparent'
- },
- bottomPlacehold: {
- flex: 8,
- width:'100%',
- height:'100%',
- backgroundColor:'transparent'
- },
-
- //layer content item
- contentItem:{
- flex: 1,
- width:'100%',
- height:'100%',
- flexDirection: 'column',
- alignItems: 'center',
- backgroundColor:'transparent'
- },
-
- });
|