1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import React, {Component} from 'react';
- import {View, SafeAreaView} from 'react-native';
- import public_css from '../../source/css/public_css';
- import {loginWeChat, weChatShare} from '../../components/wechat/weChat';
- import {WebView} from 'react-native-webview';
- export default class activity extends Component {
- constructor(props) {
- super(props);
- this.props.navigation.dangerouslyGetParent().setOptions({
- tabBarVisible: false,
- });
- this.state = {
- listData: [],
- showFoot: 0, // 控制foot, 0:隐藏footer 1:已加载完成,没有更多数据 2 :显示加载中
- isLoading: false,
- id: '',
- url: '',
- uri: '',
- injectedJavaScript: '',
- title: '',
- desc: '',
- };
- }
- render() {
- const {injectedJavaScript = '', uri = ''} = this.state;
- return (
- <SafeAreaView style={public_css.body}>
- {injectedJavaScript ? (
- <WebView
- source={{uri: uri}}
- onMessage={this.activityShare}
- injectedJavaScript={injectedJavaScript}
- />
- ) : (
- <View />
- )}
- </SafeAreaView>
- );
- }
- componentDidMount() {
- let data = this.props.route.params.data;
- this.props.navigation.setOptions({
- headerTitle: data.title,
- });
- // const id = 'bae3c1e4c6bf4d577f01a6312d30fe41';
- this.setState({
- title: data.title,
- desc: data.desc,
- id: data.number,
- url: data.url,
- uri: data.url,
- injectedJavaScript: `localStorage.removeItem('campaignId');localStorage.setItem('campaignId','${data.number}')`,
- });
- }
- setData(data) {
- this.setState({
- id: data.number,
- url: data.url,
- });
- console.log(this.state.id);
- }
- // 调用微信分享
- // 参数: type:0:好友 1:朋友圈
- activityShare = (evt: any) => {
- console.log('接收数据');
- console.log(evt);
- const data = evt.nativeEvent.data.split('&');
- let type = '';
- let userId = '';
- if (data.length > 0) {
- type = data[0];
- userId = data[1];
- }
- if (Number(type) == 0 || Number(type) == 1) {
- weChatShare(
- this.state.title,
- this.state.desc,
- parseInt(type),
- userId,
- this.state.id,
- );
- }
- };
- // 获取从web传递的数据
- getWebData = (type) => {
- console.log('2233');
- console.log(type);
- };
- }
|