Adjustreact
caicai8 5 years ago
parent c687561a9b
commit 1c99de4c84

@ -1,5 +1,5 @@
import React,{ Component } from "react"; import React,{ Component } from "react";
import { Modal , Form , Input , Spin , Select , DatePicker , InputNumber } from 'antd'; import { Modal , Form , Input , Spin , Select , AutoComplete , DatePicker , InputNumber } from 'antd';
import locale from 'antd/lib/date-picker/locale/zh_CN'; import locale from 'antd/lib/date-picker/locale/zh_CN';
import moment from 'moment'; import moment from 'moment';
import { handleDateString } from 'educoder'; import { handleDateString } from 'educoder';
@ -9,6 +9,7 @@ import axios from 'axios';
const { TextArea } = Input; const { TextArea } = Input;
const { Option } = Select; const { Option } = Select;
const array=['腾讯课堂','B站','斗鱼','威佰通']
function range(start, end) { function range(start, end) {
const result = []; const result = [];
@ -34,17 +35,14 @@ class LiveNew extends Component{
this.state={ this.state={
isSpining:false, isSpining:false,
beginTime:undefined, beginTime:undefined,
beginTimeFlag:false,
} }
} }
componentDidMount=()=>{ componentDidMount=()=>{
console.log("1",this.props.liveId)
this.checkType(); this.checkType();
} }
componentDidUpdate=(prevState)=>{ componentDidUpdate=(prevState)=>{
console.log("2",prevState.liveId);
if(prevState && prevState.liveId !== this.props.liveId){ if(prevState && prevState.liveId !== this.props.liveId){
this.setState({ this.setState({
isSpining:true isSpining:true
@ -55,7 +53,6 @@ class LiveNew extends Component{
checkType=()=>{ checkType=()=>{
const { liveId } = this.props; const { liveId } = this.props;
console.log("3",this.props.liveId);
this.clearAll(); this.clearAll();
if(liveId){ if(liveId){
const url =`/live_links/${liveId}/edit.json`; const url =`/live_links/${liveId}/edit.json`;
@ -64,7 +61,7 @@ class LiveNew extends Component{
this.props.form.setFieldsValue({ this.props.form.setFieldsValue({
url:result.data.url, url:result.data.url,
description:result.data.description, description:result.data.description,
platform:result.data.platform || "tencent", platform:result.data.platform || "腾讯课堂",
duration:result.data.duration, duration:result.data.duration,
course_name:result.data.course_name course_name:result.data.course_name
}) })
@ -80,15 +77,12 @@ class LiveNew extends Component{
} }
handleSubmit=()=>{ handleSubmit=()=>{
this.setState({
isSpining:true
})
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
if(!err){ if(!err){
const { beginTime } = this.state; console.log(values);
if(!beginTime){
this.setState({
beginTimeFlag:true
})
return;
}
const { liveId } = this.props; const { liveId } = this.props;
if(liveId){ if(liveId){
// 修改 // 修改
@ -108,6 +102,9 @@ class LiveNew extends Component{
live_time:beginTime live_time:beginTime
}).then(result=>{ }).then(result=>{
if(result){ if(result){
this.setState({
isSpining:false
})
this.props.showNotification("修改成功!"); this.props.showNotification("修改成功!");
const { setliveVisibel } = this.props; const { setliveVisibel } = this.props;
setliveVisibel && setliveVisibel(false,true); setliveVisibel && setliveVisibel(false,true);
@ -127,6 +124,9 @@ class LiveNew extends Component{
live_time:beginTime live_time:beginTime
}).then(result=>{ }).then(result=>{
if(result){ if(result){
this.setState({
isSpining:false
})
this.props.showNotification("添加成功!"); this.props.showNotification("添加成功!");
const { setliveVisibel } = this.props; const { setliveVisibel } = this.props;
setliveVisibel && setliveVisibel(false,true); setliveVisibel && setliveVisibel(false,true);
@ -156,7 +156,7 @@ class LiveNew extends Component{
clearAll=()=>{ clearAll=()=>{
this.props.form.setFieldsValue({ this.props.form.setFieldsValue({
course_name:undefined, course_name:undefined,
platform:"tencent", platform:"腾讯课堂",
url:undefined, url:undefined,
description:undefined, description:undefined,
duration:undefined duration:undefined
@ -173,10 +173,15 @@ class LiveNew extends Component{
} }
render(){ render(){
const { isSpining , beginTime , beginTimeFlag } = this.state; const { isSpining , beginTime } = this.state;
const {getFieldDecorator} = this.props.form; const {getFieldDecorator} = this.props.form;
const { visible } = this.props; const { visible } = this.props;
const dataSource = array.map((item,key)=>{
return(
<Option value={item}>{item}</Option>
)
})
return( return(
<Modal <Modal
visible={visible} visible={visible}
@ -200,26 +205,26 @@ class LiveNew extends Component{
{getFieldDecorator('platform', { {getFieldDecorator('platform', {
rules: [{required: true, message: "请选择直播平台"}], rules: [{required: true, message: "请选择直播平台"}],
})( })(
<Select> <AutoComplete
<Option value="tencent">腾讯课堂</Option> placeholder="请选择或输入直播平台名称"
<Option value="douyu">斗鱼</Option> dataSource={dataSource}
<Option value="bilibili">B站</Option> >
</Select> </AutoComplete>
)} )}
</Form.Item> </Form.Item>
<Form.Item label={`直播链接`}> <Form.Item label={`直播链接`}>
{getFieldDecorator('url', { {getFieldDecorator('url', {
rules: [{required: true, message: "请输入第三方直播链接"}], rules: [],
})( })(
<Input placeholder="请输入第三方直播链接,如:腾讯课堂播放链接等。" /> <Input placeholder="请输入第三方直播链接,如:腾讯课堂播放链接等。" />
)} )}
</Form.Item> </Form.Item>
<div className="flex-bottom"> <div className="flex-bottom">
<div className="flex1"> <div className="flex1">
<p className="ant-col ant-form-item-label color-grey-3 font-16 setStyle"><span className="color-red">*</span></p> <p className="ant-col ant-form-item-label color-grey-3 font-16 setStyle">开播时间</p>
<DatePicker <DatePicker
dropdownClassName="hideDisable" dropdownClassName="hideDisable"
className={beginTimeFlag ? "timeStyle borderRed":"timeStyle"} className="timeStyle mb20"
placeholder="年/月/日" placeholder="年/月/日"
style={{width:"220px"}} style={{width:"220px"}}
showTime={{ format: 'HH:mm' }} showTime={{ format: 'HH:mm' }}
@ -231,11 +236,6 @@ class LiveNew extends Component{
value={beginTime && moment(beginTime,"YYYY-MM-DD HH:mm")} value={beginTime && moment(beginTime,"YYYY-MM-DD HH:mm")}
onChange={this.onChangeTime} onChange={this.onChangeTime}
></DatePicker> ></DatePicker>
<p style={{height:"20px",lineHeight:"20px"}} className="pl10">
{
beginTimeFlag && <span className="color-red">请选择开播时间</span>
}
</p>
</div> </div>
<Form.Item label={`直播时长`}> <Form.Item label={`直播时长`}>
{getFieldDecorator('duration', { {getFieldDecorator('duration', {

Loading…
Cancel
Save