info.js 2.03 KB
import React,{ Component } from 'react';
import html2canvas from 'html2canvas';
import share from '../../utils/share';
import shareHide from "../../utils/shareHide";
import styles from './poster.less'

class PosterInfo extends Component{
  constructor(props) {
    super(props);
    this.state = {
      info: {}
    }
  }
  componentDidMount() {
    document.title = '海报'
    const posterImgWrap = this.posterImgWrap;
    shareHide(false);
    html2canvas(this.poster).then(function (canvas) {
      var image = new Image();
      image.src = canvas.toDataURL("image/png");
      posterImgWrap.appendChild(image);
    });
    let info = {};
    if (this.props.location.search !== '') {
      const {
        search
      } = this.props.location;
      const matchs = decodeURI(search).match(/imgpath=(.*)&position=(.*)&name=(.*)&phone=(.*)/i);
      info.img = matchs[1];
      info.position = matchs[2];
      info.name = matchs[3];
      info.phone = matchs[4];
    }
    share({
      decodeUrl: window.location.href.split('#')[0],
      title: '我是'+info.name +  ',您身边的保险管家',
      desc: '用我的专业为万千家庭带来保障',
      shareUrl: window.location.href,
      thumbnail: info.img
    });
    this.setState({
      info
    });
  }
  componentWillUnmount(){
    document.title = ''
  }
  render() {
    const { info } = this.state;
    return (
      <div className={styles.posterWrapper}>
        <div className={styles.poster} ref={el => this.poster = el}>
          <img src={info.img} alt="" />
          <ul className={styles.info}>
            <li>{info.position}</li>
            <li>{info.name}</li>
            <li>{info.phone}</li>
          </ul>
          <div className={styles.posterImg} ref={el=>this.posterImgWrap=el}></div>
        </div>
        {/* <ul className={styles.operation}>
          <li className={styles.msg}>消息</li>
          <li className={styles.moments}>朋友圈</li>
          <li className={styles.download}>下载</li>
        </ul> */}
      </div>
    )
  }
}

export default PosterInfo;