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


class ToAppDemo extends Component {

    state = {
xuzhenghua committed
14 15
        userInfoList: [
        ],
xuzhenghua committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    }

    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) {
xuzhenghua committed
36
            this.props.startFetchUser()
xuzhenghua committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50
            this.appLogin()
        }
    }
    // 保存cookie
    appLogin = () => {
        let expires = addDays(new Date(), 90)
        this.state.userInfoList.map((item, index) => {
            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'});
        });
xuzhenghua committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
        this.props.setCurrentUser(this.transformUser(this.state.userInfoList))
    }

    transformUser = res => {
        let payload

        res.map((item, index) => {
            payload = {
                hasError: false,
                data: {
                    username: item.uname,
                    avatar: item.avatar_file,
                    token: item.token,
                    uid: item.uid
                },
                isFetching: false
            }
        })

        return payload
xuzhenghua committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    }


    // 跳转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 = {
xuzhenghua committed
104 105 106 107
            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',
xuzhenghua committed
108 109 110 111 112 113 114
        }
        SendMessageToApp("QQshare", data)
    }
    // 微信分享
    WXshare = () => {
        // 内容需要和产品确认
        let data = {
xuzhenghua committed
115 116 117 118
            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',
xuzhenghua committed
119 120 121 122 123 124 125
        }
        SendMessageToApp("WXshare", data)
    }

    // 邀请好友注册
    toShare = () => {
        let data = {
xuzhenghua committed
126 127 128 129
            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',
xuzhenghua committed
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
        }
        SendMessageToApp("toShare", data)
    }

    render() {
        return (
            <div>
                <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
160 161 162 163 164 165 166

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