广告屏react-native项目
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

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