广告屏react-native项目
Não pode escolher mais do que 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.
 
 
 
 
 

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