index.js 1.92 KB
Newer Older
zhanghaozhe committed
1 2
import React, { Component } from "react"
import "./index.scss"
zhanghaozhe committed
3
import { http } from "src/utils"
zhanghaozhe committed
4 5 6
import QRCode from "qrcode"
import { connect } from "react-redux"
import { Toast } from "antd-mobile"
xuzhenghua committed
7 8

class FollowQRcode extends Component {
zhanghaozhe committed
9 10 11 12 13
  constructor(props) {
    super(props)
    this.state = {
      src: "",
      codeSrc: "",
xuzhenghua committed
14
    }
zhanghaozhe committed
15
  }
xuzhenghua committed
16

zhanghaozhe committed
17 18 19 20 21 22
  componentDidMount() {
    const _this = this
    let uid = this.props && this.props.user && this.props.user.data.uid
    http
      .get(`${API["base-api"]}/wx/user_temporary_qrcode/${uid}`)
      .then((res) => {
zhanghaozhe committed
23
        if (res.data.errno === 0) {
zhanghaozhe committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
          _this.setState({
            src: res.data.data.url,
          })
          return new Promise((resolve) => {
            QRCode.toDataURL(_this.state.src, {}, function (err, url) {
              _this.setState({
                codeSrc: url,
              })
            })
            resolve()
          })
        } else {
          Toast.info(res.data.msg, 2)
        }
      })
  }
xuzhenghua committed
40

zhanghaozhe committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  render() {
    return (
      <div className="followQRcode-box">
        <div className="followQRcode">
          <div className="content">
            <p className="title">关注公众号</p>
            <p className="desc">
              <span>1</span>
              有人通过您分享的链接领取红包后,会第一时间通过微信服务号通知您。
            </p>
            <p className="desc">
              <span>2</span>请用个人微信扫描,关注服务号后可提现红包到微信零钱
            </p>
            <img src={this.state.codeSrc} alt="" />
            <p className="tip">长按二维码保存到相册</p>
          </div>
          <div className="close">
            <i
              className="iconfont iconiconfront-2"
              onClick={this.props.toClose}
            ></i>
          </div>
        </div>
      </div>
    )
  }
xuzhenghua committed
67 68
}

zhanghaozhe committed
69 70 71
export default connect((state) => ({
  user: state.user,
}))(FollowQRcode)