toAppDemo.js 6.78 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6 7 8
import React, { Component } from "react"
import { SendMessageToApp, wxShare } from "src/utils"
import { setCurrentUser, startFetchUser } from "src/store/userAction"
import { Button, Toast, WhiteSpace } from "antd-mobile"
import cookie from "js-cookie"
import { addDays } from "date-fns"
import { compose } from "redux"
import { connect } from "react-redux"
xuzhenghua committed
9 10

class ToAppDemo extends Component {
zhanghaozhe committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  state = {
    userInfoList: [],
  }

  componentDidMount() {
    this.getData()
    // 获取App登录信息
    window["loginInfo"] = (result) => {
      this.loginInfo(result)
    }
  }

  getData = () => {
    Toast.info("获取福气值", 2)
  }

  // 获取app登录数据
  loginInfo = (result) => {
    this.setState({
      userInfoList: result,
    })
    if (this.state.userInfoList.length !== 0) {
      this.props.startFetchUser()
      this.appLogin()
    }
  }
  // 保存cookie
  appLogin = () => {
    let expires = addDays(new Date(), 90)
zhanghaozhe committed
40
    this.state.userInfoList.forEach((item, index) => {
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 67 68 69 70 71 72 73
      Toast.info(item.version, 3)
      cookie.set("token", item.token, {
        expires,
        path: "/",
        domain: "julyedu.com",
      })
      cookie.set("plat", item.plat, {
        expires,
        path: "/",
        domain: "julyedu.com",
      })
      cookie.set("uid", item.uid, {
        expires,
        path: "/",
        domain: "julyedu.com",
      })
      cookie.set("uname", item.uname, {
        expires,
        path: "/",
        domain: "julyedu.com",
      })
      cookie.set("avatar_file", item.avatar_file, {
        expires,
        path: "/",
        domain: "julyedu.com",
      })
    })
    this.props.setCurrentUser(this.transformUser(this.state.userInfoList))
  }

  transformUser = (res) => {
    let payload

zhanghaozhe committed
74
    res.forEach((item, index) => {
zhanghaozhe committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
      payload = {
        hasError: false,
        data: {
          username: item.uname,
          avatar: item.avatar_file,
          token: item.token,
          uid: item.uid,
        },
        isFetching: false,
      }
    })

    return payload
  }
  testShare = () => {
    wxShare({
      title: "AI充电节,积福气享1折秒课,超10万元奖品来就送!!",
      desc:
        "把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线",
zhanghaozhe committed
94
      link: encodeURI(window.location.href),
zhanghaozhe committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
      imgUrl:
        "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png",
    })
  }

  // 跳转App登录
  toLogin = () => {
    SendMessageToApp("toLogin")
  }

  // 立即付定金
  earnestMoney = (courseId) => {
    SendMessageToApp("earnestMoney", courseId)
  }

  // 去课程详情页
  toCourse = (courseId, type) => {
    let data = {
      courseId: courseId,
      type: type, // 正常跳课程详情页type:0,积福气浏览课程详情页-没有浏览过type:1 已浏览过type:2
    }
    SendMessageToApp("toCourse", data)
  }
  // 人工咨询
  toQQ = () => {
    SendMessageToApp("toQQ", "https://q.url.cn/AB8aue?_type=wpa&qidian=true")
  }
  // 直播间
  toLiveRoom = (toLiveRoom) => {
    SendMessageToApp("toLiveRoom", toLiveRoom)
  }
  // QQ分享
  QQshare = () => {
    // 内容需要和产品确认
    let data = {
      title: "AI充电节,积福气享1折秒课,超10万元奖品来就送!!",
      desc:
        "把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线",
      link: "https://m.julyedu.com/blessingPreheat",
      imgUrl:
        "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png",
    }
    SendMessageToApp("QQshare", data)
  }
  // 微信分享
  WXshare = () => {
    // 内容需要和产品确认
    let data = {
      title: "AI充电节,积福气享1折秒课,超10万元奖品来就送!!",
      desc:
        "把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线",
      link: "https://m.julyedu.com/blessingPreheat",
      imgUrl:
        "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png",
    }
    SendMessageToApp("WXshare", data)
  }

  // 邀请好友注册
  toShare = () => {
    let data = {
      title: "AI充电节,积福气享1折秒课,超10万元奖品来就送!!",
      desc:
        "把这门超5万人报名的【Python基础入门 升级版】课程送给你,附200元红包,请笑纳!--七月在线",
      link: "https://m.julyedu.com/blessingPreheat",
      imgUrl:
        "https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/active19_1111/m/index-share-img.png",
    }
    SendMessageToApp("toShare", data)
  }

  render() {
    return (
      <div>
        <Button type={"primary"} onClick={() => this.testShare()}>
          测试分享
        </Button>
        <WhiteSpace />
        <p>登录</p>
        <Button type={"primary"} onClick={() => this.toLogin()}>
          App登录
        </Button>
        <WhiteSpace />
        <p>去课程详情页</p>
        <Button type={"primary"} onClick={() => this.toCourse(165, 0)}>
          课程详情页
        </Button>
        <WhiteSpace />
        <p>积福气</p>
        <Button type={"primary"} onClick={() => this.toCourse(165, 1)}>
          浏览课程详情页
        </Button>
        <WhiteSpace />
        <Button type={"primary"} onClick={() => this.QQshare()}>
          分享(QQ
        </Button>
        <WhiteSpace />
        <Button type={"primary"} onClick={() => this.WXshare()}>
          分享(微信)
        </Button>
        <WhiteSpace />
        <Button type={"primary"} onClick={() => this.toShare()}>
          邀请好友注册
        </Button>
        <WhiteSpace />
        <p>定金相关</p>
        <Button type={"primary"} onClick={() => this.earnestMoney(165)}>
          立即付定金
        </Button>
        <WhiteSpace />
        <Button type={"primary"} onClick={() => this.toCourse(165, 0)}>
          去学习(跳课程详情页)
        </Button>
        <WhiteSpace />
        <p>精品特惠</p>
        <Button type={"primary"} onClick={() => this.toQQ()}>
          立抢超低团购价(跳人工咨询)
        </Button>
        <WhiteSpace />
        <Button type={"primary"} onClick={() => this.toCourse(165, 0)}>
          开始使用(跳课程详情页)
        </Button>
        <WhiteSpace />
        <Button type={"primary"} onClick={() => this.toCourse(165, 0)}>
          一分钱开团(跳课程详情页)
        </Button>
        <WhiteSpace />
        <p>大咖直播</p>
        <Button type={"primary"} onClick={() => this.toLiveRoom(100)}>
          正在直播
        </Button>
        <WhiteSpace />
      </div>
    )
  }
xuzhenghua committed
230 231 232
}

export default compose(
zhanghaozhe committed
233 234
  connect((state) => ({ user: state.user }), { setCurrentUser, startFetchUser })
)(ToAppDemo)