diff --git a/public/react/src/modules/courses/Video/LiveItem.js b/public/react/src/modules/courses/Video/LiveItem.js index a2fff5b98..0bee79fe2 100644 --- a/public/react/src/modules/courses/Video/LiveItem.js +++ b/public/react/src/modules/courses/Video/LiveItem.js @@ -1,25 +1,12 @@ import React,{ Component } from "react"; -import { Switch } from 'antd'; import { getImageUrl } from 'educoder'; import { WordsBtn } from 'educoder'; +import moment from 'moment'; import axios from 'axios'; class LiveItem extends Component{ - changeStatus=(flag,event,id)=>{ - const url = `/live_links/${id}.json`; - axios.put(url,{ - on_status:flag?1:0 - }).then(result=>{ - if(result){ - this.props.showNotification(`直播已${flag?"开启":"关闭"}!`); - const { successFunc } = this.props; - successFunc && successFunc(1); - } - }).catch(error=>{ - console.log(error); - }) - } + deleteLive=(id)=>{ this.props.confirm({ content: '是否确认删除?', @@ -44,20 +31,13 @@ class LiveItem extends Component{ } render(){ const { key, item , setLiveId } = this.props; - // let flag = false; - // flag = item.on_status; return(
- {`${item.author_name}`} - + {item.course_name} {item.on_status?'已开播':'未开播'} - { - item.op_auth ? - this.changeStatus(flag,event,item.id)}>:"" - }
@@ -71,8 +51,13 @@ class LiveItem extends Component{ }

- 创建时间:{item.created_at} - + + {`${item.author_name}`} + + { item.platform && 直播平台:{item.platform} } + { item.live_time && 开播时间:{item.live_time}} + { item.duration && 直播时长:{item.duration} } + { item.op_auth ? @@ -80,7 +65,7 @@ class LiveItem extends Component{ } { item.delete_auth ? - this.deleteLive(item.id)}>删除 + this.deleteLive(item.id)}>删除 :"" } diff --git a/public/react/src/modules/courses/Video/LiveNew.js b/public/react/src/modules/courses/Video/LiveNew.js index 2cd23f049..d505f052d 100644 --- a/public/react/src/modules/courses/Video/LiveNew.js +++ b/public/react/src/modules/courses/Video/LiveNew.js @@ -1,20 +1,50 @@ import React,{ Component } from "react"; -import { Modal , Form , Input , Spin } from 'antd'; +import { Modal , Form , Input , Spin , Select , DatePicker , InputNumber } from 'antd'; +import locale from 'antd/lib/date-picker/locale/zh_CN'; +import moment from 'moment'; +import { handleDateString } from 'educoder'; import './video.css'; import axios from 'axios'; + const { TextArea } = Input; +const { Option } = Select; + +function range(start, end) { + const result = []; + for (let i = start; i < end; i++) { + result.push(i); + } + return result; +} +function disabledDateTime() { + return { + disabledMinutes: () => range(1, 30).concat(range(31, 60)), + }; +} +function disabledDate(current) { + return current && current < moment().endOf('day').subtract(1, 'days'); +} + class LiveNew extends Component{ constructor(props){ super(props); this.state={ - isSpining:false + isSpining:false, + beginTime:undefined, + beginTimeFlag:false, } } + componentDidMount=()=>{ + console.log("1",this.props.liveId) + this.checkType(); + } + componentDidUpdate=(prevState)=>{ + console.log("2",prevState.liveId); if(prevState && prevState.liveId !== this.props.liveId){ this.setState({ isSpining:true @@ -25,7 +55,8 @@ class LiveNew extends Component{ checkType=()=>{ const { liveId } = this.props; - + console.log("3",this.props.liveId); + this.clearAll(); if(liveId){ const url =`/live_links/${liveId}/edit.json`; axios.get(url).then(result=>{ @@ -33,14 +64,15 @@ class LiveNew extends Component{ this.props.form.setFieldsValue({ url:result.data.url, description:result.data.description, + platform:result.data.platform || "tencent", + duration:result.data.duration, + course_name:result.data.course_name + }) + this.setState({ + beginTime:result.data.live_time && moment(result.data.live_time,"YYYY-MM-DD HH:mm") }) } }) - }else{ - this.props.form.setFieldsValue({ - url:undefined, - description:undefined - }) } this.setState({ isSpining:false @@ -50,7 +82,13 @@ class LiveNew extends Component{ handleSubmit=()=>{ this.props.form.validateFields((err, values) => { if(!err){ - console.log("2") + const { beginTime } = this.state; + if(!beginTime){ + this.setState({ + beginTimeFlag:true + }) + return; + } const { liveId } = this.props; if(liveId){ // 修改 @@ -64,8 +102,10 @@ class LiveNew extends Component{ // 修改 updateFunc=(id,values)=>{ const url = `/live_links/${id}.json`; + const { beginTime } = this.state; axios.put(url,{ - ...values + ...values, + live_time:beginTime }).then(result=>{ if(result){ this.props.showNotification("修改成功!"); @@ -81,8 +121,10 @@ class LiveNew extends Component{ creatFunc=(values)=>{ const CourseId=this.props.match.params.coursesId; const url = `/courses/${CourseId}/live_links.json`; + const { beginTime } = this.state; axios.post(url,{ - ...values + ...values, + live_time:beginTime }).then(result=>{ if(result){ this.props.showNotification("添加成功!"); @@ -107,15 +149,31 @@ class LiveNew extends Component{ cancelNew=()=>{ const { setliveVisibel } = this.props; + this.clearAll(); + setliveVisibel && setliveVisibel(false); + } + + clearAll=()=>{ this.props.form.setFieldsValue({ + course_name:undefined, + platform:"tencent", url:undefined, - description:undefined + description:undefined, + duration:undefined + }) + this.setState({ + beginTime:undefined + }) + } + + onChangeTime=(data,dateString)=>{ + this.setState({ + beginTime:handleDateString(dateString) }) - setliveVisibel && setliveVisibel(false); } render(){ - const { isSpining } = this.state; + const { isSpining , beginTime , beginTimeFlag } = this.state; const {getFieldDecorator} = this.props.form; const { visible } = this.props; @@ -131,6 +189,24 @@ class LiveNew extends Component{

+ + {getFieldDecorator('course_name', { + rules: [{required: true, message: "请输入课程名字"}], + })( + + )} + + + {getFieldDecorator('platform', { + rules: [{required: true, message: "请选择直播平台"}], + })( + + )} + {getFieldDecorator('url', { rules: [{required: true, message: "请输入第三方直播链接"}], @@ -138,6 +214,38 @@ class LiveNew extends Component{ )} +
+
+

*开播时间

+ +

+ { + beginTimeFlag && 请选择开播时间 + } +

+
+ + {getFieldDecorator('duration', { + rules: [], + })( + + )} + + 分钟 +
{getFieldDecorator('description', { rules: [{ @@ -147,10 +255,7 @@ class LiveNew extends Component{