import React, {Component} from 'react'; import {Link} from "react-router-dom"; import axios from 'axios'; import {getImageUrl, trigger, on, off} from 'educoder'; import { Tooltip, message,Popover,Breadcrumb} from 'antd'; import CoursesListType from '../coursesPublic/CoursesListType'; import AccountProfile from"../../user/AccountProfile"; import Addcourses from '../coursesPublic/Addcourses'; import '../css/Courses.css'; import Modals from "../../modals/Modals"; import Guide from './CoursesGuide'; import AddStudentModal from '../members/modal/AddStudentModal' import AddTeacherModal from '../members/modal/AddTeacherModal' import Jointheclass from '../../modals/Jointheclass' import Certifiedprofessional from "../../modals/Certifiedprofessional"; // 点击按钮复制功能 // function jsCopy(){ // var e = document.getElementById("copy_invite_code"); // e.select(); // document.execCommand("Copy"); // codesuccess() // } // 点击按钮复制功能 function jsCopy() { var e = document.getElementById("copy_invite_code"); e.select(); document.execCommand("Copy"); codesuccess() } function codesuccess() { message.success('复制成功'); }; class CoursesBanner extends Component { constructor(props) { super(props) this.state = { show: false, Addcoursestypes: false, modalsType: false, modalsTopval: "", loadtype: false, metype: 0, modalsBottomval: "", antIcon:false, coursedata:undefined, is_guide:false, excellent:false,//是否是精品课堂 yslJointhe:false, mydisplay:false } } componentDidMount() { this.onloadupdatabanner() on('updatabanner', this.updatabanner) } componentWillUnmount() { off('updatabanner', this.updatabanner) } HideAddcoursestypess=(i)=>{ console.log("调用了"); this.setState({ Addcoursestypes:false, mydisplay:true, occupation:i, }) }; ModalCancelsy=()=>{ this.setState({ mydisplay:false, }) }; onloadupdatabanner=()=>{ this.updatabanner() } updatabanner=()=>{ let courseId = this.props.match.params.coursesId; let url = "/courses/" + courseId + "/top_banner.json" axios.get(url).then((result) => { if( result!=undefined){ let data = result.data; this.setState({ coursedata: data, excellent:data.excellent, }) }else{ this.onloadupdatabanner() } }) } showeditmenu = () => { this.setState({ show: true, }) } hideeditmenu = () => { this.setState({ show: false }) } tojoinclass = (val) => { if(this.props.current_user&&this.props.current_user.profile_completed===false){ this.setState({ AccountProfiletype:true }) return } if (val === 1) { this.setState({ Addcoursestypes: true, }) } else { this.setState({ Addcoursestypes: false, }) } }; //精品课堂的弹框 myyslgradin=()=>{ this.setState({ yslJointhe:true }) } showActionPoll=(i,s,ss)=>{ this.setState({ modalsType: true, modalsTopval: s, loadtype: false, metype: i, modalsBottomval: ss, }) } ActionPoll = (i) => { let {coursedata}=this.state; var s = ""; var ss = ""; if (i === 1) { s = "课堂删除后数据将无法恢复,是否确定删除?"; this.showActionPoll(i,s) } if (i === 2) { s = "您确定要设置为私有?"; this.showActionPoll(i,s) } if (i === 3) { s = "设为公开后,非课堂成员也可以访问查看"; ss = "是否确认设为公开?"; this.showActionPoll(i,s,ss) } if(i===4){ if(coursedata.code_halt === true){ var url = `/courses/${this.props.match.params.coursesId}/set_invite_code_halt.json` axios.post(url, {}).then((result) => { try { if (result.data.status === 0){ this.updatabanner() } } catch (e) { } }) }else{ s = "邀请码停用后,用户不能主动加入该课堂了"; ss = "您是否确认停用?"; this.showActionPoll(i,s,ss) } } if (i ===5) { s = "复制将在后台执行,作业、资源、试卷都将复制到新课堂平台"; ss = "将为你创建一个新的同名课堂,请问是否继续?"; this.showActionPoll(i,s,ss) } } //取消 modalCancel = () => { this.setState({ modalsType: false, modalsTopval: "", modalsBottomval:"", loadtype: false, antIcon:false }) } // 确定 ModalAction = () => { let {coursedata}=this.state; var push = this.props.history; let id = this.props.match.params.coursesId; //删除 if (this.state.metype === 1) { console.log("删除"); this.modalCancel(); var url = `/courses/${id}.json` axios .delete(url, {}) .then(function (response) { console.log(response.data.status) if (response.data.status === 0) { message.success("删除成功", 1) push.push(`/courses`) } }) } //设为私有的 if (this.state.metype === 2) { this.modalCancel(); var state = this.state; var url = `/courses/${id}/set_public_or_private.json` axios.post(url, {}).then((result) => { if (result.data.status === 0) { message.success("设为私有的成功", 1); state.coursedata.is_public = false; this.setState({ coursedata: state.coursedata, }) } }) } //设为公有的 if (this.state.metype === 3) { this.modalCancel(); var state = this.state; var url = `/courses/${id}/set_public_or_private.json` axios.post(url, {}).then((result) => { if (result.data.status === 0) { message.success("设为公有的成功", 1); state.coursedata.is_public = true; this.setState({ coursedata: state.coursedata, }) } }) } //停用邀请码 if (this.state.metype === 4) { this.modalCancel(); var url = `/courses/${id}/set_invite_code_halt.json` axios.post(url, {}).then((result) => { try { if (result.data.status === 0) { message.success(coursedata.code_halt === true?"启用用邀请码成功":"停用邀请码成功", 1); this.updatabanner() } } catch (e) { } }) } if (this.state.metype ===5) { this.setState({ antIcon: true, }) var url = `/courses/${id}/duplicate_course.json` axios.post(url).then((response) => { if(response!==undefined){ window.location.href = "/courses/" + response.data.new_course_id+"/students"; return } this.modalCancel(); // window.location.href = "/courses/" + response.data.new_course_id; }).catch( (error)=> { this.modalCancel(); console.log(252); console.log(error); }); } if(this.state.metype===6){ this.setState({ antIcon: true, }) var url =`/courses/${id}/exit_course.json`; axios.post(url).then((response) => { if(response.data.status===0){ window.location.href = "/users/" + this.props.current_user.login; } }) } } addTeacher = (isTeacher) => { this.setState({ isTeacher }, () => { this.refs.addTeacherModal.setVisible(true) }) } addStudent = () => { this.refs.addStudentModal.setVisible(true) } addTeacherSuccess = (params) => { trigger('addTeacherSuccess', JSON.stringify(params)) this.updatabanner() } addStudentSuccess = (params) => { trigger('addStudentSuccess', JSON.stringify(params)) this.updatabanner() } //退出课堂按钮 exitclass=()=>{ this.setState({ modalsType: true, modalsTopval: "退出后您将不再是本课题的成员,作品将全部被删除,", modalsBottomval:"确定要退出该课堂吗?", metype:6 }) } //切换身份 switchidentity=(sum)=>{ let newurl=this.props.match.url; let id = this.props.match.params.coursesId; if(sum===1){ let url =`/courses/${id}/switch_to_student.json`; axios.post(url).then((response) => { if(response.data.status===0){ // window.location.href = "/users/" + this.props.current_user.login; // this.props.history.replace(newurl); window.location.href=newurl } }) } if(sum===2){ let url =`/courses/${id}/switch_to_teacher.json`; axios.post(url).then((response) => { if(response.data.status===0){ // window.location.href = "/users/" + this.props.current_user.login; // this.props.history.replace(newurl); window.location.href=newurl } }) } if(sum===3){ let url =`/courses/${id}/switch_to_assistant.json`; axios.post(url).then((response) => { if(response.data.status===0){ // window.location.href = "/users/" + this.props.current_user.login; // this.props.history.replace(newurl); window.location.href=newurl } }) } } postsettings=()=>{ window.location.href = "/courses/" + this.props.match.params.coursesId + "/settings"; }; postsettingstwo=()=>{ // var ids =1; // try { // if(this.state.coursedata.is_public){ // ids=1; // }else { // ids=0; // } // }catch (e) { // // } window.location.href = `/courses/${this.props.match.params.coursesId}/newgolds/settings`; }; hideAccountProfile=()=>{ this.setState({ AccountProfiletype:false }) }; ysljoinmodalCancel=()=>{ this.setState({ yslJointhe:false }) }; ysljoinmodalCanceltwo=()=>{ this.setState({ yslJointhe:false }) window.location.reload(); }; setHistoryFun=(url)=>{ this.props.history.replace(url) } render() { let { Addcoursestypes, coursedata,excellent, modalsType, modalsTopval, loadtype,modalsBottomval,antIcon,is_guide,AccountProfiletype} = this.state; return (