|
|
@@ -17,31 +17,9 @@ import Package from './package.json' |
|
|
|
import HttpUtils from './HttpUtils.js'; |
|
|
|
import CodePush from "react-native-code-push"; |
|
|
|
import DeviceInfo from "react-native-device-info"; |
|
|
|
import RNFetchBlob from 'react-native-fetch-blob'; |
|
|
|
import * as Animatable from 'react-native-animatable'; |
|
|
|
import {CachedImage,ImageCache} from "react-native-img-cache"; |
|
|
|
var testMac = 'FF:FF:FF:FF:FF:FF' |
|
|
|
|
|
|
|
var contentItemDefault = { |
|
|
|
type:0, |
|
|
|
subType:0, |
|
|
|
qrcode:[], |
|
|
|
target:{ |
|
|
|
coverImg:'', |
|
|
|
title:'', |
|
|
|
subTitle:'', |
|
|
|
priceStr:'', |
|
|
|
salePriceStr:'', |
|
|
|
remark:'', |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var baseInfoDefault = { |
|
|
|
imgUrlH:'', |
|
|
|
imgQrcodeWeapp:'', |
|
|
|
imgQrcodeWemp:'' |
|
|
|
} |
|
|
|
|
|
|
|
var curAdIndex = 0; |
|
|
|
var errorMsg = { |
|
|
|
ERR_MAC_GET:'设备编号获取错误', |
|
|
@@ -77,6 +55,8 @@ var animationThemes = [ |
|
|
|
} |
|
|
|
] |
|
|
|
|
|
|
|
var timer = null; |
|
|
|
|
|
|
|
var hbRequestCount |
|
|
|
var getAdDataCount |
|
|
|
var pageChangeCount |
|
|
@@ -92,11 +72,21 @@ var heartConfig = { |
|
|
|
var requestFailedCount = 0; |
|
|
|
var versionInfo = ''; |
|
|
|
|
|
|
|
|
|
|
|
let codePushOptions = { |
|
|
|
//设置检查更新的频率 |
|
|
|
//ON_APP_RESUME APP恢复到前台的时候 |
|
|
|
//ON_APP_START APP开启的时候 |
|
|
|
//MANUAL 手动检查 |
|
|
|
checkFrequency : CodePush.CheckFrequency.ON_APP_START |
|
|
|
}; |
|
|
|
|
|
|
|
export default class MyPage extends Component { |
|
|
|
|
|
|
|
constructor(props) { |
|
|
|
super(props); |
|
|
|
this.state = { |
|
|
|
baseInfo: baseInfoDefault, |
|
|
|
baseInfo: null, |
|
|
|
contentItem0:null, |
|
|
|
contentItem1:null, |
|
|
|
contentItem2:null, |
|
|
@@ -108,30 +98,33 @@ export default class MyPage extends Component { |
|
|
|
receivedBytes:0, |
|
|
|
totalBytes:0 |
|
|
|
}, |
|
|
|
updating:true, |
|
|
|
macAddress: '', |
|
|
|
versionInfo:'未知' |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
//更新函数 |
|
|
|
codePushUpdate() { |
|
|
|
CodePush.allowRestart(); |
|
|
|
CodePush.sync( |
|
|
|
|
|
|
|
{ mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE, |
|
|
|
installMode: CodePush.InstallMode.IMMEDIATE}, |
|
|
|
this.codePushStatusDidChange.bind(this), |
|
|
|
this.codePushDownloadDidProgress.bind(this) |
|
|
|
); |
|
|
|
async codePushUpdate() { |
|
|
|
CodePush.allowRestart(); |
|
|
|
await CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) |
|
|
|
.then((metadata: LocalPackage) => { |
|
|
|
this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode}); |
|
|
|
versionInfo = this.state.versionInfo; |
|
|
|
}, (error: any) => { |
|
|
|
this.setState({ versionInfo: "Unknown"}); |
|
|
|
versionInfo = this.state.versionInfo; |
|
|
|
}); |
|
|
|
await CodePush.sync( |
|
|
|
{ mandatoryInstallMode: CodePush.InstallMode.ON_NEXT_RESTART, |
|
|
|
installMode: CodePush.InstallMode.ON_NEXT_RESTART}, |
|
|
|
this.codePushStatusDidChange.bind(this), |
|
|
|
this.codePushDownloadDidProgress.bind(this) |
|
|
|
).then((status: SyncStatus) => { |
|
|
|
|
|
|
|
CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) |
|
|
|
.then((metadata: LocalPackage) => { |
|
|
|
this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode}); |
|
|
|
versionInfo = this.state.versionInfo; |
|
|
|
}, (error: any) => { |
|
|
|
this.setState({ versionInfo: "Unknown"}); |
|
|
|
versionInfo = this.state.versionInfo; |
|
|
|
}); |
|
|
|
CodePush.restartApp(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@@ -151,22 +144,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) |
|
|
@@ -250,7 +244,6 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
if (result.code != 200) { |
|
|
|
this.showErrMsg(result.message+'\n'+this.state.macAddress); |
|
|
|
} else if (result.data.list) { |
|
|
|
ImageCache.get().clear(); |
|
|
|
adDataList = result.data.list; |
|
|
|
if (this.updateContent()) { |
|
|
|
this.setState({contentDisplayStatus: true}) |
|
|
@@ -271,7 +264,7 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
getBaseInfo() { |
|
|
|
getBaseInfo() { |
|
|
|
HttpUtils.get(NativeModules.BuildConfig.apiHost |
|
|
|
+ 'api/wxDeviceScreenAd/info?deviceId=' |
|
|
|
+ encodeURIComponent(this.state.macAddress)) |
|
|
@@ -310,7 +303,13 @@ componentDidMount() { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
routine() { |
|
|
|
componentWillUnmount(){ |
|
|
|
if (timer) |
|
|
|
clearTimeout(timer) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async routine() { |
|
|
|
hbRequestCount -=1; |
|
|
|
getAdDataCount -=1; |
|
|
|
pageChangeCount -=1; |
|
|
@@ -325,14 +324,16 @@ routine() { |
|
|
|
} |
|
|
|
|
|
|
|
if (pageChangeCount <= 0) { //页面切换间隔 |
|
|
|
if (this.state.contentDisplayStatus) { |
|
|
|
if (this.state.contentDisplayStatus && this.state.baseInfo) { |
|
|
|
this.setState({ contentDisplayStatus: false}) |
|
|
|
if (this.updateContent()) { |
|
|
|
this.setState({ contentDisplayStatus: true}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.getBaseInfo() |
|
|
|
this.getAdDataList(true) |
|
|
|
await this.getBaseInfo() |
|
|
|
await this.getAdDataList(true) |
|
|
|
getAdDataCount = heartConfig.dataRefreshInterval |
|
|
|
hbRequestCount = heartConfig.heartbeatInterval |
|
|
|
} |
|
|
|
pageChangeCount = heartConfig.pageChangeInterval |
|
|
|
} |
|
|
@@ -340,23 +341,16 @@ routine() { |
|
|
|
this.setState({ versionInfo: versionInfo+'[E]'}); |
|
|
|
} |
|
|
|
|
|
|
|
setTimeout(()=>{ |
|
|
|
timer = setTimeout(()=>{ |
|
|
|
this.routine(); |
|
|
|
},1000); |
|
|
|
} |
|
|
|
|
|
|
|
async startAd() { |
|
|
|
this.getBaseInfo() |
|
|
|
this.getAdDataList(true) |
|
|
|
this.hbRequest() |
|
|
|
|
|
|
|
hbRequestCount = heartConfig.heartbeatInterval; |
|
|
|
getAdDataCount =heartConfig.dataRefreshInterval; |
|
|
|
pageChangeCount =heartConfig.pageChangeInterval; |
|
|
|
|
|
|
|
setTimeout(()=>{ |
|
|
|
this.routine(); |
|
|
|
},1000); |
|
|
|
startAd() { |
|
|
|
hbRequestCount = 0; |
|
|
|
getAdDataCount = 0; |
|
|
|
pageChangeCount = 0; |
|
|
|
this.routine(); |
|
|
|
} |
|
|
|
|
|
|
|
getContentViewItemUplayer(contentItem) { |
|
|
@@ -410,7 +404,7 @@ getContentViewItem(contentItem, annomation) { |
|
|
|
<ImageBackground source={require('./image/item-background.png')} resizeMode='center' style={styles.contentItemDownLayer} > |
|
|
|
{/* 列表 */} |
|
|
|
<View style={styles.contentItemTop}> |
|
|
|
<CachedImage source={{uri: contentItem.coverImg}} resizeMode='cover' style={styles.contentItemTopCoverImg} /> |
|
|
|
<Image source={{uri: contentItem.coverImg}} resizeMode='cover' style={styles.contentItemTopCoverImg} /> |
|
|
|
<View style={styles.contentItemTopDetail}> |
|
|
|
{/* 券的title */} |
|
|
|
<Text style={styles.contentItemTopDetailTitle} numberOfLines={2} ellipsizeMode="tail">{contentItem.target.title}</Text> |
|
|
@@ -427,7 +421,7 @@ getContentViewItem(contentItem, annomation) { |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
{/* <Image source={{uri:'data:image/png;base64,'+contentItem.qrcode}} resizeMode='contain' style={styles.contentItemTopQrcode} /> */} |
|
|
|
<CachedImage source={{uri:contentItem.target.qrCode}} resizeMode='contain' style={styles.contentItemTopQrcode} /> |
|
|
|
<Image source={{uri:contentItem.target.qrCode}} resizeMode='contain' style={styles.contentItemTopQrcode} /> |
|
|
|
</View> |
|
|
|
{/* 优惠券底部商户名称 */} |
|
|
|
<View style={styles.contentItemBottom}> |
|
|
@@ -469,47 +463,73 @@ getUpdateView() { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
render() { |
|
|
|
|
|
|
|
if (this.state.progress) { |
|
|
|
return this.getUpdateView(); |
|
|
|
} |
|
|
|
|
|
|
|
getAdView(){ |
|
|
|
if (this.state.baseInfo) { |
|
|
|
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> |
|
|
|
);} |
|
|
|
else { |
|
|
|
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> |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
render() { |
|
|
|
|
|
|
|
if (this.state.updating) { |
|
|
|
return this.getUpdateView(); |
|
|
|
} |
|
|
|
return this.getAdView(); |
|
|
|
} |
|
|
|
} |
|
|
|
MyPage = CodePush(codePushOptions)(MyPage); |
|
|
|
const styles = StyleSheet.create({ |
|
|
|
updatePage:{ |
|
|
|
flex: 2, |
|
|
@@ -874,5 +894,4 @@ render() { |
|
|
|
textDecorationLine: 'line-through', |
|
|
|
color : 'gray' |
|
|
|
}, |
|
|
|
|
|
|
|
}); |