import React,{ Component } from "react"; import { Modal,Checkbox,Select,Input,Upload,Button,Icon,message,DatePicker,Tooltip} from "antd"; import axios from'axios'; import {getUrl,handleDateString,appendFileSizeToUploadFileAll} from 'educoder'; import locale from 'antd/lib/date-picker/locale/zh_CN'; import moment from 'moment'; import Modals from '../../modals/Modals'; const Option = Select.Option; const dateFormat ="YYYY-MM-DD HH:mm" 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)), // disabledSeconds: () => range(1,60) } } class Selectsetting extends Component{ constructor(props){ super(props); this.state={ description:undefined, datalist:undefined, course_groups:undefined, attachment_histories:undefined, datatime:undefined, unified_setting:true, fileList:[], fileListtype:false } } componentDidMount() { let {discussMessageid} =this.props; let course_id=this.props.course_id; let url="/files/"+discussMessageid+".json"; axios.get(url, { params:{ course_id:course_id, } }) .then((response) => { if(response.status===200){ let newcourse_groups=[]; let list =response.data.course_groups; // let list=[ // { // "course_group_id": 820, // "course_group_name": "示例A班", // "course_group_publish_time": "2019-04-18T17:00:00.000+08:00" // }, // { // "course_group_id": 821, // "course_group_name": "示例B班", // "course_group_publish_time": "2019-04-19T19:00:00.000+08:00" // }, // { // "course_group_id": 822, // "course_group_name": "示例C班", // "course_group_publish_time": "2019-04-10T19:00:00.000+08:00" // } // ] if(list.length!=0){ list.forEach((item,key)=>{ newcourse_groups.push ({ course_group_id:item.course_group_id, course_group_name:item.course_group_id, publish_time:moment(item.course_group_publish_time).format(dateFormat) }) }) }else{ newcourse_groups.push ({ course_group_id:undefined, course_group_name:undefined, publish_time:"" }) } this.setState({ datalist:response.data, description: response.data.description, is_public: response.data.is_public, unified_setting: response.data.unified_setting, datatime:response.data.publish_time, // is_public:response.data.course_groups, //attachment_histories:response.data.attachment_histories course_groups:newcourse_groups }) } }) .catch(function (error) { console.log(error); }); let coursesId=this.props.match.params.coursesId; if(this.props.isAdmin()){ let url = `/courses/${coursesId}/all_course_groups.json` axios.get(url, { }) .then((response) => { this.setState({ course_groupss: response.data.course_groups, }) }) .catch(function (error) { console.log(error); }); } } getalldata=()=>{ } componentDidUpdate = (prevProps) => { if ( prevProps.visible != this.props.visible ) { console.log(prevProps) console.log(this.props) this.setState({ visible:this.props.visible }) this.getalldata() } } onChangepublics=(e)=>{ console.log(e.target.checked) this.setState({ is_public:e.target.checked }) } onChangesettings=(e)=>{ console.log(e.target.checked) this.setState({ unified_setting:e.target.checked }) } settextarea=(e)=>{ this.setState({ description:e.target.value }) } hidecouseShixunModal=()=>{ this.setState({ Modalstype:false, Modalstopval:"", ModalSave:this.hidecouseShixunModal, loadtype:false }) this.props.Cancel() } savecouseShixunModal=()=>{ debugger let {fileList,is_public,unified_setting,description,datatime,course_groups}=this.state; let newfileList=[]; for(var list of fileList){ newfileList.push(list.response.id) } if(description===undefined||description===null){ }else if(description.length>100){ this.setState({ descriptiontypes:true }) return } // course_groups.forEach((item,key)=>{ // if(item.course_group_id===undefined||item.publish_time===undefined){ // this.setState({ // course_group_publish_timestype:true // }) // return // } // }) // if(unified_setting===false){ // // course_groups.forEach((item,key)=>{ // if(item.course_group_id===undefined){ // this.setState({ // course_group_idtypes:true // }) // return // } // }) // // } let coursesId=this.props.match.params.coursesId; let attachmentId=this.props.match.params.attachmentId; let url="/files/"+this.props.discussMessageid+".json"; // axios.put(url,{ course_id:coursesId, new_attachment_id:newfileList.length===0?undefined:newfileList, is_public:is_public, is_unified_setting:unified_setting, publish_time:unified_setting===true?datatime===undefined?moment(new Date()).format('YYYY-MM-DD HH'):datatime:undefined, description:description, course_group_publish_times:unified_setting===false?course_groups:undefined }).then((result)=>{ if(result.data.status===0){ this.props.setupdate(attachmentId) this.props.showNotification("设置资源成功"); this.hidecouseShixunModal() } }) } onChangeTimepublish= (date, dateString) => { // console.log('startValue', dateString); this.setState({ datatime:handleDateString(dateString), }) } // 附件相关 START handleChange = (info) => { let fileList = info.fileList; if(info.file.status!="removed"){ this.setState({ fileList: appendFileSizeToUploadFileAll(fileList), fileListtype:true }); }else{ this.setState({ fileList: appendFileSizeToUploadFileAll(fileList), }); } } // onAttachmentRemove = (file) => { // // confirm({ // // title: '确定要删除这个附件吗?', // // okText: '确定', // // cancelText: '取消', // // // content: 'Some descriptions', // // onOk: () => { // // this.deleteAttachment(file) // // }, // // onCancel() { // // console.log('Cancel'); // // }, // // }); // // return false; // // // this.setState({ // // Modalstype:true, // // Modalstopval:'确定要删除这个附件吗?', // // ModalSave: ()=>this.deleteAttachment(file), // // ModalCancel:this.cancelAttachment // // }) // // return false; // // this.deleteAttachment(file); // } onAttachmentRemove = (file) => { // const url = `/attachments/${file.response ? file.response.id : file.uid}.json` const url = `/attachments/${file.response ? file.response.id : file.uid}.json` axios.delete(url, { }) .then((response) => { if (response.data) { const { status } = response.data; if (status == 0) { this.setState({ fileListtype:false, fileList:[] }) // this.setState((state) => { // const index = state.fileList.indexOf(file); // const newFileList = state.fileList.slice(); // newFileList.splice(index, 1); // return { // fileList: newFileList, // }; // }); } } }) .catch(function (error) { console.log(error); }); this.setState({ fileListtype:false, }) } onChangeTimepublishs= (date, dateString,key) => { let {course_groups}=this.state; let newgroup_publish=course_groups; for(var i=0; i{ let {course_groups}=this.state; let newgroup_publish=course_groups; for(var i=0; i{ let newlist=this.state.course_groups; newlist.splice(key,1); this.setState({ course_groups:newlist }) } addgrouppublish=()=>{ let newlist=this.state.course_groups; newlist.push( { course_group_id : undefined, publish_time :"" // moment(new Date()).format('YYYY-MM-DD HH:mm') }) this.setState({ course_groups:newlist }) } render(){ let {is_public,unified_setting,course_groups,datatime,description,datalist,course_group_publish_timestype}=this.state; const uploadProps = { width: 600, // https://github.com/ant-design/ant-design/issues/15505 // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // showUploadList: false, action: `${getUrl()}/api/attachments.json`, onChange: this.handleChange, onRemove: this.onAttachmentRemove, beforeUpload: (file) => { console.log('beforeUpload', file.name); const isLt150M = file.size / 1024 / 1024 < 150; if (!isLt150M) { message.error('文件大小必须小于150MB!'); } return isLt150M; }, }; // console.log(this.props.has_course_groups) return(
{/*提示*/}
  • 资源名称
  • 下载
  • 引用
  • 版本号
  • {datalist&&datalist.title} {datalist&&datalist.attachment_histories.length===0?"":当前版本}
  • {datalist&&datalist.downloads_count}
  • {datalist&&datalist.quotes}
  • {moment(datalist&&datalist.created_on).format('YYYY-MM-DD HH:mm')==="Invalid date"?"":moment(datalist&&datalist.created_on).format('YYYY-MM-DD HH:mm')}
  • {datalist&&datalist.attachment_histories.map((item,key)=>{ return(
  • {item.title} {/*当前版本*/}
  • {item.downloads_count}
  • {item.quotes}
  • {moment(item.created_on).format('YYYY-MM-DD HH:mm')==="Invalid date"?"":moment(item.created_on).format('YYYY-MM-DD HH:mm')}
  • ) })}

    { this.state.fileListtype===true?"":}

    { this.state.fileListtype===true?

    每次只能上传一个资源,
    删除下面资源可重新上传 }>
    (单个文件最大150M)
    :"" } {this.state.fileListtype===false? (单个文件最大150M) :""}

    {/**/} {/*{this.state.fileList.length===0?"":this.state.fileList.map((item,key)=>{*/} {/*return(*/} {/*

    */} {/**/} {/**/} {/**/} {/**/} {/*{item.name}*/} {/**/} {/**/} {/*{item.response===undefined?"":isNaN(bytesToSize(item.filesize))?"123":bytesToSize(item.filesize)}*/} {/**/} {/*this.onAttachmentRemove(item.response===undefined?"":item.response.id&&item.response.id)}>*/} {/*

    */} {/*)*/} {/*})}*/} {this.state.newfileListtypes===true?

    请先上传资源

    :""}

    勾选后所有用户可见,否则仅课堂成员可见
    {/*{this.props.has_course_groups&&this.props.has_course_groups===true?:""}*/} {/*{this.state.course_groupss&&this.state.course_groupss.length>0?*/} {/*统一设置(选中则所有分班使用相同的发布设置,否则各个单独设置)*/} {/*:""}*/} {/*this.props.has_course_groups&&this.props.has_course_groups===true?:""*/}
    {unified_setting===false? this.state.course_groups&&this.state.course_groups.map((item,key)=>{ return(
    this.onChangeTimepublishs(e,index,key)} // onChange={ this.onChangeTimepublish } disabledTime={disabledDateTime} /> {key!=0?this.deletegrouppublish(key)}>:""} {key===course_groups.length-1?:""}
    ) }):""}

    {unified_setting===true?

    :""} {/*{this.state.course_group_idtypes===true?

    请选择分班

    :""}*/} {/*{course_group_publish_timestype===true?

    请填写完整

    :""}*/} {this.state.descriptiontypes===true?

    描述不能超过最大限制:100个字符

    :""}
    ) } } export default Selectsetting;