import React, {Component} from 'react'; import {Link} from "react-router-dom"; import axios from 'axios'; import {getImageUrl, trigger} from 'educoder'; import { Tooltip, message,Popover} from 'antd'; import CoursesListType from '../coursesPublic/CoursesListType'; import Addcourses from '../coursesPublic/Addcourses'; import '../css/Courses.css'; import Modals from "../../modals/Modals"; import AddStudentModal from '../members/modal/AddStudentModal' import AddTeacherModal from '../members/modal/AddTeacherModal' import Trialapplication from "../../login/Trialapplication"; // 点击按钮复制功能 // 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, user_phone_binded:false, isRenders:false, showTrial:false, } } componentDidMount() { this.onloadupdatabanner() this.setState({ user_phone_binded :this.props.current_user.user_phone_binded, }) } 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; if(result.data.status === 407){ this.setState({ isRenders:true, coursedata: data, showTrial:false, }) }else{ this.setState({ coursedata: data, showTrial:true, }) } }else{ this.onloadupdatabanner() } }) } showeditmenu = () => { this.setState({ show: true, }) } hideeditmenu = () => { this.setState({ show: false }) } tojoinclass = (val) => { if (val === 1) { this.setState({ Addcoursestypes: true, }) } else { this.setState({ Addcoursestypes: false, }) } } 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 = "您确定要设置为公开?"; this.showActionPoll(i,s) } 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) => { // window.location.href = "/courses/" + response.data.new_course_id; window.location.href = "/courses/" + response.data.new_course_id+"/students"; }) } 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"; } render() { let { Addcoursestypes, coursedata, modalsType, modalsTopval, loadtype,modalsBottomval,antIcon,user_phone_binded} = this.state; return (
{ coursedata === undefined || coursedata.status===401?
:
{Addcoursestypes === true ? this.tojoinclass(2)} /> : ""}
{ coursedata===undefined || coursedata.status===401 || coursedata.status===407?"": {coursedata.name} } {/*私有:私有课堂,非课堂成员不能访问 公开:公开课堂,非课堂成员可以访问*/}
头像

{coursedata.teacher_school}

{coursedata.switch_to_student === true ? this.switchidentity(1)} > 切换为学生 :""} {coursedata.switch_to_teacher === true ? this.switchidentity(2)} > 切换为老师 :""} {coursedata.switch_to_assistant === true ? this.switchidentity(3)} > 切换为助教 :""} {coursedata.course_identity === 6&&coursedata.educoder_teacher===false? this.tojoinclass(1)}>加入课堂: ""} {coursedata.course_identity === 6&&coursedata.educoder_teacher===true? this.tojoinclass(1)}>加入课堂: ""} {coursedata.course_identity === 6&&coursedata.educoder_teacher===true? this.ActionPoll(5)}> 复制课堂 : ""} {this.props.isStudent()? this.exitclass()} > 退出课堂 :""}
{this.props.isAdmin()? } trigger="hover"> :""}
}
) } } export default CoursesBanner; // let id=this.props.match.params.coursesId; // // let url="/courses/"+id+"/top_banner.json" // axios.get(url).then((result)=>{ // if(result.status===200){ // let data=result.data; // this.setState({ // coursebannerlist:result.data, // name: result.data.name, // teacher_name: result.data.teacher_name, // teacher_login: result.data.teacher_login, // teacher_img: result.data.teacher_img, // teacher_school: result.data.teacher_school, // teacher_count: result.data.teacher_count, // student_count: result.data.student_count, // course_group_count: result.data.course_group_count, // credit: result.data.credit, // course_end: result.data.course_end, // deadline: result.data.deadline, // is_teacher: result.data.is_teacher, // is_student: result.data.is_student, // is_admin: result.data.is_admin, // is_public: result.data.is_public, // code_halt: result.data.code_halt, // invite_code: result.data.invite_code, // switch_to_student: result.data.switch_to_student, // switch_to_teacher: result.data.switch_to_teacher, // join_course: result.data.join_course, // copy_course: result.data.copy_course, // }) // } // coursebannerlist:undefined, // name: undefined, // teacher_name: undefined, // teacher_login: undefined, // teacher_img: undefined, // teacher_school: undefined, // teacher_count: undefined, // student_count: undefined, // course_group_count: undefined, // credit: undefined, // course_end: undefined, // deadline: undefined, // is_teacher: undefined, // is_student: undefined, // is_admin: undefined, // is_public: undefined, // code_halt: undefined, // invite_code:undefined, // switch_to_student: undefined, // switch_to_teacher: undefined, // join_course: undefined, // copy_course: undefined, // }).catch((error)=>{ // console.log(error); // })