index.js 2.82 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5
import React, { Component } from "react"
import { CopyToClipboard } from "react-copy-to-clipboard"
import { browser, http, wxShare, getParam } from "src/utils"
import "./index.scss"
import { Toast } from "antd-mobile"
zhanghaozhe committed
6

xuzhenghua committed
7
class aiTestHelp extends Component {
zhanghaozhe committed
8 9 10 11 12 13
  constructor(props) {
    super(props)
    this.state = {
      total_num: "",
      dec: "",
      isshowYindao: false,
xuzhenghua committed
14
    }
zhanghaozhe committed
15
  }
xuzhenghua committed
16

zhanghaozhe committed
17 18 19 20
  componentDidMount() {
    this.handleFetchInfo()
    this.getAssist()
  }
xuzhenghua committed
21

zhanghaozhe committed
22 23 24 25 26 27 28 29 30 31 32 33
  share = () => {
    wxShare({
      title: "全国AI水平测试开始了,看看你能答对几道题?",
      desc: this.state.dec,
      link: `${API.m}/ai-test/assist/${getParam("shareCode")}`,
      imgUrl:
        "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/ai-test/m/share-img.png",
    })
    this.setState({
      isshowYindao: true,
    })
  }
xuzhenghua committed
34

zhanghaozhe committed
35 36 37
  copyToSuccess = () => {
    Toast.info("链接已复制,快去发送给好友吧~")
  }
xuzhenghua committed
38

zhanghaozhe committed
39 40
  handleFetchInfo = () => {
    http.get(`${API.home}/sys/aitest/invitation`).then((res) => {
zhanghaozhe committed
41
      const { code, data } = res.data
zhanghaozhe committed
42 43 44
      if (code === 200) {
        this.setState({
          total_num: data.total_num,
xuzhenghua committed
45
        })
zhanghaozhe committed
46 47 48
      }
    })
  }
xuzhenghua committed
49

zhanghaozhe committed
50 51
  getAssist = () => {
    http.get(`${API.home}/sys/aitest/assist`).then((res) => {
zhanghaozhe committed
52
      const { code, data } = res.data
zhanghaozhe committed
53 54 55
      if (code === 200) {
        this.setState({
          dec: data.ques,
xuzhenghua committed
56
        })
zhanghaozhe committed
57 58 59
      }
    })
  }
xuzhenghua committed
60

zhanghaozhe committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
  render() {
    const { total_num, isshowYindao } = this.state
    return (
      <div className={"ai-test-help"}>
        <div className="banner">
          <img
            src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/ai-test/m/text2.png"
            alt=""
          />
          <span>{total_num}</span>
          <img
            src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/ai-test/m/text1.png"
            alt=""
          />
        </div>
xuzhenghua committed
76

zhanghaozhe committed
77 78 79 80
        <p className={"tip-l"}>分享给好友</p>
        <p className={"tip-s"}>每个好友只能助力1次哦~</p>
        <p className={"tip-m"}>好友答题为你助力,答题正确你将获得</p>
        <p className={"tip-num"}>一次测试机会</p>
xuzhenghua committed
81

zhanghaozhe committed
82 83 84 85 86 87 88 89 90 91 92 93 94
        {!browser.isWeixin && (
          <CopyToClipboard
            text={`${API.m}/ai-test/assist/${getParam("shareCode")}`}
            onCopy={this.copyToSuccess}
          >
            <div className={"share-btn"}>邀请好友助力</div>
          </CopyToClipboard>
        )}
        {browser.isWeixin && (
          <div className={"share-btn"} onClick={this.share}>
            邀请好友助力
          </div>
        )}
xuzhenghua committed
95

zhanghaozhe committed
96 97 98 99 100
        {isshowYindao && (
          <div className={"share"}>
            <div className="content">
              <p className="test">点击右上角,分享给好友</p>
              <i className="iconfont"></i>
xuzhenghua committed
101
            </div>
zhanghaozhe committed
102 103 104 105 106
          </div>
        )}
      </div>
    )
  }
xuzhenghua committed
107 108
}

zhanghaozhe committed
109
export default aiTestHelp