广告屏react-native项目
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

1309 linhas
36 KiB

  1. import React, { Component } from 'react';
  2. import {
  3. Platform,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Image,
  8. ImageBackground,
  9. PixelRatio,
  10. NativeModules,
  11. } from 'react-native';
  12. //引用插件
  13. import Package from './package.json'
  14. import HttpUtils from './HttpUtils.js';
  15. import CodePush from "react-native-code-push";
  16. import DeviceInfo from "react-native-device-info";
  17. import * as Animatable from 'react-native-animatable';
  18. import Swiper from 'react-native-swiper';
  19. import Carousel from 'react-native-snap-carousel';
  20. import {BoxShadow} from 'react-native-shadow';
  21. var testMac = 'FF:FF:FF:FF:FF:FF'
  22. var curAdIndex = 0;
  23. var errorMsg = {
  24. ERR_MAC_GET:'设备编号获取错误',
  25. ERR_START_AD:'广告播放系统错误',
  26. ERR_DATA_GET:'广告数据获取错误',
  27. ERR_HEARTBEAT:'设备心跳数据错误',
  28. ERR_NO_DATA:'暂无优惠信息'
  29. }
  30. var animationThemes = [
  31. // 滑入
  32. {
  33. first:"slideInDown",
  34. second:"slideInLeft",
  35. third:"slideInRight"
  36. },
  37. // 放大
  38. {
  39. first:"zoomInDown",
  40. second:"zoomInLeft",
  41. third:"zoomInRight"
  42. },
  43. // 翻转
  44. {
  45. first:"flipInX",
  46. second:"flipInY",
  47. third:"flipInX"
  48. },
  49. // 弹出
  50. {
  51. first:"bounceInDown",
  52. second:"bounceInLeft",
  53. third:"bounceInRight"
  54. }
  55. ]
  56. const shadowOpt = {
  57. width: 800/PixelRatio.get(),
  58. height: 240/PixelRatio.get(),
  59. color:"#000",
  60. border:2,
  61. radius:3,
  62. opacity:0.5,
  63. x:2,
  64. y:3,
  65. style:{marginVertical:5}
  66. }
  67. var curTimer = null;
  68. var hbRequestCount
  69. var getAdDataCount
  70. var pageChangeCount
  71. var adDataList = [];
  72. var adDataBgList = [];
  73. var heartConfig = {
  74. heartbeatInterval:300,
  75. dataRefreshInterval:3600,
  76. pageChangeInterval:10,
  77. }
  78. var requestFailedCount = 0;
  79. var versionInfo = '';
  80. let codePushOptions = {
  81. //设置检查更新的频率
  82. //ON_APP_RESUME APP恢复到前台的时候
  83. //ON_APP_START APP开启的时候
  84. //MANUAL 手动检查
  85. checkFrequency : CodePush.CheckFrequency.ON_APP_START
  86. };
  87. export default class MyPage extends Component {
  88. constructor(props) {
  89. super(props);
  90. this.state = {
  91. baseInfo: null,
  92. contentItem0:null,
  93. contentItem1:null,
  94. contentItem2:null,
  95. animationTheme:animationThemes[0],
  96. contentDisplayStatus:false,
  97. syncMessage: "初始化..." ,
  98. errorMessage: '加载中...',
  99. progress: {
  100. receivedBytes:0,
  101. totalBytes:0
  102. },
  103. updating:true,
  104. macAddress: '',
  105. versionInfo:'未知',
  106. adType: 0,
  107. curAdType02Index: 0, //广告图index
  108. coverImgUrl: '',
  109. previewImg: '',
  110. curImgState: false,
  111. };
  112. /* this.codePushUpdate = this.codePushUpdate.bind(this);
  113. this.startAd = this.startAd.bind(this);
  114. this.showErrMsg = this.showErrMsg.bind(this); */
  115. }
  116. componentDidMount() {
  117. this.codePushUpdate();
  118. DeviceInfo.getMACAddress().then((mac)=>{
  119. if (mac=='' || mac==null ) {
  120. if (NativeModules.BuildConfig.buildType == 'debug') {
  121. this.setState({macAddress : this.testMac})
  122. this.startAd()
  123. } else {
  124. this.showErrMsg(errorMsg.ERR_MAC_GET);
  125. }
  126. } else {
  127. this.setState({macAddress : mac})
  128. this.startAd()
  129. }
  130. }).catch(e => {
  131. this.showErrMsg(errorMsg.ERR_START_AD);
  132. })
  133. }
  134. componentDidUpdate() {
  135. /* console.log(this.refs.scrollView)
  136. if (this.refs.scrollView != undefined) {
  137. var ScrollView = this.refs.scrollView;
  138. ScrollView.scrollBy(0, true);
  139. } */
  140. }
  141. //更新函数
  142. async codePushUpdate() {
  143. CodePush.allowRestart();
  144. await CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
  145. .then((metadata: LocalPackage) => {
  146. this.setState({ versionInfo: metadata ? 'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : 'b'+ NativeModules.BuildConfig.versionCode});
  147. versionInfo = this.state.versionInfo;
  148. }, (error: any) => {
  149. this.setState({ versionInfo: "Unknown"});
  150. versionInfo = this.state.versionInfo;
  151. });
  152. await CodePush.sync(
  153. { mandatoryInstallMode: CodePush.InstallMode.ON_NEXT_RESTART,
  154. installMode: CodePush.InstallMode.ON_NEXT_RESTART},
  155. this.codePushStatusDidChange.bind(this),
  156. this.codePushDownloadDidProgress.bind(this)
  157. ).then((status: SyncStatus) => {
  158. }, (error: any) => {
  159. console.log(error)
  160. // CodePush.restartApp();
  161. });
  162. }
  163. // 监听更新状态
  164. codePushStatusDidChange(syncStatus) {
  165. switch(syncStatus) {
  166. case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
  167. this.setState({ syncMessage: "检查更新" });
  168. break;
  169. case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
  170. this.setState({ syncMessage: "下载更新" });
  171. break;
  172. case CodePush.SyncStatus.AWAITING_USER_ACTION:
  173. this.setState({ syncMessage: "等待用户操作" });
  174. break;
  175. case CodePush.SyncStatus.INSTALLING_UPDATE:
  176. this.setState({ syncMessage: "安装更新" });
  177. break;
  178. case CodePush.SyncStatus.UP_TO_DATE:
  179. this.setState({ syncMessage: "已更新到最新程序", updating: false });
  180. break;
  181. case CodePush.SyncStatus.UPDATE_IGNORED:
  182. this.setState({ syncMessage: "更新被取消", updating: false });
  183. break;
  184. case CodePush.SyncStatus.UPDATE_INSTALLED:
  185. this.setState({ syncMessage: "更新已安装,重启应用后生效", updating: false });
  186. break;
  187. case CodePush.SyncStatus.UNKNOWN_ERROR:
  188. this.setState({ syncMessage: "未知错误", updating: false });
  189. break;
  190. }
  191. }
  192. codePushDownloadDidProgress(progress) {
  193. this.setState({ progress });
  194. }
  195. // 列表滚动
  196. updateContent() {
  197. if (adDataList.length <=0)
  198. return false;
  199. if (curAdIndex >= adDataList.length) {
  200. curAdIndex = 0;
  201. }
  202. this.setState({contentItem0:adDataList[curAdIndex]});
  203. if (curAdIndex + 1 < adDataList.length)
  204. this.setState({contentItem1:adDataList[curAdIndex+1]});
  205. else
  206. this.setState({contentItem1:null});
  207. if (curAdIndex + 2 < adDataList.length)
  208. this.setState({contentItem2:adDataList[curAdIndex+2]});
  209. else
  210. this.setState({contentItem2:null});
  211. curAdIndex+=3
  212. return true;
  213. }
  214. hbRequest() {
  215. return HttpUtils.post(NativeModules.BuildConfig.apiHost
  216. + 'api/wxDeviceScreenAd/heartbeat?deviceId='
  217. + encodeURIComponent(this.state.macAddress),
  218. {version:this.state.versionInfo})
  219. .then(result => {
  220. if (result.code == 200) {
  221. let config = JSON.parse(result.data.config);
  222. heartConfig.heartbeatInterval = config.heartbeatInterval
  223. heartConfig.dataRefreshInterval=config.dataRefreshInterval
  224. heartConfig.pageChangeInterval=config.pageChangeInterval
  225. // 动画划入
  226. if(config.animationTheme == 0){
  227. this.setState({
  228. animationTheme:animationThemes[0]
  229. })
  230. }else if(config.animationTheme == 1){
  231. // 放大
  232. this.setState({
  233. animationTheme:animationThemes[1]
  234. })
  235. }else if(config.animationTheme == 2){
  236. // 淡入
  237. this.setState({
  238. animationTheme:animationThemes[2]
  239. })
  240. }else if(config.animationTheme == 3){
  241. // 弹入
  242. this.setState({
  243. animationTheme:animationThemes[3]
  244. })
  245. }
  246. } else {
  247. //do nothing
  248. }
  249. })
  250. .catch(error => {
  251. requestFailedCount++
  252. this.setState({ versionInfo: versionInfo+`[${requestFailedCount}]`});
  253. })
  254. }
  255.  showErrMsg(errMsg) {
  256. this.setState({contentDisplayStatus: false})
  257. this.setState({errorMessage : errMsg});
  258. }
  259. //判断播放类型adType
  260. dealLoopType(dataList) {
  261. adDataList = dataList.filter((item) => {
  262. return item.type == 0;
  263. })
  264. adDataBgList = dataList.filter((item) => {
  265. return item.type == 2;
  266. })
  267. //aaa
  268. let num = 0;
  269. if (adDataList.length > 0 && adDataBgList.length > 0) {
  270. num = 2;
  271. this.setState({previewImg: adDataBgList[0].coverImg});
  272. } else if (adDataList.length > 0 && !adDataBgList.length) {
  273. num = 0;
  274. } else if (!adDataList.length && adDataBgList.length > 0) {
  275. num = 1;
  276. }
  277. this.setState({adType: num })
  278. }
  279. getAdDataList(first) {
  280. HttpUtils.get(NativeModules.BuildConfig.apiHost
  281. + 'api/wxDeviceScreenAd/list?deviceId='
  282. + encodeURIComponent(this.state.macAddress)
  283. + '&pageNum=1&pageSize=1000')
  284. .then(result => {
  285. if (result.code != 200) {
  286. this.showErrMsg(result.message+'\n'+this.state.macAddress);
  287. } else if (result.data.list) {
  288. //aaa
  289. //type==0的是券 1是? 2是广告大图
  290. let curData = result.data.list;
  291. this.dealLoopType(curData);
  292. if (this.updateContent()) {
  293. this.setState({contentDisplayStatus: true})
  294. } else {
  295. this.showErrMsg(errorMsg.ERR_NO_DATA);
  296. }
  297. } else {
  298.  this.showErrMsg(errorMsg.ERR_DATA_GET);
  299. }
  300. })
  301. .catch(error => {
  302. if (first) {
  303. this.showErrMsg(error.message);
  304. }
  305. else {
  306. requestFailedCount++
  307. this.setState({ versionInfo: versionInfo+`[${requestFailedCount}]`});
  308. }
  309. })
  310. }
  311. getBaseInfo() {
  312. HttpUtils.get(NativeModules.BuildConfig.apiHost
  313. + 'api/wxDeviceScreenAd/info?deviceId='
  314. + encodeURIComponent(this.state.macAddress))
  315. .then(result => {
  316. if (result.code != 200) {
  317. this.showErrMsg(result.message+'\n'+this.state.macAddress);
  318. } else if (result.data) {
  319. this.setState({baseInfo:result.data});
  320. } else {
  321. this.showErrMsg(errorMsg.ERR_DATA_GET);
  322. }
  323. })
  324. .catch(error => {
  325. this.showErrMsg(error.message);
  326. })
  327. }
  328. componentWillUnmount(){
  329. if (curTimer)
  330. clearTimeout(curTimer)
  331. }
  332. async routine() {
  333. hbRequestCount -=1;
  334. getAdDataCount -=1;
  335. if (this.state.adType == 2 && this.state.curImgState) {
  336. pageChangeCount -=1;
  337. }
  338. if (this.state.adType != 2) {
  339. pageChangeCount -=1;
  340. }
  341. try {
  342. if (getAdDataCount<=0) {
  343. this.getAdDataList(false)
  344. getAdDataCount = heartConfig.dataRefreshInterval
  345. } else if (hbRequestCount<=0) {
  346. this.hbRequest()
  347. hbRequestCount = heartConfig.heartbeatInterval
  348. }
  349. //如果是adType == 2时间间隔到了,要检验轮播是否走完在决定切换
  350. if (this.state.adType == 2) {
  351. if (pageChangeCount<=0) {
  352. let curNum = this.state.curAdType02Index + 1;
  353. if (curNum >= adDataBgList.length) {
  354. curNum = 0;
  355. }
  356. this.setState({
  357. curAdType02Index: curNum,
  358. previewImg:adDataBgList[curNum].coverImg
  359. })
  360. pageChangeCount = heartConfig.pageChangeInterval
  361. }
  362. } else if (this.state.adType == 0) {
  363. if (pageChangeCount <= 0) { //页面切换间隔
  364. if (this.state.contentDisplayStatus && this.state.baseInfo) {
  365. this.setState({ contentDisplayStatus: false})
  366. if (this.updateContent()) {
  367. this.setState({ contentDisplayStatus: true})
  368. }
  369. } else {
  370. await this.getBaseInfo()
  371. await this.getAdDataList(true)
  372. getAdDataCount = heartConfig.dataRefreshInterval
  373. hbRequestCount = heartConfig.heartbeatInterval
  374. }
  375. pageChangeCount = heartConfig.pageChangeInterval
  376. }
  377. }
  378. } catch(e){
  379. this.setState({ versionInfo: versionInfo+'[E]'});
  380. }
  381. curTimer = setTimeout(()=>{
  382. this.routine();
  383. },1000);
  384. }
  385. startAd() {
  386. hbRequestCount = 0;
  387. getAdDataCount = 0;
  388. pageChangeCount = 0;
  389. this.routine();
  390. }
  391. getContentViewItemUplayer(contentItem) {
  392. if (contentItem.type == 0) {
  393. if (contentItem.subType == 2)
  394. return (<Image source={require('./image/timed.png')} resizeMode='center' style={styles.contentItemUpLayer} /> )
  395. if (contentItem.subType == 6)
  396. return (<Image source={require('./image/discount.png')} resizeMode='center' style={styles.contentItemUpLayer} /> )
  397. if (contentItem.subType == 7)
  398. return (<Image source={require('./image/groupbuy.png')} resizeMode='center' style={styles.contentItemUpLayer} /> )
  399. return null;
  400. }
  401. }
  402. getContentViewItemActionStr(contentItem) {
  403. if (contentItem.type == 0) {
  404. if (contentItem.subType == 2)
  405. return '扫码秒杀';
  406. else if (contentItem.subType == 6)
  407. return '扫码砍价';
  408. else if (contentItem.subType == 7)
  409. return '扫码拼团';
  410. else
  411. return '扫码领取';
  412. }
  413. }
  414. getContentViewItemMerchantName(contentItem) {
  415. if (contentItem.type == 0) {
  416. if (contentItem.target.merchantVoList.length > 1)
  417. return '多商户通用';
  418. else
  419. return contentItem.target.merchantVoList[0].merchantName;
  420. }
  421. }
  422. getContentViewItem(contentItem, annomation) {
  423. if (!contentItem)
  424. return (
  425. <View style={styles.contentItem}>
  426. </View>
  427. )
  428. actionText = this.getContentViewItemActionStr(contentItem);
  429. merchantName = this.getContentViewItemMerchantName(contentItem);
  430. // console.warn(annomation)
  431. return (
  432. <Animatable.View animation={annomation} style={styles.contentItem}>
  433. <ImageBackground source={require('./image/item-background.png')} resizeMode='center' style={styles.contentItemDownLayer} >
  434. {/* 列表 */}
  435. <View style={styles.contentItemTop}>
  436. <Image source={{uri: contentItem.coverImg}} resizeMode='cover' style={styles.contentItemTopCoverImg} />
  437. <View style={styles.contentItemTopDetail}>
  438. {/* 券的title */}
  439. <Text style={styles.contentItemTopDetailTitle} numberOfLines={2} ellipsizeMode="tail">{contentItem.target.title}</Text>
  440. <View style={styles.contentItemTopDetailPrice}>
  441. {/* 售价 */}
  442. <View style={styles.contentItemTopDetailCurPrice}>
  443. <Text style={styles.contentItemTopDetailCurPriceStrUnit}>¥</Text>
  444. <Text style={styles.contentItemTopDetailCurPriceStr}>{contentItem.target.salePriceStr}</Text>
  445. </View>
  446. {/* 面额 */}
  447. <View style={styles.contentItemTopDetailSalePrice}>
  448. <Text style={styles.contentItemTopDetailSalePriceStr} >¥{contentItem.target.priceStr}</Text>
  449. </View>
  450. </View>
  451. </View>
  452. {/* <Image source={{uri:'data:image/png;base64,'+contentItem.qrcode}} resizeMode='contain' style={styles.contentItemTopQrcode} /> */}
  453. <Image source={{uri:contentItem.target.qrCode}} resizeMode='contain' style={styles.contentItemTopQrcode} />
  454. </View>
  455. {/* 优惠券底部商户名称 */}
  456. <View style={styles.contentItemBottom}>
  457. <Text style={styles.contentItemBottomMerchantName}>{merchantName}</Text>
  458. <Text style={styles.contentItemBottomPlacehold}>{contentItem.target.merchantVoList[0].buildingName}{contentItem.target.merchantVoList[0].floorName}</Text>
  459. <Text style={styles.contentItemBottomAction}>{actionText}</Text>
  460. </View>
  461. </ImageBackground>
  462. {this.getContentViewItemUplayer(contentItem)}
  463. </Animatable.View>
  464. )
  465. }
  466. getContentView() {
  467. if (this.state.contentDisplayStatus) {
  468. return (<View style={styles.content}>
  469. {this.getContentViewItem(this.state.contentItem0,this.state.animationTheme.first)}
  470. {this.getContentViewItem(this.state.contentItem1,this.state.animationTheme.second)}
  471. {this.getContentViewItem(this.state.contentItem2,this.state.animationTheme.third)}
  472. </View>)
  473. }else{
  474. return (
  475. <View style={styles.content}>
  476. <Text style={styles.updatePage}>{this.state.errorMessage}</Text>
  477. </View>)
  478. }
  479. }
  480. setAdSwiperItemDom(item) {
  481. let contentItem = item.item;
  482. return (
  483. <View style={styles.onlyAdSwiperItem}>
  484. <Image source={{uri: contentItem.coverImg}} resizeMode='stretch' style={styles.onlyAdTypeItemImg} />
  485. </View>
  486. )
  487. }
  488. setSwiperItemDom(item) {
  489. let contentItem = item.item;
  490. let index = item.index;
  491. let curLogo = null;
  492. if (contentItem.type == 0) {
  493. if (contentItem.subType == 2)
  494. curLogo = require('./image/timed.png');
  495. if (contentItem.subType == 6)
  496. curLogo = require('./image/discount.png');
  497. if (contentItem.subType == 7)
  498. curLogo = require('./image/groupbuy.png');
  499. }
  500. return (
  501. <View style={styles.carouselItemWrap}>
  502. <BoxShadow setting={shadowOpt}>
  503. <View style={styles.contentItemTopForAd} key={index}>
  504. <Image source={curLogo} resizeMode='center' style={styles.contentItemUpLayerLogo} />
  505. {/* <ImageBackground style={styles.adTypeSwiper02} resizeMode="stretch" source={require('./image/item-background.png')}></ImageBackground> */}
  506. <Image source={{uri: contentItem.coverImg}} resizeMode='cover' style={styles.adTypeItemImg} />
  507. <View style={styles.contentItemTopDetail}>
  508. {/* 券的title */}
  509. <Text style={styles.contentItemTopDetailTitle02} numberOfLines={2} ellipsizeMode="tail">{contentItem.target.title}</Text>
  510. <View style={styles.contentItemTopDetailPrice}>
  511. {/* 售价 */}
  512. <View style={styles.contentItemTopDetailCurPrice}>
  513. <Text style={styles.contentItemTopDetailCurPriceStrUnit02}>¥</Text>
  514. <Text style={styles.contentItemTopDetailCurPriceStr02}>{contentItem.target.salePriceStr}</Text>
  515. </View>
  516. {/* 面额 */}
  517. <View style={styles.contentItemTopDetailSalePrice02}>
  518. <Text style={styles.contentItemTopDetailSalePriceStr02} >¥{contentItem.target.priceStr}</Text>
  519. </View>
  520. </View>
  521. </View>
  522. {/* <Image source={{uri:'data:image/png;base64,'+contentItem.qrcode}} resizeMode='contain' style={styles.contentItemTopQrcode} /> */}
  523. <View style={styles.contentItemTopQrcodeBox}>
  524. <Image source={{uri:contentItem.target.qrCode}} resizeMode='contain' style={styles.contentItemTopQrcode02} />
  525. </View>
  526. </View>
  527. </BoxShadow>
  528. </View>
  529. )
  530. }
  531. renderAdTypeSwiper() {
  532. if (this.state.contentDisplayStatus) {
  533. let adSwiperDomStack = [];
  534. //aaa
  535. adDataList.map((item,index) => {
  536. item.target.qrCode = 'https://iformall-net.s3.cn-northwest-1.amazonaws.com.cn/null/73ddb1e4-8f19-4d5d-8387-742d3d5d2c77.png'
  537. adSwiperDomStack.push(this.setSwiperItemDom(item, index))
  538. })
  539. return adSwiperDomStack;
  540. }else{
  541. return (
  542. <View style={styles.content}>
  543. <Text style={styles.updatePage}>{this.state.errorMessage}</Text>
  544. </View>
  545. )
  546. }
  547. }
  548. getUpdateView() {
  549. if (this.state.progress.totalBytes > 0)
  550. return (
  551. <Text style={styles.updatePage}>{this.state.syncMessage}{'\n'}
  552. {this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received{'\n'}
  553. </Text>
  554. );
  555. return (
  556. <Text style={styles.updatePage}>{this.state.syncMessage}
  557. </Text>
  558. );
  559. }
  560. rendDefaultImg() {
  561. if (this.state.coverImgUrl) {
  562. return (
  563. <ImageBackground style={styles.adTypeBg} resizeMode="stretch" source={{uri: this.state.coverImgUrl}}></ImageBackground>
  564. )
  565. } else {
  566. return (
  567. <ImageBackground style={styles.adTypeBg} resizeMode="stretch" source={require('./image/background.png')}></ImageBackground>
  568. )
  569. }
  570. }
  571. getAdView(){
  572. if (this.state.baseInfo) {
  573. if (this.state.adType == 0) {
  574. return (
  575. <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}>
  576. {/* 头部title二维码开始 */}
  577. <View style={styles.title}>
  578. <View style={styles.titleImagePlace}>
  579. <Image source={require('./image/title.png')} resizeMode='center' style={styles.titleImage} />
  580. </View>
  581. <ImageBackground source={require('./image/title-qrcode.png') } resizeMode='center' style={styles.titleQrcodeBonder} >
  582. <View style={styles.titleQrcodePlacehold}></View>
  583. <Image source={{uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.titleQrcode} />
  584. <View style={styles.titleQrcodePlacehold}></View>
  585. </ImageBackground>
  586. </View>
  587. {/* 券列表展示列表开始 */}
  588. {this.getContentView()}
  589. {/* 底部商场信息展示开始 */}
  590. <View style={styles.bottom}>
  591. <View style={styles.bottomLogoBackground}>
  592. <Image source={{ uri: this.state.baseInfo.imgUrlH}} resizeMode='contain' style={styles.bottomLogo} />
  593. </View>
  594. <View style={styles.bottomQrcode1Background}>
  595. <Image source={{ uri: this.state.baseInfo.imgQrcodeWeapp}} resizeMode='center' style={styles.bottomQrcode1} />
  596. <Text style={styles.bottomQrcode1Str}>小程序</Text>
  597. </View>
  598. <View style={styles.bottomQrcode2Background}>
  599. <Image source={{ uri: this.state.baseInfo.imgQrcodeWemp}} resizeMode='center' style={styles.bottomQrcode2} />
  600. <Text style={styles.bottomQrcode1Str}>公众号</Text>
  601. </View>
  602. <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text>
  603. </View>
  604. </ImageBackground>
  605. );
  606. } else if (this.state.adType == 2) {
  607. let curWidthNum = 1080/(PixelRatio.get());
  608. return (
  609. // <ImageBackground style={styles.adTypeBg} source={require('./image/ad1.jpg')}> slideInDown zoomInDown
  610. <View style={styles.adWrapBox}>
  611. <Image style={styles.adWrapHideImg}
  612. onLoadStart={() => {
  613. this.setState({
  614. curImgState: false
  615. })
  616. }}
  617. onLoad={() => {
  618. this.setState({
  619. coverImgUrl: this.state.previewImg,
  620. curImgState: true
  621. })
  622. }}
  623. resizeMode="stretch" source={{uri: this.state.previewImg}}>
  624. </Image>
  625. <Animatable.View animation="slideInDown" style={styles.adWrap} key={this.state.coverImgUrl}>
  626. {this.rendDefaultImg()}
  627. </Animatable.View>
  628. <View style={styles.adTypeSwiper02}>
  629. <Carousel
  630. ref={'carousel02'}
  631. data={adDataList}
  632. renderItem={this.setSwiperItemDom}
  633. sliderWidth={curWidthNum}
  634. itemWidth={curWidthNum}
  635. layout={'stack'}
  636. activeSlideOffset={0}
  637. autoplay={true}
  638. loop={true}
  639. autoplayInterval={5000}
  640. />
  641. </View>
  642. </View>
  643. );
  644. } else if (this.state.adType == 1) {
  645. let curWidthNum = 1080/(PixelRatio.get())
  646. return(
  647. <Carousel
  648. ref={'carousel01'}
  649. data={adDataBgList}
  650. renderItem={this.setAdSwiperItemDom}
  651. sliderWidth={curWidthNum}
  652. itemWidth={curWidthNum}
  653. activeSlideOffset={0}
  654. autoplay={true}
  655. loop={true}
  656. autoplayInterval={5000}
  657. />
  658. )
  659. }
  660. }
  661. else {
  662. return (
  663. <ImageBackground style={styles.background} resizeMode='center' source={require('./image/background.png')}>
  664. {/* 头部title二维码开始 */}
  665. <View style={styles.title}>
  666. </View>
  667. {/* 券列表展示列表开始 */}
  668. {this.getContentView()}
  669. {/* 底部商场信息展示开始 */}
  670. <View style={styles.bottom}>
  671. <View style={styles.bottomLogoBackground}>
  672. </View>
  673. <View style={styles.bottomQrcode1Background}>
  674. </View>
  675. <View style={styles.bottomQrcode2Background}>
  676. </View>
  677. <Text style={styles.bottomPlacehold}>{this.state.versionInfo}</Text>
  678. </View>
  679. </ImageBackground>
  680. );
  681. }
  682. }
  683. render() {
  684. if (this.state.updating) {
  685. return this.getUpdateView();
  686. }
  687. return this.getAdView();
  688. }
  689. }
  690. MyPage = CodePush(codePushOptions)(MyPage);
  691. const styles = StyleSheet.create({
  692. updatePage:{
  693. flex: 2,
  694. width:'100%',
  695. height:'100%',
  696. backgroundColor:'transparent',
  697. textAlign :'center',
  698. textAlignVertical:'center',
  699. fontSize: 63/PixelRatio.get(),
  700. color: 'darkblue'
  701. },
  702. //layer background
  703. background:{
  704. flex: 1,
  705. width:'100%',
  706. height:'100%'
  707. },
  708. //layer top
  709. title:{
  710. flex: 6,
  711. flexDirection: 'row',
  712. alignItems: 'center',
  713. paddingLeft:42/PixelRatio.get(),
  714. paddingRight:42/PixelRatio.get(),
  715. backgroundColor:'transparent'
  716. },
  717. content:{
  718. flex: 18,
  719. flexDirection: 'column',
  720. alignItems: 'center',
  721. backgroundColor:'transparent'
  722. },
  723. bottom:{
  724. flex: 2,
  725. flexDirection: 'row',
  726. alignItems: 'center',
  727. paddingLeft:42/PixelRatio.get(),
  728. paddingRight:42/PixelRatio.get(),
  729. backgroundColor:'transparent'
  730. },
  731. //layer title
  732. titleImagePlace: {
  733. flex: 2,
  734. paddingTop: '20%',
  735. paddingLeft: '15%',
  736. alignItems: 'center',
  737. backgroundColor:'transparent'
  738. },
  739. titleImage: {
  740. width:'100%',
  741. height:'100%',
  742. flex: 1,
  743. backgroundColor:'transparent'
  744. },
  745. titleQrcodeBonder: {
  746. width:'100%',
  747. height:'100%',
  748. alignItems: 'center',
  749. flexDirection: 'column',
  750. flex: 1,
  751. backgroundColor:'transparent'
  752. },
  753. titleQrcodePlacehold: {
  754. flex: 5,
  755. backgroundColor:'transparent'
  756. },
  757. titleQrcode: {
  758. flex: 6,
  759. width:'100%',
  760. height:'100%',
  761. backgroundColor:'transparent'
  762. },
  763. //layer bottom
  764. bottomLogoBackground: {
  765. flex: 3,
  766. borderRadius:16/PixelRatio.get(),
  767. marginTop: 26/PixelRatio.get(),
  768. marginBottom: 26/PixelRatio.get(),
  769. backgroundColor:'transparent',//'rgba(255,255,255,0.5)',
  770. },
  771. bottomLogo: {
  772. width:'100%',
  773. height:'100%',
  774. backgroundColor:'transparent'
  775. },
  776. bottomQrcode1Background : {
  777. flex: 1,
  778. width:'100%',
  779. height:'100%',
  780. marginLeft: 21/PixelRatio.get(),
  781. paddingTop: 27/PixelRatio.get(),
  782. paddingBottom: 11/PixelRatio.get(),
  783. flexDirection: 'column',
  784. backgroundColor:'transparent'
  785. },
  786. bottomQrcode2Background : {
  787. flex: 1,
  788. width:'100%',
  789. height:'100%',
  790. marginLeft: 21/PixelRatio.get(),
  791. paddingTop: 26/PixelRatio.get(),
  792. paddingBottom: 11/PixelRatio.get(),
  793. flexDirection: 'column',
  794. backgroundColor:'transparent'
  795. },
  796. bottomQrcode1: {
  797. flex: 2,
  798. width:'100%',
  799. height:'100%',
  800. backgroundColor:'transparent'
  801. },
  802. bottomQrcode2: {
  803. flex: 2,
  804. width:'100%',
  805. height:'100%',
  806. backgroundColor:'transparent'
  807. },
  808. bottomQrcode1Str: {
  809. flex: 1,
  810. textAlign :'center',
  811. textAlignVertical:'center',
  812. fontSize: 16/PixelRatio.get(),
  813. color : 'white',
  814. backgroundColor:'transparent'
  815. },
  816. bottomQrcode2Str: {
  817. flex: 1,
  818. textAlign :'center',
  819. textAlignVertical:'center',
  820. fontSize: 16/PixelRatio.get(),
  821. color : 'white',
  822. backgroundColor:'transparent'
  823. },
  824. bottomPlacehold: {
  825. flex: 8,
  826. width:'100%',
  827. height:'100%',
  828. backgroundColor:'transparent',
  829. textAlign :'right',
  830. textAlignVertical:'bottom',
  831. fontSize: 27/PixelRatio.get(),
  832. color : 'gray'
  833. },
  834. //layer content item
  835. contentItem:{
  836. flex: 1,
  837. width:'100%',
  838. height:'100%',
  839. flexDirection: 'column',
  840. backgroundColor:'transparent'
  841. },
  842. contentItemDownLayer:{
  843. position:'absolute',
  844. width:'100%',
  845. height:'100%',
  846. flexDirection: 'column',
  847. alignItems: 'center',
  848. backgroundColor:'transparent'
  849. },
  850. contentItemUpLayer:{
  851. width:210/PixelRatio.get(),
  852. height:153/PixelRatio.get(),
  853. position:'absolute',
  854. backgroundColor:'transparent'
  855. },
  856. contentItemUpLayerLogo: {
  857. width:160/PixelRatio.get(),
  858. height:83/PixelRatio.get(),
  859. position: 'absolute',
  860. left: -20/PixelRatio.get(),
  861. top: 20/PixelRatio.get(),
  862. zIndex:100,
  863. backgroundColor: 'transparent',
  864. },
  865. contentItemTop:{
  866. flex: 3,
  867. width:'100%',
  868. height:'100%',
  869. paddingLeft: 66/PixelRatio.get(),
  870. paddingRight: 53/PixelRatio.get(),
  871. paddingTop: 40/PixelRatio.get(),
  872. flexDirection: 'row',
  873. alignItems: 'center',
  874. backgroundColor:'transparent'
  875. },
  876. contentItemBottom:{
  877. flex: 1,
  878. width:'100%',
  879. height:'100%',
  880. paddingLeft: 66/PixelRatio.get(),
  881. paddingRight: 53/PixelRatio.get(),
  882. paddingBottom: 40/PixelRatio.get(),
  883. flexDirection: 'row',
  884. alignItems: 'center',
  885. backgroundColor:'transparent'
  886. },
  887. //layer content item top
  888. contentItemTopCoverImg:{
  889. flex: 5,
  890. width:'100%',
  891. height:'100%',
  892. borderRadius:27/PixelRatio.get(),
  893. backgroundColor:'transparent'
  894. },
  895. contentItemTopDetail:{
  896. flex: 6,
  897. width:'100%',
  898. height:'100%',
  899. paddingLeft: 20/PixelRatio.get(),
  900. paddingRight: 20/PixelRatio.get(),
  901. alignItems: 'center',
  902. backgroundColor:'transparent'
  903. },
  904. contentItemTopQrcode:{
  905. flex: 5,
  906. width:'100%',
  907. height:'100%',
  908. marginLeft:18/PixelRatio.get(),
  909. // backgroundColor:'transparent'
  910. },
  911. contentItemTopQrcodeBox:{
  912. flex: 5,
  913. width:'100%',
  914. height:'100%',
  915. flexDirection: 'column',
  916. alignItems: 'center',
  917. justifyContent: 'center',
  918. marginLeft: -28/PixelRatio.get(),
  919. // backgroundColor:'transparent'
  920. },
  921. contentItemTopQrcode02:{
  922. width:'90%',
  923. height:'90%',
  924. },
  925. //layer content item bottom
  926. contentItemBottomMerchantName:{
  927. flex: 5,
  928. width:'100%',
  929. height:'100%',
  930. alignItems: 'center',
  931. color:"black",
  932. backgroundColor:'transparent',
  933. textAlign :'center',
  934. textAlignVertical:'center',
  935. fontSize: 27/PixelRatio.get(),
  936. fontWeight : 'bold',
  937. },
  938. contentItemBottomPlacehold:{
  939. flex: 6,
  940. fontSize: 27/PixelRatio.get(),
  941. paddingLeft: 27/PixelRatio.get(),
  942. paddingRight: 79/PixelRatio.get(),
  943. width:'100%',
  944. height:'100%',
  945. color:"black",
  946. textAlignVertical:'center',
  947. backgroundColor:'transparent',
  948. },
  949. contentItemBottomAction:{
  950. flex: 5,
  951. width:'100%',
  952. height:'100%',
  953. backgroundColor:'transparent',
  954. textAlign :'center',
  955. textAlignVertical:'center',
  956. fontSize: 36/PixelRatio.get(),
  957. color: 'black',
  958. },
  959. contentItemBottomAction02:{
  960. width:'100%',
  961. height: 60/PixelRatio.get(),
  962. backgroundColor:'transparent',
  963. textAlign :'center',
  964. textAlignVertical:'center',
  965. fontSize: 36/PixelRatio.get(),
  966. color: 'black',
  967. },
  968. // 券的title
  969. contentItemTopDetailTitle:{
  970. flex: 2,
  971. // height:'100%',
  972. width:'100%',
  973. marginTop:"2%",
  974. backgroundColor:'transparent',
  975. textAlign :'left',
  976. color:"black",
  977. textAlignVertical:'center',
  978. fontSize: 53/PixelRatio.get(),
  979. },
  980. // 券的title
  981. contentItemTopDetailTitle02:{
  982. flex: 2,
  983. // height:'100%',
  984. width:'100%',
  985. marginTop:"2%",
  986. paddingRight: 14/PixelRatio.get(),
  987. backgroundColor:'transparent',
  988. textAlign :'left',
  989. color:"black",
  990. textAlignVertical:'center',
  991. fontSize: 42/PixelRatio.get(),
  992. },
  993. /*
  994. contentItemTopDetailRemark:{
  995. flex: 1,
  996. width:'100%',
  997. height:'100%',
  998. backgroundColor:'transparent',
  999. textAlign :'left',
  1000. textAlignVertical:'center',
  1001. fontSize: 27/PixelRatio.get(),
  1002. color : 'gray'
  1003. },
  1004. */
  1005. contentItemTopDetailPrice:{
  1006. flex: 2,
  1007. width:'100%',
  1008. height:'100%',
  1009. backgroundColor:'transparent',
  1010. flexDirection: 'row',
  1011. },
  1012. // 售价的样式
  1013. contentItemTopDetailCurPrice:{
  1014. position:"absolute",
  1015. bottom:10,
  1016. left:0,
  1017. width:'100%',
  1018. height:'100%',
  1019. flexDirection: 'row',
  1020. backgroundColor:'transparent',
  1021. },
  1022. contentItemTopDetailCurPriceStr:{
  1023. backgroundColor:'transparent',
  1024. fontSize:96/PixelRatio.get(),
  1025. fontFamily:"PingFangSC-Bold",
  1026. fontWeight: "bold",
  1027. textAlign :'left',
  1028. textAlignVertical:'bottom',
  1029. color : 'red'
  1030. },
  1031. contentItemTopDetailCurPriceStr02:{
  1032. backgroundColor:'transparent',
  1033. fontSize:72/PixelRatio.get(),
  1034. fontFamily:"PingFangSC-Bold",
  1035. fontWeight: "bold",
  1036. textAlign :'left',
  1037. color : 'red'
  1038. },
  1039. contentItemTopDetailCurPriceStrUnit:{
  1040. backgroundColor:'transparent',
  1041. textAlign :'left',
  1042. textAlignVertical:'bottom',
  1043. paddingBottom: 16/PixelRatio.get(),
  1044. fontSize: 48/PixelRatio.get(),
  1045. color : 'red'
  1046. },
  1047. contentItemTopDetailCurPriceStrUnit02:{
  1048. backgroundColor:'transparent',
  1049. textAlign :'left',
  1050. textAlignVertical:'center',
  1051. paddingBottom: 16/PixelRatio.get(),
  1052. fontSize: 48/PixelRatio.get(),
  1053. color : 'red'
  1054. },
  1055. // 面额的样式
  1056. contentItemTopDetailSalePrice:{
  1057. position:"absolute",
  1058. bottom:2,
  1059. left:0,
  1060. // flex: 1,
  1061. paddingTop:138/PixelRatio.get(),
  1062. width:'100%',
  1063. // height:'100%',
  1064. backgroundColor:'transparent',
  1065. },
  1066. contentItemTopDetailSalePrice02:{
  1067. position:"absolute",
  1068. bottom:14/PixelRatio.get(),
  1069. left:0,
  1070. // flex: 1,
  1071. paddingTop:138/PixelRatio.get(),
  1072. width:'100%',
  1073. // height:'100%',
  1074. backgroundColor:'transparent',
  1075. },
  1076. contentItemTopDetailSalePriceStr:{
  1077. width:'100%',
  1078. height:'100%',
  1079. backgroundColor:'transparent',
  1080. textAlign :'left',
  1081. textAlignVertical:'bottom',
  1082. fontSize: 27/PixelRatio.get(),
  1083. textDecorationLine: 'line-through',
  1084. color : 'gray'
  1085. },
  1086. contentItemTopDetailSalePriceStr02:{
  1087. width:'100%',
  1088. height:'100%',
  1089. backgroundColor:'transparent',
  1090. textAlignVertical:'center',
  1091. textAlign :'left',
  1092. fontSize: 27/PixelRatio.get(),
  1093. textDecorationLine: 'line-through',
  1094. color : 'gray'
  1095. },
  1096. adTypeBg:{
  1097. flex: 1,
  1098. width: '100%',
  1099. height: '100%',
  1100. },
  1101. adWrapBox: {
  1102. width: '100%',
  1103. height: '100%',
  1104. position: 'relative',
  1105. },
  1106. adWrap: {
  1107. width: '100%',
  1108. height: '100%',
  1109. position: 'absolute',
  1110. left: 0,
  1111. top: 0,
  1112. zIndex: 10,
  1113. },
  1114. adWrapHideImg: {
  1115. width: '100%',
  1116. height: '100%',
  1117. position: 'absolute',
  1118. left: 0,
  1119. top: 0,
  1120. zIndex: -1,
  1121. opacity:0,
  1122. },
  1123. adTypeSwiper02:{
  1124. flex: 1,
  1125. alignItems: 'center',
  1126. position: 'absolute',
  1127. left: 0,
  1128. bottom: 60/PixelRatio.get(),
  1129. width: '100%',
  1130. height: 270/PixelRatio.get(),
  1131. },
  1132. adTypeItemImgWrap:{
  1133. flex: 1,
  1134. width: '100%',
  1135. height: 369/PixelRatio.get(),
  1136. flexDirection: 'row',
  1137. alignItems: 'center',
  1138. },
  1139. adTypeItemImg:{
  1140. width: 200/PixelRatio.get(),
  1141. height: 200/PixelRatio.get(),
  1142. marginLeft: 8/PixelRatio.get(),
  1143. marginTop: 20/PixelRatio.get(),
  1144. borderRadius:27/PixelRatio.get(),
  1145. backgroundColor:'transparent'
  1146. },
  1147. bottomBox:{
  1148. position: 'absolute',
  1149. bottom: 20/PixelRatio.get(),
  1150. left: 0,
  1151. width: '100%',
  1152. height: 130/PixelRatio.get(),
  1153. flexDirection: 'row',
  1154. alignItems: 'center',
  1155. backgroundColor:'transparent',
  1156. },
  1157. contentItemTopForAd:{
  1158. position: 'relative',
  1159. flex: 1,
  1160. width: 800/PixelRatio.get(),
  1161. // width: '100%',
  1162. height:'100%',
  1163. paddingLeft: 12/PixelRatio.get(),
  1164. paddingRight: 26/PixelRatio.get(),
  1165. flexDirection: 'row',
  1166. alignItems: 'flex-start',
  1167. borderRadius: 6,
  1168. backgroundColor:'rgba(255,255,255,.8)',
  1169. },
  1170. onlyAdSwiperItem:{
  1171. width: '100%',
  1172. height: '100%',
  1173. },
  1174. onlyAdTypeItemImg:{
  1175. width: '100%',
  1176. height: '100%',
  1177. },
  1178. carouselItemWrap: {
  1179. flex: 1,
  1180. width: '100%',
  1181. backgroundColor: 'transparent',
  1182. alignItems: 'center',
  1183. }
  1184. });