import React, {Component} from 'react'; import {Input, InputNumber, Select, Radio, Checkbox, Popconfirm, message, Modal, Tooltip} from 'antd'; import {BrowserRouter as Router, Route, Link, Switch} from "react-router-dom"; // import "antd/dist/antd.css"; import { getImageUrl, toPath, getUrl } from 'educoder'; import axios from 'axios'; import './css/TPMchallengesnew.css'; import TPMMDEditor from './TPMMDEditor'; let origin = getUrl(); let path = getUrl("/editormd/lib/") const $ = window.$; let timeout; let currentValue; const Option = Select.Option; const RadioGroup = Radio.Group; // const testAnswers = [{ // "id": 4337, // "name": "解题思路1", // "contents": "答案的解题思路1", // "level": 1, // "score": 25 // }, // { // "id": 4338, // "name": "解题思路2", // "contents": "答案的解题思路2", // "level": 2, // "score": 25 // }] export default class TPManswer extends Component { constructor(props) { super(props) this.state = { choice_url: undefined, practice_url: undefined, go_back_url: undefined, value: 1, answer:"", id:undefined, checkpointId:undefined, power: false, prev_challenge: undefined, next_challenge: undefined, answers: [] //testAnswers } } componentDidMount() { let id = this.props.match.params.shixunId; let checkpointId=this.props.match.params.checkpointId; let newchoice_url= "/shixuns/"+id+"/challenges/newquestion"; let newpractice_url= "/shixuns/"+id+"/challenges/new"; let newgo_back_url="/shixuns/"+id+"/challenges"; this.setState({ shixunId:id, checkpointId:checkpointId }) let url = "/shixuns/" + id + "/challenges/" + checkpointId + "/edit.json?tab=2"; axios.get(url).then((response) => { let newprev_challenge = response.data.prev_challenge; let next_challenge = response.data.next_challenge; if (newprev_challenge != undefined) { if(newprev_challenge.st===0){ newprev_challenge = "/shixuns/" + id + "/challenges/" + newprev_challenge.id + "/editcheckpoint"; }else{ newprev_challenge = "/shixuns/" + id + "/challenges/" + newprev_challenge.id + "/editquestion"; } } if (next_challenge != undefined) { if(next_challenge.st===0){ next_challenge = "/shixuns/" + id + "/challenges/" + next_challenge.id+ "/editcheckpoint"; }else{ next_challenge = "/shixuns/" + id + "/challenges/" + next_challenge.id+ "/editquestion"; } } this.setState({ answer:response.data.answer, power: response.data.power, choice_url: newchoice_url, // 导航中的新建选择题url practice_url: newpractice_url, //string 导航中新建实践题url go_back_url: newgo_back_url, //string 导航中的返回url position: response.data.position, //int 关卡位置,导航栏中的第几关 prev_challenge: newprev_challenge, next_challenge: next_challenge, }) if(response.data.power===false){ this.props.showSnackbar("没有权限修改"); } // if(response.data.answer===undefined||response.data.answer===null){ // this.answerMD("", "answerMD"); // }else{ // this.answerMD(response.data.answer, "answerMD"); // } }).catch((error) => { console.log(error) }); let urlAnswer = `/shixuns/${id}/challenges/${checkpointId}/answer.json`; axios.get(urlAnswer).then((response) => { if (response.data.status === 401) { } else if (response.data) { this.setState({ answers: response.data }) } }) } challenge_answer_submit=()=> { // `levelSection${index}` // this.refs.md0 const { answers } = this.state; const answersParams = answers.slice(0) console.log(answersParams) let isValidate = true; let totalScore = 0; answersParams.forEach( (item, index) => { if (!isValidate) { return; } const sectionId = `#levelSection${index}`; const mdContnet = this.refs[`md${index}`].getValue().trim();; item.contents = mdContnet; item.name = item.name.trim() totalScore += item.score; delete item.id; if (!item.name) { this.props.showSnackbar("请先填写参考答案名称"); isValidate = false; } else if (!mdContnet) { this.props.showSnackbar("请先填写参考答案内容"); isValidate = false; } if (!isValidate) { $("html, body").animate({ scrollTop: $(`${sectionId}`).offset().top - 100}) } }) if (!isValidate) { return; } if (answersParams.length != 0 && totalScore != 100) { this.props.showSnackbar("请先保证占比和为100%"); return; } let id = this.props.match.params.shixunId; let {checkpointId} = this.state; let url = `/shixuns/${id}/challenges/${checkpointId}/crud_answer.json`; axios.post(url,{ challenge_answer: answersParams } ).then((response) => { if (response.data) { if (response.data.message) { this.props.showSnackbar(response.data.message); } if (response.data.status == 1) { $("html").animate({ scrollTop: 0 }) } } }).catch((error) => { console.log(error) }); } onNameChange = (e, index) => { const newAnswer = Object.assign({}, this.state.answers[index]) newAnswer.name = e.target.value const newAnswers = this.state.answers.slice(0) newAnswers[index] = newAnswer this.setState({ answers: newAnswers}) } onScoreChange = (val, index) => { const newAnswer = Object.assign({}, this.state.answers[index]) newAnswer.score = val const newAnswers = this.state.answers.slice(0) newAnswers[index] = newAnswer this.setState({ answers: newAnswers}) } answerOnChange = (val, index) => { if (!this.state.answers[index]) { // 1、2、3删除2会走到这里 return; } const newAnswer = Object.assign({}, this.state.answers[index]) newAnswer.contents = val const newAnswers = this.state.answers.slice(0) newAnswers[index] = newAnswer this.setState({ answers: newAnswers}) } addAnswer = () => { const newAnswers = this.state.answers.slice(0) newAnswers.push({ "name": `解题思路${newAnswers.length + 1}`, "contents": "", "score": 10 }) this.setState({ answers: newAnswers }) } delanswers=(index)=>{ let {answers}=this.state; let newanswers=answers; newanswers.splice(index,1) this.setState({ answers:newanswers }, () => { for(let i = index; i < newanswers.length; i ++) { this.refs[`md${i}`].setValue(newanswers[i].contents) } }) } render() { let { choice_url, practice_url, go_back_url, position, task_pass_default, submit_url, shixunId, checkpointId, power, prev_challenge, next_challenge, answers, } = this.state; let tab1url="/shixuns/" + shixunId + "/challenges/"+checkpointId+"/editcheckpoint"; let tab2url="/shixuns/" + shixunId + "/challenges/"+checkpointId+"/tab=2"; let tab3url="/shixuns/" + shixunId + "/challenges/"+checkpointId+"/tab=3"; // console.log(this.props) return (
第{position}关 返回 {prev_challenge === undefined ? "" : 上一关 } {next_challenge === undefined ? "" : 下一关 } + 实践类型 + 选择题类型
  • 本关任务
  • 评测设置
  • 参考答案
  • 可以将参考答案分级设置,让学员自行选择级别,每级查看后按照比例扣分值(学员已完成任务再查看,则不影响原因已获得的成绩)

    示例:级别1,扣减分值占比25%;级别2,扣减分值占比35%;级别3,扣减分值占比40%;则学员选择查看级别1的答案,将被扣减25%的分值; 选择查看级别2的答案,将被扣减60%的分值;选择查看级别3的答案,将被扣减100%的分值。

    { answers.map((answer, index) => { return
    *

    级别{index + 1}

    this.delanswers(index)}>
    名称: this.onNameChange(e, index)}> 扣减分值占比: this.onScoreChange(e, index)} >%
    参考答案: this.answerOnChange(val, index)}>
    }) }
    4||this.props.identity===undefined||power===false?"none":"block"}}> 新增
    4||this.props.identity===undefined||power===false?"none":"block"}}> 提交 取消
    ) } }