Commit 873ae3df by zhanghaozhe

video

parent 02660017
...@@ -16,12 +16,13 @@ class DatumCatalog extends Component { ...@@ -16,12 +16,13 @@ class DatumCatalog extends Component {
} }
render() { render() {
const {datum} = this.props
return ( return (
<div className='datum-catalog'> <div className='datum-catalog'>
<p className='prompt'>课程资料请到PC端播放页下载</p> <p className='prompt'>课程资料请到PC端播放页下载</p>
<Accordion> <Accordion>
{ {
this.props.datum.map((item, index) => { datum && datum.length && datum.map((item, index) => {
return ( return (
<Accordion.Panel header={item.dir_name} key={index}> <Accordion.Panel header={item.dir_name} key={index}>
{ {
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import HeaderBar from '@/common/HeaderBar' import HeaderBar from '@/common/HeaderBar'
import './video.scss' import './video.scss'
import { NavLink, Route } from 'react-router-dom'; import { NavLink, Route, Redirect, Switch } from 'react-router-dom';
import { http, api } from '@/utils' import { http, api, getParam } from '@/utils'
import Recommendation from './recommendation' import Recommendation from './recommendation'
import VideoCatalog from './video-catalog' import VideoCatalog from './video-catalog'
import DatumCatalog from './datum-catalog' import DatumCatalog from './datum-catalog'
import { Toast } from 'antd-mobile'; import { Toast } from 'antd-mobile';
import videojs from 'video.js' import videojs from 'video.js'
import 'video.js/dist/video-js.min.css' import 'video.js/dist/video-js.min.css'
// import 'video.scss' import { Modal } from "antd-mobile";
let alert = Modal.alert
class Video extends Component { class Video extends Component {
video; video
player
courseID
state = { state = {
title: '视频', title: '视频',
courseId: 140, courseId: null,
video_catalog: [], video_catalog: [],
datum: [] datum: [],
currentVideoSrc: '',
activeIndex: 0,
isAuth: true,
course: null,
salePrice: null
} }
componentDidMount() { componentDidMount() {
this.courseID = getParam('id')
this.setState({
courseId: this.courseID
})
this.getVideoCatalog()
this.getDatumCatalog()
}
initializePlayer = () => {
window.HELP_IMPROVE_VIDEOJS = false; window.HELP_IMPROVE_VIDEOJS = false;
videojs(this.video, { this.player = videojs(this.video, {
controls: true, controls: true,
autoplay: true,
preload: 'auto', preload: 'auto',
bigPlayButton: true, bigPlayButton: true,
textTrackDisplay: false, textTrackDisplay: false,
posterImage: false, posterImage: false,
errorDisplay: false, errorDisplay: false
}, function () { })
this.log.debug() this.player.enableTouchActivity()
}
componentWillUnmount() {
if (this.player) {
this.player.dispose()
}
}
handleClick = index => {
if (this.hasAuth()) {
this.setPlayerSrc(this.state.video_catalog[index]['play_url'])
this.playVideo()
}
this.setState({
activeIndex: index
}) })
this.getVideoCatalog()
this.getDatumCatalog()
} }
getVideoCatalog = () => { getVideoCatalog = () => {
http.get(`${api.home}/m/course/play/40`) http.get(`${api.home}/m/course/play/${this.courseID}`)
.then(res => { .then(res => {
const data = res.data const data = res.data
if (data.code === 200) { if (data.code === 200) {
this.setState({ this.setState(
video_catalog: data.data.lessons state => ({
}) video_catalog: data.data['lessons'],
currentVideoSrc: data.data['lessons'][state.activeIndex]['play_url'],
course: data.data.course,
courseId: data.data.course['course_id']
}),
() => {
if (this.lessonAvailable()) {
if (this.hasAuth(this.state.activeIndex)) {
this.initializePlayer()
this.playWithAuth()
} else {
this.getCoursePrice();
}
} else {
alert('暂无视频', '', [{
text: 'OK',
onPress: () => {
this.props.history.push('/')
}
}])
}
}
)
} else { } else {
Toast.info(data.msg) Toast.info(data.msg)
} }
}) })
} }
setPlayerSrc = src => {
this.player.src({
src,
type: 'application/x-mpegURL'
})
}
playVideo = () => {
this.player.play()
}
getDatumCatalog() { getDatumCatalog() {
http.get(`${api.home}/m/course/data/40`) http.get(`${api.home}/m/course/data/${this.courseID}`)
.then(res => { .then(res => {
const data = res.data const data = res.data
if (data.code === 200) { if (data.code === 200) {
...@@ -76,16 +141,84 @@ class Video extends Component { ...@@ -76,16 +141,84 @@ class Video extends Component {
}) })
} }
lessonAvailable = () => {
const {video_catalog, activeIndex} = this.state
return video_catalog[activeIndex]['video_size'] !== 0
}
getCoursePrice = () => {
http.get(`${api.home}/sys/course/price/${this.state.courseId}`)
.then(res => {
const {data} = res
if (data.code === 200) {
this.setState({
salePrice: data.data['sale_price']
})
}
})
}
playWithAuth = () => {
const {video_catalog, activeIndex} = this.state
if (this.hasAuth()) {
this.setPlayerSrc(video_catalog[activeIndex]['play_url'])
}
}
hasAuth = (index) => {
const {course, video_catalog, activeIndex} = this.state
let lesson = video_catalog[activeIndex]
if (!lesson['is_free']) {
if (course['is_audition']) {
this.setState({
isAuth: true
})
return true
} else {
if (lesson['video_auth']) {
this.setState({
isAuth: true
})
return true
}
this.setState({
isAuth: false
})
return false
}
}
this.setState({
isAuth: true
})
return true
}
render() { render() {
let {match} = this.props let {match} = this.props
const {video_catalog, activeIndex, isAuth, salePrice} = this.state
return ( return (
<div className='play'> <div className='play'>
<HeaderBar title={this.state.title}/> <HeaderBar title={this.state.title}/>
<div className="video"> <div className="video">
<video className={'video-js'} ref={el => this.video = el}> <video className={'video-js'} ref={el => this.video = el}>
<source src='/v2/ts/40/191/175d6e5a.m3u8' type='application/x-mpegURL'/> <source src={'/'} type='application/x-mpegURL'/>
</video> </video>
{
!isAuth && (
<div className="purchase-box">
<div className='hint'>您尚未购买该课时,请购买后学习。</div>
<div className='btns'>
<button type='button' className='purchase-class'>¥{salePrice} 购买课程</button>
<button type='button'
className='purchase-episode'>¥{video_catalog.length && video_catalog[activeIndex]['class_price']} 购买单集
</button>
</div>
</div>
)
}
</div> </div>
<div className='tab'> <div className='tab'>
<div> <div>
...@@ -101,15 +234,23 @@ class Video extends Component { ...@@ -101,15 +234,23 @@ class Video extends Component {
>资料</NavLink> >资料</NavLink>
</div> </div>
</div> </div>
{/*<Route path={`${match.path}/video`} render={props => { <Switch>
return <VideoCatalog videoCatalog={this.state.video_catalog} {...props}/> <Redirect exact from={'/play'} to={'/play/video'}/>
}}/> <Route path={`${match.path}/video`} render={props => {
<Route path={`${match.path}/datum`} render={props => { return <VideoCatalog
return <DatumCatalog {...props} datum={this.state.datum}/> activeIndex={this.state.activeIndex}
}}/> handleClick={this.handleClick}
videoCatalog={this.state.video_catalog}
{...props}/>
}}/>
<Route path={`${match.path}/datum`} render={props => {
return <DatumCatalog {...props} datum={this.state.datum}/>
}}/>
</Switch>
<Route render={props => { <Route render={props => {
return <Recommendation {...props} courseId={this.state.courseId}/> return this.state.courseId ? <Recommendation {...props} courseId={this.state.courseId}/>
}}/>*/} : null
}}/>
</div> </div>
); );
} }
......
import React, { Component } from 'react'; import React, { PureComponent } from 'react';
import './recommendation.scss' import './recommendation.scss'
import { http, api } from '@/utils' import { http, api } from '@/utils'
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
...@@ -17,12 +17,14 @@ const Bottom = ({item}) => { ...@@ -17,12 +17,14 @@ const Bottom = ({item}) => {
class Recommendation extends Component { class Recommendation extends PureComponent {
state = { state = {
num: 10, num: 10,
list: [] list: [],
courseId: null
} }
componentDidMount() { componentDidMount() {
http.get(`${api.home}/m/play/recommend_course/${this.props.courseId}?num=${this.state.num}`) http.get(`${api.home}/m/play/recommend_course/${this.props.courseId}?num=${this.state.num}`)
.then(res => { .then(res => {
...@@ -39,6 +41,7 @@ class Recommendation extends Component { ...@@ -39,6 +41,7 @@ class Recommendation extends Component {
}) })
} }
handleClick = id => { handleClick = id => {
console.log(id) console.log(id)
} }
......
...@@ -5,14 +5,21 @@ import classnames from 'classnames' ...@@ -5,14 +5,21 @@ import classnames from 'classnames'
class VideoCatalog extends Component { class VideoCatalog extends Component {
handleClick = (i) => {
this.props.handleClick(i)
}
render() { render() {
return ( return (
<div className='video-catalog'> <div className='video-catalog'>
<ul> <ul>
{ {
this.props.videoCatalog.map(item => { this.props.videoCatalog.map((item, index) => {
return ( return (
<li key={item.id}> <li key={item.id}
className={classnames({active: this.props.activeIndex === index})}
onClick={this.handleClick.bind(this, index)}
>
<span className="title">{item.name}</span> <span className="title">{item.name}</span>
<span className='duration'>{item.duration}</span> <span className='duration'>{item.duration}</span>
<i className={classnames(`iconfont`, <i className={classnames(`iconfont`,
......
...@@ -5,6 +5,66 @@ $tabHeight: 44px; ...@@ -5,6 +5,66 @@ $tabHeight: 44px;
width: 100%; width: 100%;
height: 215px; height: 215px;
background-color: $black; background-color: $black;
position: relative;
.video-js {
width: 100%;
height: 100%;
.vjs-big-play-button {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.purchase-box {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
background-color: rgba(0, 0, 0, 0.8);
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
.hint {
font-size: $font_14;
color: $white;
margin-bottom: 20px;
}
@mixin button{
display: block;
-webkit-appearance: none;
outline: none;
border: none;
background-color: transparent;
border-radius: 5px;
line-height: 30px;
font-size: 13px;
padding: 0 9px;
}
.btns {
width: 100%;
padding: 0 60px;
display: flex;
justify-content: space-around;
}
.purchase-class{
@include button;
background-color: $white;
color: $color_FF4000;
}
.purchase-episode{
@include button;
background-color: $bg_FF4000;
color: $white;
}
}
video { video {
width: 100%; width: 100%;
...@@ -35,7 +95,10 @@ $tabHeight: 44px; ...@@ -35,7 +95,10 @@ $tabHeight: 44px;
.active { .active {
color: $active; color: $active;
border-bottom: 1px solid $active;
.iconiconfront-74 {
color: $color_555;
}
} }
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ const config = { ...@@ -14,7 +14,7 @@ const config = {
v2: { v2: {
development: '/v2', development: '/v2',
test: 'https://v2.julyedu.com', test: 'https://v2.julyedu.com',
production: 'https://search.julyedu.com', production: 'https://v2.julyedu.com',
proxy: { proxy: {
secure: false, secure: false,
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment