import React, { Component } from 'react'; import { Link } from "react-router-dom"; import { getImageUrl ,markdownToHTML, configShareForCustom} from 'educoder'; import { CircularProgress } from 'material-ui/Progress'; import { Modal, Spin, Tooltip ,message,Icon,Button,Divider} from 'antd'; import axios from 'axios'; import '../shixunchildCss/Challenges.css'; import AccountProfile from"../../../user/AccountProfile"; const $ = window.$; class Challenges extends Component { constructor(props) { super(props) this.state = { ChallengesDataList: undefined, operate: true, startbtns: false, sumid: "", sumidtype: false, startshixunCombattype:false, shixunsreplace:false, shixunsmessage:"", hidestartshixunsreplacevalue:"", operationstrue:false, isSpin:false, boxoffsetHeigh:0, opentitletype:true, isopentitletype:"Less", } } ChallengesList = () => { let id = this.props.match.params.shixunId; let ChallengesURL = `/shixuns/` + id + `/challenges.json`; axios.get(ChallengesURL).then((response) => { if (response.status === 200) { if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { }else{ configShareForCustom(this.props.shixunsDetails.name, response.data.description) this.setState({ ChallengesDataList: response.data, sumidtype: false, }); if(response.data.description=== ""||response.data.description===null||response.data.description===undefined){ this.setState({ isopentitletype:"Less", }) } this.getjianjiesize() } } }).catch((error) => { console.log(error) }); } getjianjiesize=()=>{ let {ChallengesDataList}=this.state; let boxoffsetHeigh; let box=document.getElementById("shixunchallengesid"); if(box){ boxoffsetHeigh=box.offsetHeight if(ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined){ }else{ if(this.state.isopentitletype==="greater"){ }else{ if(boxoffsetHeigh>=300){ this.setState({ opentitletype:true, isopentitletype:"greater", boxoffsetHeigh:boxoffsetHeigh }) }else{ this.setState({ isopentitletype:"Less", boxoffsetHeigh:boxoffsetHeigh }) } } } } } componentDidMount() { if(this.state.isopentitletype==="greater"){ }else { this.ChallengesList() } } componentDidUpdate = (prevProps,prevState) => { //防止陷入无限循环 if(prevState.ChallengesDataList!=this.state.ChallengesDataList){ if(this.state.isopentitletype==="greater"){ }else{ this.getjianjiesize() } } } updatamakedown = (id) => { setTimeout(() => { var shixunDescr = window.editormd.markdownToHTML(id, { htmlDecode: "style,script,iframe", taskList: true, tex: true, flowChart: true, sequenceDiagram: true }); $("#" + id + " p:first").addClass("ReactMarkdown"); }, 200) } // 关卡的上移下移操作 operations = (sumid, type) => { this.setState({ operationstrue:true }) let { ChallengesDataList } = this.state; let operationUrl; if (type === "up") { operationUrl = "/shixuns/" + ChallengesDataList.shixun_identifier + "/challenges/" + sumid + "/index_up.json"; } else if (type === "down") { operationUrl = "/shixuns/" + ChallengesDataList.shixun_identifier + "/challenges/" + sumid + "/index_down.json"; } if (this.state.operate) { this.setState({ operate: false }); axios.get(operationUrl).then((response) => { if (response.status === 200) { this.setState({ operate: true, operationstrue:false }); this.ChallengesList(); } }).catch((error) => { console.log(error); this.setState({ operate: true, operationstrue:false }); this.ChallengesList() }) } } delOperations = (sumid) => { this.setState({ sumid: sumid, sumidtype: true }) } clonedelOperationss = () => { this.setState({ sumidtype: false }) } delOperationss = () => { let { ChallengesDataList, sumid } = this.state; let operationUrl = "/shixuns/" + ChallengesDataList.shixun_identifier + "/challenges/" + sumid+".json" if (this.state.operate) { this.setState({ operate: false, sumidtype: false }) axios.delete(operationUrl, { withCredentials: true }).then((response) => { if (response.status === 200) { this.setState({ operate: true, sumidtype: false }); this.ChallengesList(); } this.ChallengesList() }).catch((error) => { console.log(error); this.setState({ operate: true, sumidtype: false }); this.ChallengesList() }) } } startgameid=(id)=>{ let url = "/shixuns/" + id + "/shixun_exec.json"; axios.get(url).then((response) => { if (response.data.status === -2) { this.setState({ shixunsreplace:true, hidestartshixunsreplacevalue:response.data.message+".json" }) } else if (response.data.status === -1) { console.log(response) }else if(response.data.status===-3){ this.setState({ shixunsmessage:response.data.message, startshixunCombattype:true, }) } else { window.location.href = "/tasks/" + response.data.game_identifier; // window.location.href = path // let path="/tasks/"+response.data.game_identifier; // this.props.history.push(path); } }).catch((error) => { }); } hidestartshixunsreplace=(url)=>{ this.setState({ isSpin:true, }) axios.get(url).then((response) => { if(response.status===200){ // let path="/shixuns/"+response.data.shixun_identifier+"/challenges"; // this.props.history.push(path); message.success('重置成功,正在进入实训!'); this.startgameid(response.data.shixun_identifier); this.setState({ shixunsreplace:false, isSpin:false, }) // message.success('重置成功,正在进入实训!'); // this.startshixunCombat(); }} ).catch((error) => { }); } //编辑实训题目选择题 EditTraining=(type, ids, path)=>{ let { ChallengesDataList } = this.state; window.location.href = "/shixuns/" + ChallengesDataList.shixun_identifier + "/challenges/" + ids + path; } //开始实战按钮 startshixunCombat = (type, ids, id) => { if(this.props.checkIfLogin()===false){ this.props.showLoginDialog() return } if(this.props.checkIfProfileCompleted()===false){ this.setState({ AccountProfiletype:true }) return } // if(this.props.checkIfProfessionalCertification()===false){ // this.setState({ // AccountProfiletype:true // }) // return // } let { ChallengesDataList } = this.state; // let id = this.props.match.params.shixunId; this.setState({ startbtns: true }) let url = "/shixuns/" + ChallengesDataList.shixun_identifier + "/shixun_exec.json?challenge_id="+id; axios.get(url).then((response) => { if (response.data.status === -2) { this.setState({ startbtns:false, shixunsreplace:true, hidestartshixunsreplacevalue:response.data.message+".json" }) } else if (response.data.status === -1) { this.setState({ startbtns: false }) console.log(response) }else if(response.data.status===-3){ this.setState({ shixunsmessage:response.data.message, startshixunCombattype:true, startbtns:false }) } else { window.location.href = "/tasks/" + response.data.game_identifier; // window.location.href = path // let path="/tasks/"+response.data.game_identifier; // this.props.history.push(path); } }).catch((error) => { }); // if(path===null){ // }else{ // if (type > 4 || type === false) { // window.location.href = path; // } else { // // } // } } hidestartshixunCombattype=()=>{ this.setState({ startshixunCombattype:false }) } hideAccountProfile=()=>{ this.setState({ AccountProfiletype:false }) } opentitle=()=>{ this.setState({ opentitletype:!this.state.opentitletype, }) } render() { let { ChallengesDataList, startbtns, sumidtype ,startshixunCombattype,shixunsreplace,shixunsmessage,hidestartshixunsreplacevalue,operationstrue,AccountProfiletype} = this.state; let { loadingContent } = this.props; if (ChallengesDataList != undefined) { this.updatamakedown("ReactMarkdown") } let id = this.props.match.params.shixunId; const antIcon = ; return ( {AccountProfiletype===true?this.hideAccountProfile()} {...this.props} {...this.state} />:""} {loadingContent ? :
{/*

*/} {/* {this.props.identity < 5 && ChallengesDataList&&ChallengesDataList.shixun_status=== 0 ?*/} {/* */} {/* */} {/* */} {/* 实践任务*/} {/* */} {/* : ""*/} {/* }*/} {/* {this.props.identity < 5 && ChallengesDataList&&ChallengesDataList.shixun_status=== 0 ?*/} {/* */} {/* */} {/* */} {/* 选择题任务*/} {/* */} {/* : ""*/} {/* }*/} {/*

*/}

简介 {this.props.identity < 5 && ChallengesDataList&&ChallengesDataList.shixun_status < 3 ? {/**/} 编辑 :""} {this.props.user && this.props.user.main_site === true ? this.props.identity < 5?实训制作指南 : "":""}
{ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined?:""} {ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined?"":this.state.isopentitletype==="greater"&&this.state.opentitletype===true? :""}
{ChallengesDataList === undefined || ChallengesDataList&&ChallengesDataList.description=== ""||ChallengesDataList&&ChallengesDataList.description===null||ChallengesDataList&&ChallengesDataList.description===undefined?
{this.props.identity < 5?:}

暂时还没有相关数据哦!

:

{ChallengesDataList === undefined ? "" :ChallengesDataList&&ChallengesDataList.description===null?"":

}

}
{this.state.isopentitletype==="Less"?"":this.state.opentitletype===true?this.opentitle()} className={"pointer Breadcrumbfont color-grey-9 "}> 阅读全文 :this.opentitle()} className={"pointer Breadcrumbfont color-grey-9 "}> 收起全文 }

全部任务 {/* */} {/**/} {/* */} {this.props.identity < 5 && ChallengesDataList&&ChallengesDataList.shixun_status=== 0 ? : "" } {this.props.identity < 5 && ChallengesDataList&&ChallengesDataList.shixun_status=== 0 ? : "" } {/**/} {/* */} {/* */}
{ChallengesDataList === undefined ?
{this.props.identity < 5?:}

暂时还没有相关数据哦!

: ChallengesDataList.challenge_list === undefined ?
{this.props.identity < 5?:}

暂时还没有相关数据哦!

: ChallengesDataList.challenge_list.length === 0 ?
{this.props.identity < 5?:}

暂时还没有相关数据哦!

: ChallengesDataList.challenge_list.map((item, key) => { return (
第{key+1}关:{item.st === 0 ?"实践题":"选择题"} {/*this.startshixunCombat(false,undefined, item.challenge_id)}*/} {/* // onClick={() => this.startshixunCombat(false)}*/} {/* title={"查看挑战关卡"}*/} {/*>已完成*/} {/*判断比较复杂 有排第一不能是灰色按钮*/} {item.status === 2 ? : "" } {/* this.startshixunCombat(false,undefined, item.challenge_id)} // onClick={() => this.startshixunCombat(false)} >直接挑战 */} { ChallengesDataList.allow_skip === true && item.status === 1? : "" } {/* this.startshixunCombat(false,undefined, item.challenge_id)} style={{marginTop: '-2px'}}>直接挑战 */} { ChallengesDataList.allow_skip === false ? item.status === 1? :"":"" } {/**/} {/* this.startshixunCombat(false,undefined, item.challenge_id):""}*/} {/* style={{marginTop: '-2px'}}>直接挑战*/} {/**/} { item.status === 0 ? :"" }
{item.delete_url != undefined && this.delOperations(item.challenge_id)} style={{ display:this.props.user.admin===true?"block":this.props.identity < 5 && ChallengesDataList.shixun_status === 0 ? "block" : 'none' }} className="fl mr25"> {/**/} } {item.up_url != undefined && this.operations(item.challenge_id, "up")} style={{ display:this.props.user.admin===true?"block":this.props.identity < 5 && ChallengesDataList.shixun_status === 0 ? "block" : 'none' }} className="fl mr25"> {/**/} } {item.down_url != undefined && this.operations(item.challenge_id, "down")} style={{ display: this.props.user.admin===true?"block":this.props.identity < 5 && ChallengesDataList.shixun_status=== 0 ? "block" : 'none' }} className="fl mr25"> {/**/} } { item.st === 1 ? {/**/} : {/**/} }
{/*onClick={() => this.EditTraining(this.props.identity, item.challenge_id, "/editquestion")}*/} {this.props.identity<5? item.st === 1 ?
{item.name}
:
{item.name}
:
this.startshixunCombat(this.props.identity, item.challenge_id, "/editcheckpoint")} className="font-16 color05101a fonthiddens">{item.name}
} {/* onClick={() => this.EditTraining(this.props.identity, item.challenge_id, "/editcheckpoint")}*/}
正在挑战: {item.playing_count}人 完成挑战: {item.passed_count}人 可获经验: {item.score}点
) })}

目前该实训项目尚在内测中,将于{shixunsmessage}之后开放,谢谢!

{/*

*/} {/*知道了*/} {/*

*/}

实训已经更新了,正在为您重置!

}
) } } export default Challenges; // { // ChallengesDataList.allow_skip === false ? item.status === 1 && newstatus === 2 ? // // this.startshixunCombat(false,undefined, item.challenge_id)} // style={{marginTop: '-2px'}}>直接挑战 // // // : item.status === 1 && newstatus === 1 ? // // this.startshixunCombat(false,undefined, item.challenge_id)} // style={{marginTop: '-2px'}}>直接挑战 // : "" : "" // // }