activity.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React, {Component} from 'react';
  2. import {View, SafeAreaView} from 'react-native';
  3. import public_css from '../../source/css/public_css';
  4. import {loginWeChat, weChatShare} from '../../components/wechat/weChat';
  5. import {WebView} from 'react-native-webview';
  6. export default class activity extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.props.navigation.dangerouslyGetParent().setOptions({
  10. tabBarVisible: false,
  11. });
  12. this.state = {
  13. listData: [],
  14. showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
  15. isLoading: false,
  16. id: '',
  17. url: '',
  18. uri: '',
  19. injectedJavaScript: '',
  20. title: '',
  21. desc: '',
  22. };
  23. }
  24. render() {
  25. const {injectedJavaScript = '', uri = ''} = this.state;
  26. return (
  27. <SafeAreaView style={public_css.body}>
  28. {injectedJavaScript ? (
  29. <WebView
  30. source={{uri: uri}}
  31. onMessage={this.activityShare}
  32. injectedJavaScript={injectedJavaScript}
  33. />
  34. ) : (
  35. <View />
  36. )}
  37. </SafeAreaView>
  38. );
  39. }
  40. componentDidMount() {
  41. let data = this.props.route.params.data;
  42. this.props.navigation.setOptions({
  43. headerTitle: data.title,
  44. });
  45. // const id = 'bae3c1e4c6bf4d577f01a6312d30fe41';
  46. this.setState({
  47. title: data.title,
  48. desc: data.desc,
  49. id: data.number,
  50. url: data.url,
  51. uri: data.url,
  52. injectedJavaScript: `localStorage.removeItem('campaignId');localStorage.setItem('campaignId','${data.number}')`,
  53. });
  54. }
  55. setData(data) {
  56. this.setState({
  57. id: data.number,
  58. url: data.url,
  59. });
  60. console.log(this.state.id);
  61. }
  62. // 调用微信分享
  63. // 参数: type:0:好友 1:朋友圈
  64. activityShare = (evt: any) => {
  65. console.log('接收数据');
  66. console.log(evt);
  67. const data = evt.nativeEvent.data.split('&');
  68. let type = '';
  69. let userId = '';
  70. if (data.length > 0) {
  71. type = data[0];
  72. userId = data[1];
  73. }
  74. if (Number(type) == 0 || Number(type) == 1) {
  75. weChatShare(
  76. this.state.title,
  77. this.state.desc,
  78. parseInt(type),
  79. userId,
  80. this.state.id,
  81. );
  82. }
  83. };
  84. // 获取从web传递的数据
  85. getWebData = (type) => {
  86. console.log('2233');
  87. console.log(type);
  88. };
  89. }