广告屏react-native项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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