import Taro from "@tarojs/taro";

import { Component } from "react";
import { Block, WebView } from "@tarojs/components";

// 打开外部页面使用
export default class WebViewPage extends Component<any, any> {
  constructor(props) {
    super(props);
    this.state = {
      name: "webView",
      url: "",
    };
  }
  $instance = Taro.getCurrentInstance();

  async onLoad() {}
  componentDidMount() {}

  componentWillUnmount() {}

  componentDidShow() {
    this.initData();
  }

  componentDidHide() {}

  async initData() {
    let url = this.$instance.router?.params?.url;
    if (!url?.includes("https://") && !url?.includes("http://")) {
      url = "https://" + url;
    }
    console.log("url", url);
    this.setState({ url: url });
  }

  render() {
    let { url } = this.state;
    return (
      <Block>
        <WebView src={url}></WebView>
      </Block>
    );
  }
}
