index.js 1.61 KB
Newer Older
xuzhenghua committed
1 2
import React, {Component} from 'react'
import {Carousel, WingBlank} from 'antd-mobile'
xuzhenghua committed
3 4

import './index.scss'
xuzhenghua committed
5
import {api, getParam, http} from "@/utils"
xuzhenghua committed
6

xuzhenghua committed
7
// 课程页面滚动广告
xuzhenghua committed
8 9 10 11 12 13 14 15 16 17 18
class Carouselw extends Component {
    constructor(props) {
        super(props)
        this.state = {
            list: []
        }
    }

    componentDidMount() {
        const _this = this
        _this.getList()
xuzhenghua committed
19 20
        this.timer = setInterval(function () {
            _this.getList()
xuzhenghua committed
21
        }, 10000);
xuzhenghua committed
22 23 24 25 26 27 28 29 30 31 32 33

    }

    componentWillUnmount() {
        this.timer && clearTimeout(this.timer);
    }

    // 获取课程接口
    getList = () => {
        let data = {
            course_id: getParam('id')
        }
zhanghaozhe committed
34
        http.post(`${API.home}/m/course/barrages`, data).then((res) => {
xuzhenghua committed
35 36 37 38 39 40 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
            if (res.data.code === 200) {
                this.setState({
                    list: res.data.data,
                });
            }
        })
    }

    render() {
        return (
            <WingBlank>
                <Carousel className="my-carousel"
                          vertical
                          dots={false}
                          autoplay
                          infinite
                >
                    {
                        this.state.list &&
                        <div className="v-item text-overflow-one">
                            <img src={this.state.list.avatar} alt=""/>
                            {this.state.list.user_name} {this.state.list.live_msg}
                        </div>
                    }

                </Carousel>
            </WingBlank>
        )
    }
}

xuzhenghua committed
66
export default Carouselw