import { Component } from '@tarojs/taro';
import { ComponentClass } from 'react';
import { WebView } from '@tarojs/components';
import { shareHandle } from '@/common/shareMethod';

type PageState = {
  linkUrl: string;
};

interface WebPage {
  state: PageState;
}

class WebPage extends Component {
  constructor(props) {
    super(props);
    this.state = {
      linkUrl: '',
    };
  }
  onShareAppMessage = shareHandle;

  componentWillMount() {
    console.log(this.$router.params);
    const { url } = this.$router.params;
    if (url) {
      this.setState({
        linkUrl: url,
      });
    }
  }

  render() {
    const { linkUrl } = this.state;
    return linkUrl && <WebView src={linkUrl} />;
  }
}

export default WebPage as ComponentClass<any, PageState>;
