diff --git a/public/react/src/modules/tpm/TPMIndex.js b/public/react/src/modules/tpm/TPMIndex.js index 98783f552..576b9b5c0 100644 --- a/public/react/src/modules/tpm/TPMIndex.js +++ b/public/react/src/modules/tpm/TPMIndex.js @@ -180,7 +180,7 @@ class TPMIndex extends Component { power: response.data.power, identity: response.data.identity, propaedeutics:response.data.propaedeutics, - status: response.data.status, + status: response.data.shixun_status, }); } }).catch((error) => { diff --git a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js index 193ac511f..ec9d8d503 100644 --- a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js +++ b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js @@ -190,7 +190,7 @@ export default class TPMsettings extends Component { evaluate_script:undefined, standard_scripts: undefined, choice_main_type: "", - choice_small_type: [""], + choice_small_type: [], choice_standard_scripts:undefined, editordescriptios: undefined, editorevaluate_scripts: undefined, @@ -222,7 +222,7 @@ export default class TPMsettings extends Component { scope_partmenttype:false, newuse_scope:undefined, scope_partments:0, - + shixun_service_configs:undefined, pod_exist_time: undefined, pod_exist_timetype: false, shixunmemoMDvalue:"", @@ -325,6 +325,7 @@ export default class TPMsettings extends Component { newuse_scope:response.data.shixun.use_scope, scope_partments: response.data.shixun.scope_partment.length, shixunmemoMDvalue:response.data.shixun.evaluate_script, + shixun_service_configs:response.data.shixun.shixun_service_configs }) // if(response.data.status===403){ @@ -513,6 +514,23 @@ export default class TPMsettings extends Component { bigClass = (value) => { + let {settingsData,shixun_service_configs}=this.state; + let newshixun_service_configs=shixun_service_configs; + + settingsData.shixun.main_type.some((item,key)=> { + if (item.id === value) { + newshixun_service_configs[0]={ + mirror_repository_id:value, + name:item.type_name, + cpu_limit:1, + lower_cpu_limit:0.1, + memory_limit:1024, + request_limit:10 + } + return true + } + } + ) let url = `/shixuns/get_mirror_script.json?mirror_id=`+value; axios.get(url).then((response) => { if (response.status === 200) { @@ -520,7 +538,8 @@ export default class TPMsettings extends Component { this.setState({ choice_main_type: value, standard_scripts:response.data, - choice_standard_scripts:null + choice_standard_scripts:null, + shixun_service_configs:newshixun_service_configs }) } }).catch((error) => { @@ -530,10 +549,78 @@ export default class TPMsettings extends Component { } - + Deselectlittle=(value)=>{ + + let {settingsData,shixun_service_configs,choice_small_type}=this.state; + let newshixun_service_configs=shixun_service_configs; + let newchoice_small_type=choice_small_type; + newchoice_small_type.some((items,keys)=> { + if (items === value) { + newchoice_small_type.splice(keys, 1) + return true + } + } + ) + + + settingsData.shixun.small_type.some((items,keys)=> { + if (items.id === value) { + newshixun_service_configs.splice(keys+1, 1) + return true + } + } + ) + + + + this.setState({ + choice_small_type: newchoice_small_type, + shixun_service_configs:newshixun_service_configs + }) + } littleClass = (value) => { + + let {settingsData,shixun_service_configs,choice_small_type}=this.state; + let newshixun_service_configs=shixun_service_configs; + let newchoice_small_type=choice_small_type; + // if(Array.isArray(value)===true){ + // value.map((item,key)=>{ + // settingsData.shixun.small_type.some((items,keys)=> { + // if (items.id === item) { + // newshixun_service_configs.push({ + // mirror_repository_id:value, + // name:items.type_name, + // cpu_limit:1, + // lower_cpu_limit:0.1, + // memory_limit:1024, + // request_limit:10 + // }) + // return true + // } + // } + // ) + // }) + // } + settingsData.shixun.small_type.some((items,keys)=> { + if (items.id === value) { + newshixun_service_configs.push({ + mirror_repository_id:value, + name:items.type_name, + cpu_limit:1, + lower_cpu_limit:0.1, + memory_limit:1024, + request_limit:10 + }) + return true + } + } + ) + + newchoice_small_type.push(value) + this.setState({ - choice_small_type: value + choice_small_type: newchoice_small_type, + shixun_service_configs:newshixun_service_configs }) } onPodExistTimeChange = (e) => { @@ -596,7 +683,7 @@ export default class TPMsettings extends Component { let { name, description, choice_main_type, choice_small_type, choice_standard_scripts, scope_partment, choice_standard_scriptssum, evaluate_script, exec_time, webssh, use_scope, trainee, can_copy, task_pass, test_set_permission, hide_code, code_hidden, forbid_copy, vnc,multi_webssh, - opening_time, pod_exist_time,shixunmemoMDvalue + opening_time, pod_exist_time,shixunmemoMDvalue,shixun_service_configs } = this.state; let operateauthority=this.props.identity<5&&this.state.status==0||this.props.identity===1&&this.state.status==2||this.props.identity===1&&this.state.status==1; @@ -689,31 +776,35 @@ export default class TPMsettings extends Component { if(newmulti_webssh===null){ newmulti_webssh=0 } - + //exec_time: exec_time, let Url = `/shixuns/` + id + `.json`; let data = { - name: name, - description: description_editormd, - main_type: choice_main_type, - small_type: choice_small_type, - webssh: webssh, - user_scope: use_scope, - scope_partment: scope_partment, - can_copy: can_copy, - vnc: vnc, - test_set_permission: test_set_permission, - code_hidden: code_hidden, - trainee: trainee, - task_pass: task_pass, - standard_scripts: choice_standard_scripts, - hide_code: hide_code, - forbid_copy: forbid_copy, - exec_time: exec_time, - evaluate_script: evaluate_script_editormd, - multi_webssh:newmulti_webssh, - opening_time:opening_time, - mirror_script_id:choice_standard_scriptssum, - delType:1 + shixun:{ + name: name, + webssh: webssh, + user_scope: use_scope, + can_copy: can_copy, + vnc: vnc, + test_set_permission: test_set_permission, + code_hidden: code_hidden, + trainee: trainee, + task_pass: task_pass, + standard_scripts: choice_standard_scripts, + hide_code: hide_code, + forbid_copy: forbid_copy, + multi_webssh:newmulti_webssh, + opening_time:opening_time, + mirror_script_id:choice_standard_scriptssum, + delType:1 + }, + shixun_info:{ + description: description_editormd, + evaluate_script: evaluate_script_editormd, + }, + main_type: choice_main_type, + small_type: choice_small_type, + scope_partment: scope_partment, + shixun_service_configs:shixun_service_configs } axios.put(Url, data).then((response) => { @@ -941,7 +1032,7 @@ export default class TPMsettings extends Component { this.setState({ opers:true }) - e.stopPropagation();//阻止冒泡 + } bigopens=(e)=>{ @@ -951,19 +1042,19 @@ export default class TPMsettings extends Component { opersss:false, opensmail:false }) - e.stopPropagation();//阻止冒泡 + } bigopensmal=(e)=>{ this.setState({ opensmail:true }) - e.stopPropagation();//阻止冒泡 + } sbigopen=(e)=>{ this.setState({ operss:true }) - e.stopPropagation();//阻止冒泡 + } sbigopens=()=>{ @@ -975,7 +1066,7 @@ export default class TPMsettings extends Component { this.setState({ opersss:true }) - e.stopPropagation();//阻止冒泡 + } sbigopensss=()=>{ @@ -1020,7 +1111,9 @@ export default class TPMsettings extends Component { }) } + inputs=()=>{ + } render() { let { @@ -1075,7 +1168,8 @@ export default class TPMsettings extends Component { scope_partmenttype, newuse_scope, scope_partments, - shixunmemoMDvalue,delType + shixunmemoMDvalue,delType, + shixun_service_configs } = this.state; let options; @@ -1259,9 +1353,10 @@ export default class TPMsettings extends Component { value={choice_small_type.length===0||choice_small_type[0]===""||choice_small_type===[]?undefined:choice_small_type} style={{width: 180}} disabled={operateauthority?false:true} - onChange={operateauthority?this.littleClass:""} + // onChange={operateauthority?this.littleClass:""} + onDeselect={operateauthority?this.Deselectlittle:""} onMouseEnter={operateauthority?this.bigopensmal:""} - onSelect={operateauthority?this.bigopens:""} + onSelect={operateauthority?this.littleClass:""} defaultOpen={false} open={opensmail} > @@ -1700,6 +1795,58 @@ export default class TPMsettings extends Component { {/**/} + {/*"name": "我是镜像名", # 镜像名称*/} + {/*"cpu_limit": 1, # cpu核*/} + {/*"lower_cpu_limit": 0.1, # 最低cpu核 浮点数*/} + {/*"memory_limit": 1024 ,#内存限制*/} + {/*"request_limit": 10, # 内存要求*/} + {/*"mirror_repository_id": 12, # 镜像id*/} +
+ {this.props.identity<2?shixun_service_configs&&shixun_service_configs.map((item,key)=>{ + return( +
+

服务配置

+
+

{item.name}

+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ ) + + }) :""} +

{ @@ -1711,49 +1858,7 @@ export default class TPMsettings extends Component { 取消 :"" } - {/*{*/} - {/*this.props.identity===1&&this.props.status==2?*/} - {/*

*/} - {/*保存*/} - {/*取消*/} - {/*/!**!/*/} - {/*/!*永久关闭*!/*/} - {/*/!**!/*/} - {/*
:""*/} - {/*}*/} - - - - - {/*{*/} - {/*this.props.identity===1||this.props.power==true?*/} - {/*
*/} - {/*保存*/} - {/*取消*/} - {/**/} - {/**/} - {/*{status===0?"":"永久关闭"}*/} - {/**/} - {/**/} - {/*
:""*/} - - {/*}*/} - {/*
*/} - {/*保存*/} - {/*取消*/} - {/*
*/} +

diff --git a/public/react/src/modules/tpm/challengesnew/TPManswer.js b/public/react/src/modules/tpm/challengesnew/TPManswer.js index 7d73e9b40..51659e974 100644 --- a/public/react/src/modules/tpm/challengesnew/TPManswer.js +++ b/public/react/src/modules/tpm/challengesnew/TPManswer.js @@ -1,366 +1,366 @@ -import React, {Component} from 'react'; - -import {Input, Select, Radio, Checkbox, Popconfirm, message, Modal} 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'; - -let origin = getUrl(); - -let path = getUrl("/editormd/lib/") - -const $ = window.$; - -let timeout; - -let currentValue; - -const Option = Select.Option; - -const RadioGroup = Radio.Group; - - -// 恢复数据 -function md_rec_data(k,mdu,id, editor){ - if(window.sessionStorage.getItem(k+mdu) !== null){ - editor.setValue(window.sessionStorage.getItem(k+mdu)); - md_clear_data(k,mdu,id); - } -} - -// 保存数据 -function md_add_data(k,mdu,d){ - window.sessionStorage.setItem(k+mdu,d); -} - -// 清空保存的数据 -function md_clear_data(k,mdu,id){ - window.sessionStorage.removeItem(k+mdu); - var id1 = "#e_tip_"+id; - var id2 = "#e_tips_"+id; - if(k == 'content'){ - $(id2).html(""); - }else{ - $(id1).html(""); - } -} - -function md_elocalStorage(editor,mdu,id){ - if (window.sessionStorage){ - var oc = window.sessionStorage.getItem('content'+mdu); - if(oc !== null ){ - console.log("#e_tips_"+id) - $("#e_tips_"+id).data('editor', editor); - var h = '您上次有已保存的数据,是否恢复 ? / 不恢复'; - $("#e_tips_"+id).html(h); - } - setInterval(function() { - var d = new Date(); - var h = d.getHours(); - var m = d.getMinutes(); - var s = d.getSeconds(); - h = h < 10 ? '0' + h : h; - m = m < 10 ? '0' + m : m; - s = s < 10 ? '0' + s : s; - if(editor.getValue().trim() != ""){ - md_add_data("content",mdu,editor.getValue()); - var id1 = "#e_tip_"+id; - var id2 = "#e_tips_"+id; - - $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 "); - $(id2).html(""); - } - },10000); - - }else{ - $("#e_tip_"+id).after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!'); - } -} - - -function create_editorMD(id, width, high, placeholder, imageUrl, callback) { - var editorName = window.editormd(id, { - width: width, - height: high, - path: path, // "/editormd/lib/" - - syncScrolling: "single", - tex: true, - tocm: true, - emoji: true, - taskList: true, - codeFold: true, - searchReplace: true, - htmlDecode: "style,script,iframe", - sequenceDiagram: true, - autoFocus: false, - toolbarIcons: function () { - // Or return editormd.toolbarModes[name]; // full, simple, mini - // Using "||" set icons align right. - return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"] - }, - toolbarCustomIcons: { - testIcon: "
", - testIcon1: "
" - }, - //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 - saveHTMLToTextarea: true, - // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 - dialogMaskOpacity: 0.6, - placeholder: placeholder, - imageUpload: true, - imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], - imageUploadURL: imageUrl,//url - onload: function () { - // this.previewing(); - $("#" + id + " [type=\"latex\"]").bind("click", function () { - editorName.cm.replaceSelection("```latex"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("```"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line - 1, 0); - }); - - $("#" + id + " [type=\"inline\"]").bind("click", function () { - editorName.cm.replaceSelection("$$$$"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line, __Cursor.ch - 2); - editorName.cm.focus(); - }); - $("[type=\"inline\"]").attr("title", "行内公式"); - $("[type=\"latex\"]").attr("title", "多行公式"); - - md_elocalStorage(editorName, `answers__${id}`, "Memoanswers"); - - callback && callback() - } - }); - return editorName; -} - - -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, - } - } - - answerMD(initValue, id) { - - this.contentChanged = false; - const placeholder = ""; - // amp; - // 编辑时要传memoId - const imageUrl = `/api/attachments.json`; - // 创建editorMd - - const answers_editormd = create_editorMD(id, '100%', 400, placeholder, imageUrl, () => { - setTimeout(() => { - answers_editormd.resize() - answers_editormd.cm && answers_editormd.cm.refresh() - }, 500) - - if (initValue != undefined) { - answers_editormd.setValue(initValue) - } - answers_editormd.cm.on("change", (_cm, changeObj) => { - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - this.answers_editormd = answers_editormd; - window.answers_editormd = answers_editormd; - - } - - 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) - }); - } - - challenge_answer_submit=()=> { - let id = this.props.match.params.shixunId; - let{checkpointId}=this.state; - let url = "/shixuns/"+id+"/challenges/"+checkpointId+".json"; - const answer_editormdvalue = this.answers_editormd.getValue(); - - axios.put(url,{ - tab:2, - identifier:id, - id:checkpointId, - challenge:{ - answer:answer_editormdvalue - } - } - ).then((response) => { - this.props.showSnackbar(response.data.messages); - - }).catch((error) => { - console.log(error) - }); - } - - render() { - - let { - choice_url, - practice_url, - go_back_url, - position, - task_pass_default, - submit_url, - shixunId, - checkpointId, - power, - prev_challenge, - next_challenge, - } = 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 ? "" : - 下一关 - } - - + 实践类型 - + 选择题类型 - -
- -
- -
  • - 本关任务 -
  • - -
  • - 评测设置 -
  • - -
  • - 参考答案 -
  • -
    - -
    - -
    -

    参考答案

    -
    -
    - -
    -
    -
    -
    -

    -

    -
    - -
    - -
    3||this.props.identity===undefined||power===false?"none":"block"}}> - 提交 - 取消 -
    -
    -
    - ) - } -} - - +import React, {Component} from 'react'; + +import {Input, Select, Radio, Checkbox, Popconfirm, message, Modal} 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'; + +let origin = getUrl(); + +let path = getUrl("/editormd/lib/") + +const $ = window.$; + +let timeout; + +let currentValue; + +const Option = Select.Option; + +const RadioGroup = Radio.Group; + + +// 恢复数据 +function md_rec_data(k,mdu,id, editor){ + if(window.sessionStorage.getItem(k+mdu) !== null){ + editor.setValue(window.sessionStorage.getItem(k+mdu)); + md_clear_data(k,mdu,id); + } +} + +// 保存数据 +function md_add_data(k,mdu,d){ + window.sessionStorage.setItem(k+mdu,d); +} + +// 清空保存的数据 +function md_clear_data(k,mdu,id){ + window.sessionStorage.removeItem(k+mdu); + var id1 = "#e_tip_"+id; + var id2 = "#e_tips_"+id; + if(k == 'content'){ + $(id2).html(""); + }else{ + $(id1).html(""); + } +} + +function md_elocalStorage(editor,mdu,id){ + if (window.sessionStorage){ + var oc = window.sessionStorage.getItem('content'+mdu); + if(oc !== null ){ + console.log("#e_tips_"+id) + $("#e_tips_"+id).data('editor', editor); + var h = '您上次有已保存的数据,是否恢复 ? / 不恢复'; + $("#e_tips_"+id).html(h); + } + setInterval(function() { + var d = new Date(); + var h = d.getHours(); + var m = d.getMinutes(); + var s = d.getSeconds(); + h = h < 10 ? '0' + h : h; + m = m < 10 ? '0' + m : m; + s = s < 10 ? '0' + s : s; + if(editor.getValue().trim() != ""){ + md_add_data("content",mdu,editor.getValue()); + var id1 = "#e_tip_"+id; + var id2 = "#e_tips_"+id; + + $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 "); + $(id2).html(""); + } + },10000); + + }else{ + $("#e_tip_"+id).after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!'); + } +} + + +function create_editorMD(id, width, high, placeholder, imageUrl, callback) { + var editorName = window.editormd(id, { + width: width, + height: high, + path: path, // "/editormd/lib/" + + syncScrolling: "single", + tex: true, + tocm: true, + emoji: true, + taskList: true, + codeFold: true, + searchReplace: true, + htmlDecode: "style,script,iframe", + sequenceDiagram: true, + autoFocus: false, + toolbarIcons: function () { + // Or return editormd.toolbarModes[name]; // full, simple, mini + // Using "||" set icons align right. + return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"] + }, + toolbarCustomIcons: { + testIcon: "
    ", + testIcon1: "
    " + }, + //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 + saveHTMLToTextarea: true, + // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 + dialogMaskOpacity: 0.6, + placeholder: placeholder, + imageUpload: true, + imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], + imageUploadURL: imageUrl,//url + onload: function () { + // this.previewing(); + $("#" + id + " [type=\"latex\"]").bind("click", function () { + editorName.cm.replaceSelection("```latex"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("```"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line - 1, 0); + }); + + $("#" + id + " [type=\"inline\"]").bind("click", function () { + editorName.cm.replaceSelection("$$$$"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line, __Cursor.ch - 2); + editorName.cm.focus(); + }); + $("[type=\"inline\"]").attr("title", "行内公式"); + $("[type=\"latex\"]").attr("title", "多行公式"); + + md_elocalStorage(editorName, `answers__${id}`, "Memoanswers"); + + callback && callback() + } + }); + return editorName; +} + + +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, + } + } + + answerMD(initValue, id) { + + this.contentChanged = false; + const placeholder = ""; + // amp; + // 编辑时要传memoId + const imageUrl = `/api/attachments.json`; + // 创建editorMd + + const answers_editormd = create_editorMD(id, '100%', 400, placeholder, imageUrl, () => { + setTimeout(() => { + answers_editormd.resize() + answers_editormd.cm && answers_editormd.cm.refresh() + }, 500) + + if (initValue != undefined) { + answers_editormd.setValue(initValue) + } + answers_editormd.cm.on("change", (_cm, changeObj) => { + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + this.answers_editormd = answers_editormd; + window.answers_editormd = answers_editormd; + + } + + 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) + }); + } + + challenge_answer_submit=()=> { + let id = this.props.match.params.shixunId; + let{checkpointId}=this.state; + let url = "/shixuns/"+id+"/challenges/"+checkpointId+".json"; + const answer_editormdvalue = this.answers_editormd.getValue(); + + axios.put(url,{ + tab:2, + identifier:id, + id:checkpointId, + challenge:{ + answer:answer_editormdvalue + } + } + ).then((response) => { + this.props.showSnackbar(response.data.messages); + + }).catch((error) => { + console.log(error) + }); + } + + render() { + + let { + choice_url, + practice_url, + go_back_url, + position, + task_pass_default, + submit_url, + shixunId, + checkpointId, + power, + prev_challenge, + next_challenge, + } = 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 ? "" : + 下一关 + } + + + 实践类型 + + 选择题类型 + +
    + +
    + +
  • + 本关任务 +
  • + +
  • + 评测设置 +
  • + +
  • + 参考答案 +
  • +
    + +
    + +
    +

    参考答案

    +
    +
    + +
    +
    +
    +
    +

    +

    +
    + +
    + +
    3||this.props.identity===undefined||power===false?"none":"block"}}> + 提交 + 取消 +
    +
    +
    + ) + } +} + + diff --git a/public/react/src/modules/tpm/challengesnew/TPManswer2.js b/public/react/src/modules/tpm/challengesnew/TPManswer2.js index cebf4386e..f379ccf53 100644 --- a/public/react/src/modules/tpm/challengesnew/TPManswer2.js +++ b/public/react/src/modules/tpm/challengesnew/TPManswer2.js @@ -1,345 +1,345 @@ -import React, {Component} from 'react'; - -import {Input, InputNumber, Select, Radio, Checkbox, Popconfirm, message, Modal} 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) { - 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 (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); - } - } - - }).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}) - } - 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 - }) - } - 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)} >% -
    -
    - 参考答案: - -
    -
    -
    - }) - } - -
    3||this.props.identity===undefined||power===false?"none":"block"}}> - 新增 -
    -
    - - -
    - -
    3||this.props.identity===undefined||power===false?"none":"block"}}> - 提交 - 取消 -
    -
    -
    - ) - } -} - - +import React, {Component} from 'react'; + +import {Input, InputNumber, Select, Radio, Checkbox, Popconfirm, message, Modal} 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) { + 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 (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); + } + } + + }).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}) + } + 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 + }) + } + 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)} >% +
    +
    + 参考答案: + +
    +
    +
    + }) + } + +
    3||this.props.identity===undefined||power===false?"none":"block"}}> + 新增 +
    +
    + + +
    + +
    3||this.props.identity===undefined||power===false?"none":"block"}}> + 提交 + 取消 +
    +
    +
    + ) + } +} + + diff --git a/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js b/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js index 5d12d0e7f..e0944cac6 100644 --- a/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js +++ b/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js @@ -1,733 +1,754 @@ -import React, {Component} from 'react'; - -import {Input, Select, Radio, Checkbox, Popconfirm, message, Modal} from 'antd'; - -import {BrowserRouter as Router, Route, Link, Switch} from "react-router-dom"; - -// import "antd/dist/antd.css"; - -import axios from 'axios'; - -import './css/TPMchallengesnew.css'; - -import { getImageUrl, toPath } from 'educoder'; - -import {getUrl} from 'educoder'; - -let origin = getUrl(); - -let path = getUrl("/editormd/lib/") - -const $ = window.$; - -let timeout; - -let currentValue; - -const Option = Select.Option; - -const RadioGroup = Radio.Group; - -// 恢复数据 -function md_rec_data(k,mdu,id, editor){ - if(window.sessionStorage.getItem(k+mdu) !== null){ - editor.setValue(window.sessionStorage.getItem(k+mdu)); - md_clear_data(k,mdu,id); - } -} - -// 保存数据 -function md_add_data(k,mdu,d){ - window.sessionStorage.setItem(k+mdu,d); -} - -// 清空保存的数据 -function md_clear_data(k,mdu,id){ - window.sessionStorage.removeItem(k+mdu); - var id1 = "#e_tip_"+id; - var id2 = "#e_tips_"+id; - if(k == 'content'){ - $(id2).html(""); - }else{ - $(id1).html(""); - } -} - -function md_elocalStorage(editor,mdu,id){ - if (window.sessionStorage){ - var oc = window.sessionStorage.getItem('content'+mdu); - if(oc !== null ){ - - $("#e_tips_"+id).data('editor', editor); - var h = '您上次有已保存的数据,是否恢复 ? / 不恢复'; - $("#e_tips_"+id).html(h); - } - setInterval(function() { - var d = new Date(); - var h = d.getHours(); - var m = d.getMinutes(); - var s = d.getSeconds(); - h = h < 10 ? '0' + h : h; - m = m < 10 ? '0' + m : m; - s = s < 10 ? '0' + s : s; - if(editor.getValue().trim() != ""){ - md_add_data("content",mdu,editor.getValue()); - var id1 = "#e_tip_"+id; - var id2 = "#e_tips_"+id; - - $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 "); - $(id2).html(""); - } - },10000); - - }else{ - $("#e_tip_"+id).after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!'); - } -} - - -function create_editorMD(id, width, high, placeholder, imageUrl, callback) { - var editorName = window.editormd(id, { - width: width, - height: high, - path: path, // "/editormd/lib/" - - syncScrolling: "single", - tex: true, - tocm: true, - emoji: true, - taskList: true, - codeFold: true, - searchReplace: true, - htmlDecode: "style,script,iframe", - sequenceDiagram: true, - autoFocus: false, - toolbarIcons: function () { - // Or return editormd.toolbarModes[name]; // full, simple, mini - // Using "||" set icons align right. - return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"] - }, - toolbarCustomIcons: { - testIcon: "
    ", - testIcon1: "
    " - }, - //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 - saveHTMLToTextarea: true, - // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 - dialogMaskOpacity: 0.6, - placeholder: placeholder, - imageUpload: true, - imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], - imageUploadURL: imageUrl,//url - onload: function () { - // this.previewing(); - $("#" + id + " [type=\"latex\"]").bind("click", function () { - editorName.cm.replaceSelection("```latex"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("```"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line - 1, 0); - }); - - $("#" + id + " [type=\"inline\"]").bind("click", function () { - editorName.cm.replaceSelection("$$$$"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line, __Cursor.ch - 2); - editorName.cm.focus(); - }); - $("[type=\"inline\"]").attr("title", "行内公式"); - $("[type=\"latex\"]").attr("title", "多行公式"); - - md_elocalStorage(editorName, `exercise__${id}`, "Memochallengesnew"); - - callback && callback() - } - }); - return editorName; -} - - -export default class TPMchallengesnew extends Component { - constructor(props) { - super(props) - this.state = { - choice_url: undefined, - practice_url: undefined, - go_back_url: undefined, - task_pass_default: undefined, - submit_url: undefined, - shixunCreatePracticeGroup: 1, - optionsums:[100,200], - activetype:0, - setopen: false, - shixunCreatePractice: undefined, - onshixunsmarkvalue: 100, - shixunsskillvalue: undefined, - shixunsskillvaluelist: [], - tab2url: "", - tab3url: "", - prev_challenge:undefined, - next_challenge:undefined, - power: false, - shixunCreatePracticetype: false, - shixunsskillvaluelisttype: false, - marktype:false, - editPracticesendtype:false, - CreatePracticesendtype:false - } - } - - - exerciseMD(initValue, id) { - - this.contentChanged = false; - const placeholder = ""; - // amp; - // 编辑时要传memoId - const imageUrl = `/api/attachments.json`; - // 创建editorMd - - const exercise_editormd = create_editorMD(id, '100%', 400, placeholder, imageUrl, () => { - setTimeout(() => { - exercise_editormd.resize() - exercise_editormd.cm && exercise_editormd.cm.refresh() - }, 500) - - if (initValue != undefined) { - exercise_editormd.setValue(initValue) - } - exercise_editormd.cm.on("change", (_cm, changeObj) => { - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - this.exercise_editormd = exercise_editormd; - window.exercise_editormd = exercise_editormd; - - } - - formatSearch = (url) => { - if (typeof url !== "undefined") { - url = url.substr(1); //从起始索引号提取字符串中指定数目的字符 - var arr = url.split("&"), //把字符串分割为字符串数组 - obj = {}, - newarr = []; - arr.forEach(function (v, i) { //数组遍历 - // console.log(v); - // console.log(i); - newarr = v.split("="); - if (typeof obj[newarr[0]] === "undefined") { - obj[newarr[0]] = newarr[1]; - } - }); - return obj; - } - ; - } - 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" - if(checkpointId===undefined){ - //新建模式 - let url = "/shixuns/" + id + "/challenges/new.json" - axios.get(url).then((response) => { - this.setState({ - choice_url: newchoice_url, - practice_url: newpractice_url, - go_back_url: newgo_back_url, - position: response.data.position, - task_pass_default: response.data.task_pass_default, - submit_url: response.data.submit_url, - checkpointId:checkpointId - }) - this.exerciseMD(response.data.task_pass_default, "exercisememoMD"); - }).catch((error) => { - console.log(error) - }); - }else{ - //编辑模式 - let url="/shixuns/"+id+"/challenges/"+checkpointId+".json?tab=0"; - axios.get(url).then((response) => { - - let optionsum; - if(response.data.difficulty===1){ - optionsum=[100,200]; - }else if(response.data.difficulty===2){ - optionsum=[300,400,500,600]; - }else if(response.data.difficulty===3){ - optionsum=[700,800,900,1000] - } - 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({ - power: response.data.power, - prev_challenge:newprev_challenge, - next_challenge:next_challenge, - choice_url: newchoice_url, - practice_url: newpractice_url, - go_back_url: newgo_back_url, - shixunCreatePractice:response.data.subject, - position:response.data.position, - shixunCreatePracticeGroup:response.data.difficulty, - optionsums:optionsum, - onshixunsmarkvalue:response.data.score, - shixunsskillvaluelist:response.data.tags, - checkpointId:checkpointId, - tab2url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=2", - tab3url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=3", - }) - if(response.data.power===false){ - this.props.showSnackbar("你没有权限修改"); - } - this.exerciseMD(response.data.task_pass, "exercisememoMD"); - }).catch((error) => { - console.log(error) - }); - - } - - } - - onshixunCreatePracticeChange = (e) => { - let optionsum; - let onshixunsmark; - if(e.target.value===1){ - optionsum=[100,200]; - onshixunsmark=100; - }else if(e.target.value===2){ - optionsum=[300,400,500,600]; - onshixunsmark=300; - }else if(e.target.value===3){ - optionsum=[700,800,900,1000] - onshixunsmark=700; - } - this.setState({ - shixunCreatePracticeGroup: e.target.value, - optionsums:optionsum, - onshixunsmarkvalue:onshixunsmark - }) - } - - shixunCreatePractice = (e) => { - this.setState({ - shixunCreatePractice: e.target.value - }) - } - - CreatePracticesend = () => { - this.setState({ - CreatePracticesendtype:true - }) - - if(this.props.status===2){ - this.props.showSnackbar("该实训已经发布不能新建") - this.setState({ - CreatePracticesendtype:false - }) - return - } - let {shixunCreatePractice, shixunCreatePracticeGroup, onshixunsmarkvalue, shixunsskillvaluelist} = this.state; - if (shixunCreatePractice === undefined||shixunCreatePractice=="") { - this.setState({ - shixunCreatePracticetype: true - }) - this.props.showSnackbar("任务名称为空") - $('html').animate({ - scrollTop: 10 - }, 1000); - - this.setState({ - CreatePracticesendtype:false - }) - return - } - - if (shixunsskillvaluelist.length === 0) { - this.setState({ - shixunsskillvaluelisttype: true, - CreatePracticesendtype:false - }) - this.props.showSnackbar("技能标签为空") - return - } - - const exercise_editormdvalue = this.exercise_editormd.getValue(); - - let id = this.props.match.params.shixunId; - - let url = "/shixuns/" + id + "/challenges.json"; - - axios.post(url, { - identifier:id, - subject: shixunCreatePractice, - task_pass: exercise_editormdvalue, - difficulty: shixunCreatePracticeGroup, - score: onshixunsmarkvalue, - challenge_tag: shixunsskillvaluelist, - st: 0 - }).then((response) => { - this.props.showSnackbar(response.data.messages); - if (response.data.status === 1) { - this.setState({ - setopen: true, - tab2url: "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=2", - tab3url: "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=3", - }) - window.location.href = "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=2" - } - - }).catch((error) => { - console.log(error) - }); - - - - } - - onshixunsmark = (value) => { - this.setState({ - onshixunsmarkvalue: value - }) - } - - shixunsskill = (e) => { - this.setState({ - shixunsskillvalue: e.target.value - }) - } - - clickshixunsskill = () => { - - let {shixunsskillvalue, shixunsskillvaluelist} = this.state; - if (shixunsskillvalue === "") { - return - } else if (shixunsskillvalue === undefined) { - return - } - - if(shixunsskillvalue == "" || shixunsskillvalue == undefined || shixunsskillvalue == null || (shixunsskillvalue.length>0 && shixunsskillvalue.trim().length == 0)){ - message.error("输入为空,不能保存!"); - return - } - - let list = shixunsskillvaluelist; - list.push(shixunsskillvalue); - this.setState({ - shixunsskillvaluelist: list, - shixunsskillvalue: "" - }) - } - - delshixunsskilllist = (key) => { - let {shixunsskillvaluelist} = this.state; - let newshixunsskillvaluelist = shixunsskillvaluelist; - newshixunsskillvaluelist.splice(key, 1); - this.setState({ - shixunsskillvaluelist: newshixunsskillvaluelist - }) - } - - editPracticesend=()=>{ - - this.setState({ - editPracticesendtype:true - }) - - let {shixunCreatePractice, shixunCreatePracticeGroup, onshixunsmarkvalue, shixunsskillvaluelist,checkpointId} = this.state; - - const exercise_editormdvalue = this.exercise_editormd.getValue(); - - let id = this.props.match.params.shixunId; - - let url = "/shixuns/"+id+"/challenges/"+checkpointId+".json"; - - if (shixunCreatePractice === undefined||shixunCreatePractice=="") { - // this.setState({ - // shixunCreatePracticetype: true - // }) - this.props.showSnackbar("任务名称为空") - $('html').animate({ - scrollTop: 10 - }, 1000); - this.setState({ - editPracticesendtype:false - }) - return - } - - if (shixunsskillvaluelist.length === 0) { - // this.setState({ - // shixunsskillvaluelisttype: true - // }) - this.props.showSnackbar("技能标签为空") - this.setState({ - editPracticesendtype:false - }) - return - } - axios.put(url, { - tab:0, - identifier:id, - id:checkpointId, - challenge:{ - subject: shixunCreatePractice, - task_pass: exercise_editormdvalue, - difficulty: shixunCreatePracticeGroup, - score: onshixunsmarkvalue, - }, - challenge_tag:shixunsskillvaluelist - }).then((response) => { - this.props.showSnackbar(response.data.messages); - if (response.data.status === 1) { - this.setState({ - setopen: true, - tab2url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=2", - tab3url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=3", - }) - window.location.href = "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=2" - } - }).catch((error) => { - console.log(error) - }); - - - } - - onshixunsmarks=()=> { - this.setState({ - marktype:true - }) - } - - onshixunsmarkss=()=> { - this.setState({ - marktype:false - }) - } - render() { - - let shixuntype = this.props.match.params.type; - - - let {marktype, - shixunCreatePracticetype, shixunsskillvaluelisttype, - choice_url, practice_url, go_back_url, position, task_pass_default, submit_url, setopen,checkpointId,prev_challenge,next_challenge,power, - shixunCreatePractice, shixunCreatePracticeGroup, onshixunsmarkvalue, shixunsskillvalue, shixunsskillvaluelist, tab2url, tab3url,optionsums, - CreatePracticesendtype,editPracticesendtype - } = this.state; - - let options; - options = optionsums.map((d, k) => { - return ( - - ) - }) - - return ( - -
    -
    - - - - 第{position}关 - - 返回 - - { prev_challenge===undefined?"": - 上一关 - } - - { next_challenge===undefined?"": - 下一关 - } - - - 3||this.props.identity===undefined||this.props.status===2||this.props.status===1?"none":'block'}} - data-tip-down="新增代码编辑类型的任务">+ 实践类型 - - 3||this.props.identity===undefined||this.props.status===2||this.props.status===1?"none":'block'}} - data-tip-down="新增选择题类型的任务">+ 选择题类型 - -
    - -
    - -
  • - 本关任务 -
  • - -
  • - {tab2url === "" ? 评测设置 : 评测设置} -
  • - -
  • - {tab3url === "" ? 参考答案 : 参考答案} - -
  • -
    - -
    -
    -

    任务名称

    -
    - * -
    - -
    -
    - 必填项 -
    -
    -
    -
    - - -
    - -

    过关任务

    - -
    - -
    -
    -
    -

    -

    -
    - - -
    -

    难度系数

    -
    - - - 简单 - 中等 - 困难 - - -
    -

    奖励经验值

    -
    - * - - - - -

    - 如果学员答题错误,则不能得到相应的经验值
    - 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币 -

    - - 必填项 -
    -
    - - -
    -

    技能标签

    -
    - * -
    - - {/*+ 添加*/} -
    学员答题正确将获得技能,否则不能获得技能
    -
    - - { - shixunsskillvaluelist.length === 0 ? "" : shixunsskillvaluelist.map((itme, key) => { - return ( -
  • {itme} - this.delshixunsskilllist(key)}>× -
  • - ) - }) - } - - -
    -
    - - 必填项 -
    -
    - -
    3||this.props.identity===undefined?"none":'block'}} - > - {checkpointId===undefined?提交: - 提交} - 取消 -
    -
    -
    - ) - } -} - - +import React, {Component} from 'react'; + +import {Input, Select, Radio, Checkbox, Popconfirm, message, Modal} from 'antd'; + +import {BrowserRouter as Router, Route, Link, Switch} from "react-router-dom"; + +// import "antd/dist/antd.css"; + +import axios from 'axios'; + +import './css/TPMchallengesnew.css'; + +import { getImageUrl, toPath } from 'educoder'; + +import {getUrl} from 'educoder'; + +let origin = getUrl(); + +let path = getUrl("/editormd/lib/") + +const $ = window.$; + +let timeout; + +let currentValue; + +const Option = Select.Option; + +const RadioGroup = Radio.Group; + +// 恢复数据 +function md_rec_data(k,mdu,id, editor){ + if(window.sessionStorage.getItem(k+mdu) !== null){ + editor.setValue(window.sessionStorage.getItem(k+mdu)); + md_clear_data(k,mdu,id); + } +} + +// 保存数据 +function md_add_data(k,mdu,d){ + window.sessionStorage.setItem(k+mdu,d); +} + +// 清空保存的数据 +function md_clear_data(k,mdu,id){ + window.sessionStorage.removeItem(k+mdu); + var id1 = "#e_tip_"+id; + var id2 = "#e_tips_"+id; + if(k == 'content'){ + $(id2).html(""); + }else{ + $(id1).html(""); + } +} + +function md_elocalStorage(editor,mdu,id){ + if (window.sessionStorage){ + var oc = window.sessionStorage.getItem('content'+mdu); + if(oc !== null ){ + + $("#e_tips_"+id).data('editor', editor); + var h = '您上次有已保存的数据,是否恢复 ? / 不恢复'; + $("#e_tips_"+id).html(h); + } + setInterval(function() { + var d = new Date(); + var h = d.getHours(); + var m = d.getMinutes(); + var s = d.getSeconds(); + h = h < 10 ? '0' + h : h; + m = m < 10 ? '0' + m : m; + s = s < 10 ? '0' + s : s; + if(editor.getValue().trim() != ""){ + md_add_data("content",mdu,editor.getValue()); + var id1 = "#e_tip_"+id; + var id2 = "#e_tips_"+id; + + $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 "); + $(id2).html(""); + } + },10000); + + }else{ + $("#e_tip_"+id).after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!'); + } +} + + +function create_editorMD(id, width, high, placeholder, imageUrl, callback) { + var editorName = window.editormd(id, { + width: width, + height: high, + path: path, // "/editormd/lib/" + + syncScrolling: "single", + tex: true, + tocm: true, + emoji: true, + taskList: true, + codeFold: true, + searchReplace: true, + htmlDecode: "style,script,iframe", + sequenceDiagram: true, + autoFocus: false, + toolbarIcons: function () { + // Or return editormd.toolbarModes[name]; // full, simple, mini + // Using "||" set icons align right. + return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"] + }, + toolbarCustomIcons: { + testIcon: "
    ", + testIcon1: "
    " + }, + //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 + saveHTMLToTextarea: true, + // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 + dialogMaskOpacity: 0.6, + placeholder: placeholder, + imageUpload: true, + imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], + imageUploadURL: imageUrl,//url + onload: function () { + // this.previewing(); + $("#" + id + " [type=\"latex\"]").bind("click", function () { + editorName.cm.replaceSelection("```latex"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("```"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line - 1, 0); + }); + + $("#" + id + " [type=\"inline\"]").bind("click", function () { + editorName.cm.replaceSelection("$$$$"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line, __Cursor.ch - 2); + editorName.cm.focus(); + }); + $("[type=\"inline\"]").attr("title", "行内公式"); + $("[type=\"latex\"]").attr("title", "多行公式"); + + md_elocalStorage(editorName, `exercise__${id}`, "Memochallengesnew"); + + callback && callback() + } + }); + return editorName; +} + + +export default class TPMchallengesnew extends Component { + constructor(props) { + super(props) + this.state = { + choice_url: undefined, + practice_url: undefined, + go_back_url: undefined, + task_pass_default: undefined, + submit_url: undefined, + shixunCreatePracticeGroup: 1, + optionsums:[100,200], + activetype:0, + setopen: false, + shixunCreatePractice: undefined, + onshixunsmarkvalue: 100, + shixunsskillvalue: undefined, + shixunsskillvaluelist: [], + tab2url: "", + tab3url: "", + prev_challenge:undefined, + next_challenge:undefined, + power: false, + shixunCreatePracticetype: false, + shixunsskillvaluelisttype: false, + marktype:false, + editPracticesendtype:false, + CreatePracticesendtype:false, + exec_time:undefined + } + } + + + exerciseMD(initValue, id) { + + this.contentChanged = false; + const placeholder = ""; + // amp; + // 编辑时要传memoId + const imageUrl = `/api/attachments.json`; + // 创建editorMd + + const exercise_editormd = create_editorMD(id, '100%', 400, placeholder, imageUrl, () => { + setTimeout(() => { + exercise_editormd.resize() + exercise_editormd.cm && exercise_editormd.cm.refresh() + }, 500) + + if (initValue != undefined) { + exercise_editormd.setValue(initValue) + } + exercise_editormd.cm.on("change", (_cm, changeObj) => { + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + this.exercise_editormd = exercise_editormd; + window.exercise_editormd = exercise_editormd; + + } + + formatSearch = (url) => { + if (typeof url !== "undefined") { + url = url.substr(1); //从起始索引号提取字符串中指定数目的字符 + var arr = url.split("&"), //把字符串分割为字符串数组 + obj = {}, + newarr = []; + arr.forEach(function (v, i) { //数组遍历 + // console.log(v); + // console.log(i); + newarr = v.split("="); + if (typeof obj[newarr[0]] === "undefined") { + obj[newarr[0]] = newarr[1]; + } + }); + return obj; + } + ; + } + 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" + if(checkpointId===undefined){ + //新建模式 + let url = "/shixuns/" + id + "/challenges/new.json" + axios.get(url).then((response) => { + this.setState({ + choice_url: newchoice_url, + practice_url: newpractice_url, + go_back_url: newgo_back_url, + position: response.data.position, + task_pass_default: response.data.task_pass_default, + submit_url: response.data.submit_url, + checkpointId:checkpointId + }) + this.exerciseMD(response.data.task_pass_default, "exercisememoMD"); + }).catch((error) => { + console.log(error) + }); + }else{ + //编辑模式 + let url="/shixuns/"+id+"/challenges/"+checkpointId+".json?tab=0"; + axios.get(url).then((response) => { + + let optionsum; + if(response.data.difficulty===1){ + optionsum=[100,200]; + }else if(response.data.difficulty===2){ + optionsum=[300,400,500,600]; + }else if(response.data.difficulty===3){ + optionsum=[700,800,900,1000] + } + 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({ + power: response.data.power, + prev_challenge:newprev_challenge, + next_challenge:next_challenge, + choice_url: newchoice_url, + practice_url: newpractice_url, + go_back_url: newgo_back_url, + shixunCreatePractice:response.data.subject, + position:response.data.position, + shixunCreatePracticeGroup:response.data.difficulty, + optionsums:optionsum, + onshixunsmarkvalue:response.data.score, + shixunsskillvaluelist:response.data.tags, + checkpointId:checkpointId, + exec_time:response.data.exec_time, + tab2url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=2", + tab3url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=3", + }) + if(response.data.power===false){ + this.props.showSnackbar("你没有权限修改"); + } + this.exerciseMD(response.data.task_pass, "exercisememoMD"); + }).catch((error) => { + console.log(error) + }); + + } + + } + + onshixunCreatePracticeChange = (e) => { + let optionsum; + let onshixunsmark; + if(e.target.value===1){ + optionsum=[100,200]; + onshixunsmark=100; + }else if(e.target.value===2){ + optionsum=[300,400,500,600]; + onshixunsmark=300; + }else if(e.target.value===3){ + optionsum=[700,800,900,1000] + onshixunsmark=700; + } + this.setState({ + shixunCreatePracticeGroup: e.target.value, + optionsums:optionsum, + onshixunsmarkvalue:onshixunsmark + }) + } + + shixunCreatePractice = (e) => { + this.setState({ + shixunCreatePractice: e.target.value + }) + } + + CreatePracticesend = () => { + this.setState({ + CreatePracticesendtype:true + }) + + if(this.props.status===2){ + this.props.showSnackbar("该实训已经发布不能新建") + this.setState({ + CreatePracticesendtype:false + }) + return + } + let {shixunCreatePractice, shixunCreatePracticeGroup, onshixunsmarkvalue, shixunsskillvaluelist,exec_time} = this.state; + if (shixunCreatePractice === undefined||shixunCreatePractice=="") { + this.setState({ + shixunCreatePracticetype: true + }) + this.props.showSnackbar("任务名称为空") + $('html').animate({ + scrollTop: 10 + }, 1000); + + this.setState({ + CreatePracticesendtype:false + }) + return + } + + if (shixunsskillvaluelist.length === 0) { + this.setState({ + shixunsskillvaluelisttype: true, + CreatePracticesendtype:false + }) + this.props.showSnackbar("技能标签为空") + return + } + + const exercise_editormdvalue = this.exercise_editormd.getValue(); + + let id = this.props.match.params.shixunId; + + let url = "/shixuns/" + id + "/challenges.json"; + + axios.post(url, { + identifier:id, + subject: shixunCreatePractice, + task_pass: exercise_editormdvalue, + difficulty: shixunCreatePracticeGroup, + score: onshixunsmarkvalue, + challenge_tag: shixunsskillvaluelist, + st: 0, + exec_time:exec_time + }).then((response) => { + this.props.showSnackbar(response.data.messages); + if (response.data.status === 1) { + this.setState({ + setopen: true, + tab2url: "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=2", + tab3url: "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=3", + }) + // window.location.href = "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=2" + } + + }).catch((error) => { + console.log(error) + }); + + + + } + + onshixunsmark = (value) => { + this.setState({ + onshixunsmarkvalue: value + }) + } + + shixunsskill = (e) => { + this.setState({ + shixunsskillvalue: e.target.value + }) + } + + clickshixunsskill = () => { + + let {shixunsskillvalue, shixunsskillvaluelist} = this.state; + if (shixunsskillvalue === "") { + return + } else if (shixunsskillvalue === undefined) { + return + } + + if(shixunsskillvalue == "" || shixunsskillvalue == undefined || shixunsskillvalue == null || (shixunsskillvalue.length>0 && shixunsskillvalue.trim().length == 0)){ + message.error("输入为空,不能保存!"); + return + } + + let list = shixunsskillvaluelist; + list.push(shixunsskillvalue); + this.setState({ + shixunsskillvaluelist: list, + shixunsskillvalue: "" + }) + } + + delshixunsskilllist = (key) => { + let {shixunsskillvaluelist} = this.state; + let newshixunsskillvaluelist = shixunsskillvaluelist; + newshixunsskillvaluelist.splice(key, 1); + this.setState({ + shixunsskillvaluelist: newshixunsskillvaluelist + }) + } + + editPracticesend=()=>{ + + this.setState({ + editPracticesendtype:true + }) + + let {shixunCreatePractice, shixunCreatePracticeGroup, onshixunsmarkvalue, shixunsskillvaluelist,checkpointId,exec_time} = this.state; + + const exercise_editormdvalue = this.exercise_editormd.getValue(); + + let id = this.props.match.params.shixunId; + + let url = "/shixuns/"+id+"/challenges/"+checkpointId+".json"; + + if (shixunCreatePractice === undefined||shixunCreatePractice=="") { + // this.setState({ + // shixunCreatePracticetype: true + // }) + this.props.showSnackbar("任务名称为空") + $('html').animate({ + scrollTop: 10 + }, 1000); + this.setState({ + editPracticesendtype:false + }) + return + } + + if (shixunsskillvaluelist.length === 0) { + // this.setState({ + // shixunsskillvaluelisttype: true + // }) + this.props.showSnackbar("技能标签为空") + this.setState({ + editPracticesendtype:false + }) + return + } + axios.put(url, { + tab:0, + identifier:id, + id:checkpointId, + challenge:{ + subject: shixunCreatePractice, + task_pass: exercise_editormdvalue, + difficulty: shixunCreatePracticeGroup, + score: onshixunsmarkvalue, + exec_time:exec_time + }, + challenge_tag:shixunsskillvaluelist + }).then((response) => { + this.props.showSnackbar(response.data.messages); + if (response.data.status === 1) { + this.setState({ + setopen: true, + tab2url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=2", + tab3url: "/shixuns/" + id + "/challenges/"+checkpointId+"/tab=3", + }) + // window.location.href = "/shixuns/" + id + "/challenges/"+response.data.challenge_id+"/tab=2" + } + }).catch((error) => { + console.log(error) + }); + + + } + + onshixunsmarks=()=> { + this.setState({ + marktype:true + }) + } + + onshixunsmarkss=()=> { + this.setState({ + marktype:false + }) + } + + setexec_time=(e)=>{ + this.setState({ + exec_time:e.target.value + }) + } + render() { + + let shixuntype = this.props.match.params.type; + + + let {marktype, + shixunCreatePracticetype, shixunsskillvaluelisttype, + choice_url, practice_url, go_back_url, position, task_pass_default, submit_url, setopen,checkpointId,prev_challenge,next_challenge,power, + shixunCreatePractice, shixunCreatePracticeGroup, onshixunsmarkvalue, shixunsskillvalue, shixunsskillvaluelist, tab2url, tab3url,optionsums, + CreatePracticesendtype,editPracticesendtype + } = this.state; + + let options; + options = optionsums.map((d, k) => { + return ( + + ) + }) + + return ( + +
    +
    + + + + 第{position}关 + + 返回 + + { prev_challenge===undefined?"": + 上一关 + } + + { next_challenge===undefined?"": + 下一关 + } + + + 3||this.props.identity===undefined||this.props.status===2||this.props.status===1?"none":'block'}} + data-tip-down="新增代码编辑类型的任务">+ 实践类型 + + 3||this.props.identity===undefined||this.props.status===2||this.props.status===1?"none":'block'}} + data-tip-down="新增选择题类型的任务">+ 选择题类型 + +
    + +
    + +
  • + 本关任务 +
  • + +
  • + {tab2url === "" ? 评测设置 : 评测设置} +
  • + +
  • + {tab3url === "" ? 参考答案 : 参考答案} + +
  • +
    + +
    +
    +

    任务名称

    +
    + * +
    + +
    +
    + 必填项 +
    +
    +
    +
    + + +
    + +

    过关任务

    + +
    + +
    +
    +
    +

    +

    +
    + + +
    +

    难度系数

    +
    + + + 简单 + 中等 + 困难 + + +
    +

    奖励经验值

    +
    + * + + + + +

    + 如果学员答题错误,则不能得到相应的经验值
    + 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币 +

    + + 必填项 +
    +
    + + +
    +

    技能标签

    +
    + * +
    + + {/*+ 添加*/} +
    学员答题正确将获得技能,否则不能获得技能
    +
    + + { + shixunsskillvaluelist.length === 0 ? "" : shixunsskillvaluelist.map((itme, key) => { + return ( +
  • {itme} + this.delshixunsskilllist(key)}>× +
  • + ) + }) + } + + +
    +
    + + 必填项 +
    +
    + +
    +

    服务配置

    +
    + +
    + +
    +
    +
    +
    + +
    3||this.props.identity===undefined?"none":'block'}} + > + {checkpointId===undefined?提交: + 提交} + 取消 +
    +
    +
    + ) + } +} + + diff --git a/public/react/src/modules/tpm/challengesnew/TPMevaluation.js b/public/react/src/modules/tpm/challengesnew/TPMevaluation.js index 00141188f..ccd34f1ee 100644 --- a/public/react/src/modules/tpm/challengesnew/TPMevaluation.js +++ b/public/react/src/modules/tpm/challengesnew/TPMevaluation.js @@ -765,14 +765,14 @@ export default class TPMevaluation extends Component { 第{position}关 返回 + className="color-grey-6 fr font-15 mt3">返回 {prev_challenge === undefined ? "" : - 上一关 + 上一关 } {next_challenge === undefined ? "" : - 下一关 + 下一关 } 恢复 ? / 不恢复'; - $("#e_tips_"+id).html(h); - } - setInterval(function() { - var d = new Date(); - var h = d.getHours(); - var m = d.getMinutes(); - var s = d.getSeconds(); - h = h < 10 ? '0' + h : h; - m = m < 10 ? '0' + m : m; - s = s < 10 ? '0' + s : s; - if(editor.getValue().trim() != ""){ - md_add_data("content",mdu,editor.getValue()); - var id1 = "#e_tip_"+id; - var id2 = "#e_tips_"+id; - - $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 "); - $(id2).html(""); - } - },10000); - - }else{ - $("#e_tip_"+id).after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!'); - } -} - -function create_editorMD(id, width, high, placeholder, imageUrl,initValue, callback) { - var editorName = window.editormd(id, { - width: width, - height: high, - path: path, // "/editormd/lib/" - markdown : initValue, - syncScrolling: "single", - tex: true, - tocm: true, - emoji: true, - taskList: true, - codeFold: true, - searchReplace: true, - htmlDecode: "style,script,iframe", - sequenceDiagram: true, - autoFocus: false, - placeholder: placeholder, - toolbarIcons: function () { - // Or return editormd.toolbarModes[name]; // full, simple, mini - // Using "||" set icons align right. - return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"] - }, - toolbarCustomIcons: { - testIcon: "
    ", - testIcon1: "
    " - }, - //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 - saveHTMLToTextarea: true, - // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 - dialogMaskOpacity: 0.6, - imageUpload: true, - imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], - imageUploadURL: imageUrl,//url - onload: function () { - // this.previewing(); - $("#" + id + " [type=\"latex\"]").bind("click", function () { - editorName.cm.replaceSelection("```latex"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("```"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line - 1, 0); - }); - - $("#" + id + " [type=\"inline\"]").bind("click", function () { - editorName.cm.replaceSelection("$$$$"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line, __Cursor.ch - 2); - editorName.cm.focus(); - }); - $("[type=\"inline\"]").attr("title", "行内公式"); - $("[type=\"latex\"]").attr("title", "多行公式"); - - callback && callback() - } - }); - return editorName; -} - - -export default class TPMquestion extends Component { - constructor(props) { - super(props) - this.state = { - choice_url: undefined, - practice_url: undefined, - go_back_url: undefined, - position: undefined, - task_pass_default: undefined, - submit_url: undefined, - questionInputvalue:undefined, - questionaddsum:0, - questionaddarray:[], - questionaddtype:true, - activetype:"", - questionlists:[{str:"A",val:"",type:false},{str:"B",val:"",type:false},{str:"C",val:"",type:false},{str:"D",val:"",type:false}], - answeshixunsGroup: 1, - answeoptions:[10,20], - answeonshixunsmark:10, - shixunssanswerkillvalue:"", - shixunsskillanswerlist:[], - challenge_id:"", - challenge_choose_id:undefined, - questionlistss:[], - newcnttype:false, - newquestioMDvaluetype:false, - challenge_tagtype:false, - editquestionaddtype:false, - mancheckpointId:undefined, - power:false, - questionInputvaluetype:false, - questioMD:"", - standard_answer:"", - subject:"", - newquestioMDvaluetypes:false, - questionInputvaluetypes:false, - prev_challenge:undefined, - next_challenge:undefined, - newcnttypesum:1, - marktype:false, - answer:"", - sumittype:false - } - } -questioMD=(initValue, id)=> { - - this.contentChanged = false; - const placeholder = "请输入选择题的过关任务内容"; -// amp; -// 编辑时要传memoId - // const imageUrl = `/upload_with_markdown?container_id=&container_type=Memo`; - const imageUrl = `/api/attachments.json`; -// 创建editorMd - - let questio_editormd = create_editorMD(id, '100%', 400, placeholder, imageUrl, initValue,() => { - setTimeout(() => { - questio_editormd.resize() - questio_editormd.cm && questio_editormd.cm.refresh() - }, 500) - - if (initValue != undefined) { - questio_editormd.setValue(initValue) - } - questio_editormd.cm.on("change", (_cm, changeObj) => { - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - md_elocalStorage(questio_editormd, `MemoQuestion_${id}`, `${id}Question`); - this.questio_editormd = questio_editormd; - window.questio_editormd = questio_editormd; - -} - -newanswerMD=(initValue, id)=> { - - this.contentChanged = false; -// amp; -// 编辑时要传memoId - const imageUrl = `/api/attachments.json`; -// 创建editorMd - - let newanswerMD_editormd = create_editorMD(id, '100%', 400, "请输入各个选项的具体解析或其他相关信息", imageUrl, initValue,() => { - setTimeout(() => { - newanswerMD_editormd.resize() - newanswerMD_editormd.cm && newanswerMD_editormd.cm.refresh() - }, 500) - - if (initValue != undefined) { - newanswerMD_editormd.setValue(initValue) - } - newanswerMD_editormd.cm.on("change", (_cm, changeObj) => { - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - - md_elocalStorage(newanswerMD_editormd, `MemoQuestion_${id}`, `${id}Question`); - - this.newanswerMD_editormd = newanswerMD_editormd; - window.newanswerMD_editormd = newanswerMD_editormd; - -} - -newquestioMD=(initValue, id)=>{ - this.contentChanged = false; -// amp; -// 编辑时要传memoId - const imageUrl = `/api/attachments.json`; -// 创建editorMd - - let newquestioMD_editormd = create_editorMD(id, '100%', 400, "请输入选择题的题干内容", imageUrl, initValue,() => { - setTimeout(() => { - newquestioMD_editormd.resize() - newquestioMD_editormd.cm && newquestioMD_editormd.cm.refresh() - }, 500) - - if (initValue != undefined) { - newquestioMD_editormd.setValue(initValue) - } - newquestioMD_editormd.cm.on("change", (_cm, changeObj) => { - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - md_elocalStorage(newquestioMD_editormd, `MemoQuestion_${id}`, `${id}Question`); - this.newquestioMD_editormd = newquestioMD_editormd; - window.newquestioMD_editormd = newquestioMD_editormd; - -} - -editanswerMD=(initValue, id)=> { - - this.contentChanged = false; - const placeholder = ""; -// amp; -// 编辑时要传memoId - const imageUrl = `/api/attachments.json`; -// 创建editorMd - - const neweditanswer_editormd =create_editorMD(id, '100%', 400, "请输入选择题的题干内容", imageUrl, initValue,()=> { - setTimeout(() => { - neweditanswer_editormd.resize() - neweditanswer_editormd.cm && neweditanswer_editormd.cm.refresh() - }, 500) - - if (initValue != undefined) { - neweditanswer_editormd.setValue(initValue) - } - neweditanswer_editormd.cm.on("change", (_cm, changeObj) => { - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - md_elocalStorage(neweditanswer_editormd, `MemoQuestion_${id}`, `${id}Question`); - this.neweditanswer_editormd = neweditanswer_editormd; - window.neweditanswer_editormd = neweditanswer_editormd; - -} - -editanswersMD=(initValue, id)=> { - - this.contentChanged = false; - const placeholder = ""; -// amp; -// 编辑时要传memoId - const imageUrl = `/api/attachments.json`; -// 创建editorMd - - const editanswersMD_editormd = create_editorMD(id, '100%', 400, "请输入各个选项的具体解析或其他相关信息", imageUrl, initValue,() => { - setTimeout(() => { - editanswersMD_editormd.resize() - editanswersMD_editormd.cm && editanswersMD_editormd.cm.refresh() - }, 500) - - if (initValue != undefined) { - editanswersMD_editormd.setValue(initValue) - } - editanswersMD_editormd.cm.on("change", (_cm, changeObj) => { - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - md_elocalStorage(editanswersMD_editormd, `MemoQuestion_${id}`, `${id}Question`); - this.editanswersMD_editormd = editanswersMD_editormd; - window.editanswersMD_editormd = editanswersMD_editormd; - -} - - //_______________________________________________________________________________ - questionInputvalue=(e)=>{ - this.setState({ - questionInputvalue: e.target.value - }) - } - componentDidMount() { - if(this.props.status===2){ - - } - let id = this.props.match.params.shixunId; - let checkpointId=this.props.match.params.checkpointId; - - this.setState({ - mancheckpointId:id, - }) - - let newchoice_url= "/shixuns/"+id+"/challenges/newquestion"; - let newpractice_url= "/shixuns/"+id+"/challenges/new"; - let newgo_back_url="/shixuns/"+id+"/challenges"; - - if(this.props.match.params.choose_id===undefined){ - if(checkpointId===undefined){ - //新建模式 - let nurl = "/shixuns/" + id + "/challenges/new.json" - axios.get(nurl).then((response) => { - - if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { - - }else { - this.setState({ - choice_url: newchoice_url, - practice_url: newpractice_url, - go_back_url: newgo_back_url, - position: response.data.position, - task_pass_default: response.data.task_pass_default, - submit_url: response.data.submit_url, - power:true, - activetype:"first", - - }) - if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { - this.questioMD("", "questioMD"); - - this.setState({ - questioMD:"" - }) - } else { - this.questioMD("", "questioMD"); - - // this.create_mackdown(response.data.task_pass_default, "questioMD","") - this.setState({ - questioMD:response.data.task_pass_default - }) - } - this.shixunsautoHeight() - } - - }).catch((error) => { - console.log(error) - }); - - }else{ - //编辑模式 - let url = "/shixuns/"+ id +"/challenges/"+checkpointId+"/edit.json?st=1" - axios.get(url).then((response) => { - // if(choose_idlist!=undefined){ - // - // for(var i=0; i { - console.log(error) - }); - } - - }else{ - $('html').animate({ - scrollTop:10 - }, 500); - - let{challenge_id} =this.state; - - let id = this.props.match.params.shixunId; - let url = "/shixuns/"+ id +"/challenges/"+checkpointId+"/edit.json?st=1" - axios.get(url).then((response) => { - // if(choose_idlist!=undefined){ - // - // for(var i=0; i { - console.log(error) - }); - - let zrl ='/shixuns/'+this.props.match.params.shixunId+'/challenges/'+this.props.match.params.checkpointId+'/edit_choose_question.json?choose_id='+this.props.match.params.choose_id; - axios.get(zrl).then((response) => { - if(response.status===200){ - let choose_contents=response.data.choose_contents; - let newchoose_contentslist=[] - for(var i=0; i { - }); - - } - } - - clickquestionsumit=()=>{ - this.setState({ - sumittype:true - }) - let checkpointId=this.props.match.params.checkpointId; - if(this.props.status===2&&checkpointId===undefined){ - this.props.showSnackbar("该实训已经发布不能新建") - this.setState({ - sumittype:false - }) - return - } - let {questionInputvalue} =this.state; - const exercise_editormdvalue = this.questio_editormd.getValue(); - let id = this.props.match.params.shixunId; - - if(questionInputvalue===undefined||questionInputvalue===null||questionInputvalue===""){ - this.setState({ - questionInputvaluetype:true - }) - $('html').animate({ - scrollTop: 10 - }, 1000); - this.setState({ - sumittype:false - }) - return - } - - - if(exercise_editormdvalue===null ||exercise_editormdvalue===""){ - this.setState({ - questionInputvaluetypes:true - }) - $('html').animate({ - scrollTop: 500 - }, 1000); - this.setState({ - sumittype:false - }) - return - } - if(checkpointId===undefined){ - - let url = "/shixuns/" + id + "/challenges.json"; - - axios.post(url, { - identifier:id, - subject: questionInputvalue, - task_pass: exercise_editormdvalue, - st: 1 - }).then((response) => { - this.props.showSnackbar(response.data.messages); - // if(response.data.status===1){ - // - // this.setState({ - // questionaddtype:false, - // challenge_id:response.data.challenge_id - // }) - // - // this.questionadd() - // } - window.location.href = '/shixuns/'+id+'/challenges/'+response.data.challenge_id+'/editquestion'; - - }).catch((error) => { - console.log(error) - }); - }else{ - let url ="/shixuns/"+id+"/challenges/"+checkpointId+".json"; - axios.put(url, { - tab:0, - subject: questionInputvalue, - task_pass: exercise_editormdvalue, - }).then((response) => { - if(response.data.status===1){ - this.setState({ - questionaddtype:false, - challenge_id:response.data.challenge_id - }) - } - $('html').animate({ - scrollTop: 10 - }, 200); - this.props.showSnackbar(response.data.messages); - window.location.href = '/shixuns/'+id+'/challenges/'+response.data.challenge_id+'/editquestion'; - }).catch((error) => { - console.log(error) - }); - } - - } - - questionall=()=>{ - let {task_pass_default}=this.state; - this.setState({ - activetype:"first", - newquestionaddtype:false, - editquestionaddtype:false - }) - this.questioMD(task_pass_default, "questioMD"); - } - questionadd=()=>{ - $('html').animate({ - scrollTop: 10 - }, 200); - let{questionaddarray}=this.state; - - let questionaddsums=questionaddarray.length; - - if(questionaddarray.length-1>9){ - return - } - - let questionaddarrays=questionaddarray; - questionaddarrays.push({type:0,choose_id:0}); - this.setState({ - activetype:0, - questionaddarray:questionaddarrays, - questionaddtype:true, - newquestionaddtype:true, - editquestionaddtype:false, - questionlists:[{str:"A",val:"",type:false},{str:"B",val:"",type:false},{str:"C",val:"",type:false},{str:"D",val:"",type:false}], - answeshixunsGroup: 1, - answeoptions:[10,20], - answeonshixunsmark:10, - shixunssanswerkillvalue:"", - shixunsskillanswerlist:[] - }) - - this.newanswerMD("","challenge_choose_answer") - this.newquestioMD("","newquestioMDs") - // this.create_mackdown("", "newquestioMDs","请输入选择题的题干内容","newanswerMD_editormd") - // this.create_mackdown("", "challenge_choose_answer","请输入各个选项的具体解析或其他相关信息","newquestioMD_editormd") - this.shixunsautoHeight() - } - - editquestionlists=(newquestionlists)=>{ - let newlist=newquestionlists; - let list=[] - for(var i=0; i{ - let{questionlists} = this.state; - let newquestionlists=questionlists; - let newli={str:letterArr[questionlists.length],val:"",type:false}; - newquestionlists.push(newli); - this.editquestionlists(newquestionlists); - } - - - delquestionlists=(key)=>{ - let{questionlists} = this.state; - let newquestionlists=questionlists; - newquestionlists.splice(key,1); - for(var i=0; i{ - let{questionlists} = this.state; - let newquestionlists=questionlists; - if(newquestionlists[key].type===true){ - newquestionlists[key].type=false; - }else if(newquestionlists[key].type===false){ - newquestionlists[key].type=true; - } - - this.editquestionlists(newquestionlists); - } - - onshixunGroupanswe=(e)=> { - let optionsum; - let onshixunsmark; - if(e.target.value===1){ - optionsum=[10,20]; - onshixunsmark=10; - }else if(e.target.value===2){ - optionsum=[30,40,50,60]; - onshixunsmark=30; - }else if(e.target.value===3){ - optionsum=[70,80,90,100] - onshixunsmark=70; - } - this.setState({ - answeshixunsGroup: e.target.value, - answeoptions:optionsum, - answeonshixunsmark:onshixunsmark - }) - } - shixunssanswerkill = (e) => { - this.setState({ - shixunssanswerkillvalue: e.target.value - }) - - } - clickshixunsanswerskill = () => { - - let {shixunssanswerkillvalue, shixunsskillanswerlist} = this.state; - if (shixunssanswerkillvalue === "") { - return - } else if (shixunssanswerkillvalue === undefined) { - return - } - - if(shixunssanswerkillvalue == "" || shixunssanswerkillvalue == undefined || shixunssanswerkillvalue == null || (shixunssanswerkillvalue.length>0 && shixunssanswerkillvalue.trim().length == 0)){ - message.error("输入为空,不能保存!"); - return - } - - let list = shixunsskillanswerlist; - list.push(shixunssanswerkillvalue); - this.setState({ - shixunsskillanswerlist: list, - shixunssanswerkillvalue: "" - }) - } - delshixunssnswerllist=(key)=>{ - let {shixunsskillanswerlist} = this.state; - let newshixunsskillanswerlist = shixunsskillanswerlist; - newshixunsskillanswerlist.splice(key, 1); - this.setState({ - shixunsskillanswerlist: newshixunsskillanswerlist - }) - } - onInputoquestionption=(e,key)=>{ - - $.fn.autoHeight = function(){ - function autoHeight(elem){ - elem.style.height = 'auto'; - elem.style.maxHeight = '140px'; - elem.scrollTop = 0; //防抖动 - elem.style.height = elem.scrollHeight + 'px'; - } - this.each(function(){ - autoHeight(this); - $(this).on('keyup', function(){ - autoHeight(this); - }); - }); - } - $("#"+e.target.id).autoHeight(); - - let {questionlists}=this.state; - let newquestionlists=questionlists; - newquestionlists[key].val=e.target.value; - this.editquestionlists(newquestionlists); - } - - onshixunsansweSelect=(value)=>{ - this.setState({ - answeonshixunsmark: value - }) - } - - answer_subit=(sumtype,challenge_choose_id)=>{ - - let {challenge_id,questionlists,shixunsskillanswerlist,answeonshixunsmark,answeshixunsGroup,questionaddarray} =this.state; - if(challenge_id===undefined){ - message.error("关卡id为空"); - return - } - let newquestionlists=questionlists; - let newlist=""; - let newtype=[]; - let newcnt=[]; - let list=0; - for(var i=0; i { - console.log(error) - }); - }else{ - let newquestioMDvalue = this.newquestioMD_editormd.getValue(); - - if(newquestioMDvalue===""||newquestioMDvalue==="请输入选择题的题干内容"){ - this.setState({ - newquestioMDvaluetype:true, - }) - $('html').animate({ - scrollTop:100 - }, 200); - message.error("题干为空"); - return - } - let newnewanswerMDvalue = this.newanswerMD_editormd.getValue(); - // - // if(newnewanswerMDvalue===""||newnewanswerMDvalue==="请输入选择题的题干内容"){ - // this.setState({ - // newquestioMDvaluetypes:true, - // }) - // - // $('html').animate({ - // scrollTop:1300 - // }, 200); - // this.props.showSnackbar("参考答案为空"); - // return - // } - if(newnewanswerMDvalue===""||newnewanswerMDvalue===" "){ - newnewanswerMDvalue=newlist - } - url="/shixuns/" + id + "/challenges/" + challenge_id + "/create_choose_question.json"; - axios.post(url, { - challenge_choose: {subject: newquestioMDvalue, answer: newnewanswerMDvalue, standard_answer:newlist , score: answeonshixunsmark, difficult: answeshixunsGroup}, - challenge_tag: shixunsskillanswerlist, - question: {cnt: newcnt}, - choice: {answer: newtype} - }).then((response) => { - - let questionaddsums=questionaddarray.length; - let questionaddarrays=questionaddarray; - questionaddarrays[questionaddsums-1].choose_id=response.data.challenge_choose_id; - if(newlist.length===1){ - questionaddarrays[questionaddsums-1].type=1; - }else if(newlist.length>1){ - questionaddarrays[questionaddsums-1].type=2; - } - this.setState({ - challenge_choose_id:response.data.challenge_choose_id, - questionaddtype:false, - editquestionaddtype:false, - newquestioMDvaluetype:false, - newquestioMDvaluetypes:false, - questionaddarray:questionaddarrays - }) - // $('html').animate({ - // scrollTop: 10 - // }, 200); - message.success("新建成功"); - // this.getanswer_subitlist() - this.gochooseid("/shixuns/"+this.props.match.params.shixunId+"/challenges/"+this.props.match.params.checkpointId+"/editquestion"+"/"+response.data.challenge_choose_id) - }).catch((error) => { - console.log(error) - }); - } - - - } - - // getanswer_subitlist=()=>{ - // let{challenge_choose_id,challenge_id,questionaddarray} =this.state - // let id = this.props.match.params.shixunId; - // let url ='/shixuns/'+id+'/challenges/'+challenge_id+'/edit_choose_question.json?choose_id='+challenge_choose_id; - // axios.get(url).then((response) => { - // if(response.status===200){ - // this.create_mackdown(response.data.subject, "neweditanswer","","neweditanswer_editormd") - // this.create_mackdown(response.data.standard_answer, "editanswers","","editanswersMD_editormd") - // let choose_contents=response.data.choose_contents; - // let newchoose_contentslist=[] - // for(var i=0; i { - // }); - // } - - questionlist=(key,challenge_choose_id,type)=>{ - - $('html').animate({ - scrollTop:10 - }, 500); - - let{challenge_id} =this.state; - - if(challenge_choose_id===""||type===0){ - - this.newanswerMD("","neweditanswer") - this.editanswersMD("","editanswers") - this.setState({ - activetype:challenge_choose_id, - editquestionaddtype:true, - questionaddtype:true, - newquestionaddtype:false, - questionlists:[{str:"A",val:"",type:false},{str:"B",val:"",type:false},{str:"C",val:"",type:false},{str:"D",val:"",type:false}], - answeshixunsGroup: 1, - answeoptions:[10,20], - answeonshixunsmark:10, - shixunssanswerkillvalue:"", - shixunsskillanswerlist:[] - }) - - // this.create_mackdown("", "newquestioMDs","请输入选择题的题干内容","newanswerMD_editormd") - // this.create_mackdown("", "challenge_choose_answer","请输入各个选项的具体解析或其他相关信息","newquestioMD_editormd") - - }else{ - let id = this.props.match.params.shixunId; - let url ='/shixuns/'+id+'/challenges/'+challenge_id+'/edit_choose_question.json?choose_id='+challenge_choose_id; - axios.get(url).then((response) => { - if(response.status===200){ - let choose_contents=response.data.choose_contents; - let newchoose_contentslist=[] - for(var i=0; i { - }); - - } - - } - - shixunsautoHeight=()=>{ - $.fn.autoHeight = function(){ - function autoHeight(elem){ - elem.style.height = 'auto'; - elem.style.maxHeight = '140px'; - elem.scrollTop = 0; //防抖动 - if(elem.scrollHeight===0){ - elem.style.height = 62 + 'px'; - }else{ - // if(elem.style.height>140){ - // - // } - elem.style.height = elem.scrollHeight + 'px'; - } - - } - this.each(function(){ - autoHeight(this); - $(this).on('keyup', function(){ - autoHeight(this); - }); - }); - } - $('textarea[autoHeight]').autoHeight(); - } - - gochooseid=(url)=>{ - window.location.href =url - } - onshixunsmarks=()=> { - this.setState({ - marktype:true - }) - } - - onshixunsmarkss=()=> { - this.setState({ - marktype:false - }) - } - render() { - - let {choice_url, - practice_url, - go_back_url, - position, - questionInputvalue, - challenge_tagtype, - questionInputvaluetype, - answeshixunsGroup, - answeoptions, - answeonshixunsmark, - shixunssanswerkillvalue, - questionlistss,power, - questionaddarray, - questionaddtype, - activetype, - newquestionaddtype, - newquestioMDvaluetype, - editquestionaddtype, - questionlists, - shixunsskillanswerlist, - newcnttype, - challenge_choose_id, - mancheckpointId, - challenge_id, - questioMD, - standard_answer, - subject, - newquestioMDvaluetypes, - questionInputvaluetypes, - prev_challenge, - next_challenge, - newcnttypesum, - marktype, - answer, - sumittype - } = this.state; - - let options; - - - options = answeoptions.map((d, k) => { - return ( - - ) - }) - console.log(answer) - return ( - -
    - - -
    - -
  • - 本关任务 -
  • - - { - questionaddarray.length===0?"":questionaddarray.map((item,key)=>{ - return( -
  • this.questionlist(key,item.choose_id,item.type):""} - > - - { - item.choose_id!=0? - this.gochooseid("/shixuns/"+this.props.match.params.shixunId+"/challenges/"+this.props.match.params.checkpointId+"/editquestion"+"/"+item.choose_id)}> - {key+1}.{item.type===2?"多选题":item.type===1?"单选题":'选择题'} - :{key+1}.{item.type===2?"多选题":item.type===1?"单选题":'选择题'} - } - -
  • - ) - }) - } - - -
  • - - + - -
  • - -
    - -
    - -
    -
    -

    任务名称

    -
    - * -
    - -
    -
    - 必填项 -
    -
    -
    -
    - - -
    -

    过关任务

    -
    - * -
    -
    - -
    -
    -
    - {/**/} -
    -
    - 必填项 -
    -
    -

    -

    -
    - - -
    3||this.props.identity===undefined||power===false?"none":"block"}}> - 提交 - 取消 - -
    - -
    - - - {/*新建*/} - - {newquestionaddtype===true?
    - -
    -
    -

    题干

    -
    - * -
    -
    - {/**/} - {/*
    */} - {/*
    */} - {/**/} -
    - -
    - - -
    - 必填项 -
    - -
    -

    -

    - - -
    - { - questionlists===undefined||questionlists.length===0?"":questionlists.map((item,key)=>{ - return( -
  • - - - this.delquestionlists(key)}> - - - - - -
  • - ) - }) - } -

    - 新增选项 - - - {newcnttypesum===0?"请选择答案":"选项内容不能为空"} - -

    -
  • - - -
  • -
    -
    -
    - - -
    -
    -

    参考答案

    -
    -
    - {/**/} - {/*
    */} - {/*
    */} -
    - -
    - 必填项 -
    -
    -

    -

    - -
    -
    - -
    -

    难度系数

    -
    - - - 简单 - 中等 - 困难 - - -
    -

    奖励经验值

    -
    - * - - - -

    - 如果学员答题错误,则不能得到相应的经验值
    - 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币 -

    - - 必填项 -
    -
    - -
    -

    技能标签

    -
    - * -
    - - {/*+ 添加*/} -
    学员答题正确将获得技能,否则不能获得技能 - - 必填项 - -
    -
    - - { - shixunsskillanswerlist.length === 0 ? "" : shixunsskillanswerlist.map((itme, key) => { - return ( -
  • {itme} - this.delshixunssnswerllist(key)}>× -
  • - ) - }) - } - - -
    - -
    - -
    -
    - - -
    3||this.props.identity===undefined||power===false?"none":"block"}}> - 提交 - 取消 -
    - -
    :""} - - - {/*修改*/} - {editquestionaddtype===true?
    - -
    -
    -

    题干

    -
    - * -
    -
    - -
    -
    -
    -
    - - -
    - 必填项 -
    - -
    -

    -

    -
    - { - questionlists===undefined||questionlists.length===0?"":questionlists.map((item,key)=>{ - return( -
  • - - - this.delquestionlists(key)}> - - -
  • - ) - }) - } -

    - 新增选项 - - - {newcnttypesum===0?"请选择答案":"选项内容不能为空"} - -

    -
  • - - -
  • -
    -
    -
    - - -
    -
    -

    参考答案

    -
    -
    - {/**/} - {/*
    */} - {/*
    */} -
    -
    - 必填项 -
    -
    -

    -

    -
    -
    - -
    -

    难度系数

    -
    - - - 简单 - 中等 - 困难 - - -
    -

    奖励经验值

    -
    - * - - - -

    - 如果学员答题错误,则不能得到相应的经验值
    - 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币 -

    - - 必填项 -
    -
    - -
    -

    技能标签

    -
    - * -
    - - {/*+ 添加*/} -
    学员答题正确将获得技能,否则不能获得技能 - - 必填项 - -
    -
    - - { - shixunsskillanswerlist.length === 0 ? "" : shixunsskillanswerlist.map((itme, key) => { - return ( -
  • {itme} - this.delshixunssnswerllist(key)}>× -
  • - ) - }) - } - - -
    - -
    - -
    -
    - - -
    3||this.props.identity===undefined||power===false?"none":"block"}}> - this.answer_subit("edit",challenge_choose_id)}>提交 - 取消 -
    - -
    - :""} - -
    -
    - ) - } -} - - +import React, {Component} from 'react'; + +import {Input, 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 axios from 'axios'; + +import { getImageUrl, toPath } from 'educoder'; + +import './css/TPMchallengesnew.css'; + +import {getUrl} from 'educoder'; + +import TPMeditorMD from './editorMD'; + +let origin = getUrl(); + +let path = getUrl("/editormd/lib/") + +const $ = window.$; + +const Option = Select.Option; + +const RadioGroup = Radio.Group; + +var letterArr = []; +for (var i = 65, j = 0; i < 91; i++, j++) { + letterArr[j] = String.fromCharCode(i); +} + +// 恢复数据 +function md_rec_data(k,mdu,id, editor){ + if(window.sessionStorage.getItem(k+mdu) !== null){ + editor.setValue(window.sessionStorage.getItem(k+mdu)); + md_clear_data(k,mdu,id); + } +} + +// 保存数据 +function md_add_data(k,mdu,d){ + window.sessionStorage.setItem(k+mdu,d); +} + +// 清空保存的数据 +function md_clear_data(k,mdu,id){ + window.sessionStorage.removeItem(k+mdu); + var id1 = "#e_tip_"+id; + var id2 = "#e_tips_"+id; + if(k == 'content'){ + $(id2).html(""); + }else{ + $(id1).html(""); + } +} + +function md_elocalStorage(editor,mdu,id){ + + if (window.sessionStorage){ + var oc = window.sessionStorage.getItem('content'+mdu); + if(oc !== null ){ + // console.log("#e_tips_"+id) + $("#e_tips_"+id).data('editor', editor); + var h = '您上次有已保存的数据,是否恢复 ? / 不恢复'; + $("#e_tips_"+id).html(h); + } + setInterval(function() { + var d = new Date(); + var h = d.getHours(); + var m = d.getMinutes(); + var s = d.getSeconds(); + h = h < 10 ? '0' + h : h; + m = m < 10 ? '0' + m : m; + s = s < 10 ? '0' + s : s; + if(editor.getValue().trim() != ""){ + md_add_data("content",mdu,editor.getValue()); + var id1 = "#e_tip_"+id; + var id2 = "#e_tips_"+id; + + $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 "); + $(id2).html(""); + } + },10000); + + }else{ + $("#e_tip_"+id).after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!'); + } +} + +function create_editorMD(id, width, high, placeholder, imageUrl,initValue, callback) { + var editorName = window.editormd(id, { + width: width, + height: high, + path: path, // "/editormd/lib/" + markdown : initValue, + syncScrolling: "single", + tex: true, + tocm: true, + emoji: true, + taskList: true, + codeFold: true, + searchReplace: true, + htmlDecode: "style,script,iframe", + sequenceDiagram: true, + autoFocus: false, + placeholder: placeholder, + toolbarIcons: function () { + // Or return editormd.toolbarModes[name]; // full, simple, mini + // Using "||" set icons align right. + return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear"] + }, + toolbarCustomIcons: { + testIcon: "
    ", + testIcon1: "
    " + }, + //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 + saveHTMLToTextarea: true, + // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 + dialogMaskOpacity: 0.6, + imageUpload: true, + imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], + imageUploadURL: imageUrl,//url + onload: function () { + // this.previewing(); + $("#" + id + " [type=\"latex\"]").bind("click", function () { + editorName.cm.replaceSelection("```latex"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("```"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line - 1, 0); + }); + + $("#" + id + " [type=\"inline\"]").bind("click", function () { + editorName.cm.replaceSelection("$$$$"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line, __Cursor.ch - 2); + editorName.cm.focus(); + }); + $("[type=\"inline\"]").attr("title", "行内公式"); + $("[type=\"latex\"]").attr("title", "多行公式"); + + callback && callback() + } + }); + return editorName; +} + + +export default class TPMquestion extends Component { + constructor(props) { + super(props) + this.state = { + choice_url: undefined, + practice_url: undefined, + go_back_url: undefined, + position: undefined, + task_pass_default: undefined, + submit_url: undefined, + questionInputvalue:undefined, + questionaddsum:0, + questionaddarray:[], + questionaddtype:true, + activetype:"", + questionlists:[{str:"A",val:"",type:false},{str:"B",val:"",type:false},{str:"C",val:"",type:false},{str:"D",val:"",type:false}], + answeshixunsGroup: 1, + answeoptions:[10,20], + answeonshixunsmark:10, + shixunssanswerkillvalue:"", + shixunsskillanswerlist:[], + challenge_id:"", + challenge_choose_id:undefined, + questionlistss:[], + newcnttype:false, + newquestioMDvaluetype:false, + challenge_tagtype:false, + editquestionaddtype:false, + mancheckpointId:undefined, + power:false, + questionInputvaluetype:false, + questioMD:"", + standard_answer:"", + subject:"", + newquestioMDvaluetypes:false, + questionInputvaluetypes:false, + prev_challenge:undefined, + next_challenge:undefined, + newcnttypesum:1, + marktype:false, + answer:"", + sumittype:false + } + } +questioMD=(initValue, id)=> { + + this.contentChanged = false; + const placeholder = "请输入选择题的过关任务内容"; +// amp; +// 编辑时要传memoId + // const imageUrl = `/upload_with_markdown?container_id=&container_type=Memo`; + const imageUrl = `/api/attachments.json`; +// 创建editorMd + + let questio_editormd = create_editorMD(id, '100%', 400, placeholder, imageUrl, initValue,() => { + setTimeout(() => { + questio_editormd.resize() + questio_editormd.cm && questio_editormd.cm.refresh() + }, 500) + + if (initValue != undefined) { + questio_editormd.setValue(initValue) + } + questio_editormd.cm.on("change", (_cm, changeObj) => { + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + md_elocalStorage(questio_editormd, `MemoQuestion_${id}`, `${id}Question`); + this.questio_editormd = questio_editormd; + window.questio_editormd = questio_editormd; + +} + +newanswerMD=(initValue, id)=> { + + this.contentChanged = false; +// amp; +// 编辑时要传memoId + const imageUrl = `/api/attachments.json`; +// 创建editorMd + + let newanswerMD_editormd = create_editorMD(id, '100%', 400, "请输入各个选项的具体解析或其他相关信息", imageUrl, initValue,() => { + setTimeout(() => { + newanswerMD_editormd.resize() + newanswerMD_editormd.cm && newanswerMD_editormd.cm.refresh() + }, 500) + + if (initValue != undefined) { + newanswerMD_editormd.setValue(initValue) + } + newanswerMD_editormd.cm.on("change", (_cm, changeObj) => { + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + + md_elocalStorage(newanswerMD_editormd, `MemoQuestion_${id}`, `${id}Question`); + + this.newanswerMD_editormd = newanswerMD_editormd; + window.newanswerMD_editormd = newanswerMD_editormd; + +} + +newquestioMD=(initValue, id)=>{ + this.contentChanged = false; +// amp; +// 编辑时要传memoId + const imageUrl = `/api/attachments.json`; +// 创建editorMd + + let newquestioMD_editormd = create_editorMD(id, '100%', 400, "请输入选择题的题干内容", imageUrl, initValue,() => { + setTimeout(() => { + newquestioMD_editormd.resize() + newquestioMD_editormd.cm && newquestioMD_editormd.cm.refresh() + }, 500) + + if (initValue != undefined) { + newquestioMD_editormd.setValue(initValue) + } + newquestioMD_editormd.cm.on("change", (_cm, changeObj) => { + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + md_elocalStorage(newquestioMD_editormd, `MemoQuestion_${id}`, `${id}Question`); + this.newquestioMD_editormd = newquestioMD_editormd; + window.newquestioMD_editormd = newquestioMD_editormd; + +} + +editanswerMD=(initValue, id)=> { + + this.contentChanged = false; + const placeholder = ""; +// amp; +// 编辑时要传memoId + const imageUrl = `/api/attachments.json`; +// 创建editorMd + + const neweditanswer_editormd =create_editorMD(id, '100%', 400, "请输入选择题的题干内容", imageUrl, initValue,()=> { + setTimeout(() => { + neweditanswer_editormd.resize() + neweditanswer_editormd.cm && neweditanswer_editormd.cm.refresh() + }, 500) + + if (initValue != undefined) { + neweditanswer_editormd.setValue(initValue) + } + neweditanswer_editormd.cm.on("change", (_cm, changeObj) => { + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + md_elocalStorage(neweditanswer_editormd, `MemoQuestion_${id}`, `${id}Question`); + this.neweditanswer_editormd = neweditanswer_editormd; + window.neweditanswer_editormd = neweditanswer_editormd; + +} + +editanswersMD=(initValue, id)=> { + + this.contentChanged = false; + const placeholder = ""; +// amp; +// 编辑时要传memoId + const imageUrl = `/api/attachments.json`; +// 创建editorMd + + const editanswersMD_editormd = create_editorMD(id, '100%', 400, "请输入各个选项的具体解析或其他相关信息", imageUrl, initValue,() => { + setTimeout(() => { + editanswersMD_editormd.resize() + editanswersMD_editormd.cm && editanswersMD_editormd.cm.refresh() + }, 500) + + if (initValue != undefined) { + editanswersMD_editormd.setValue(initValue) + } + editanswersMD_editormd.cm.on("change", (_cm, changeObj) => { + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + md_elocalStorage(editanswersMD_editormd, `MemoQuestion_${id}`, `${id}Question`); + this.editanswersMD_editormd = editanswersMD_editormd; + window.editanswersMD_editormd = editanswersMD_editormd; + +} + + //_______________________________________________________________________________ + questionInputvalue=(e)=>{ + this.setState({ + questionInputvalue: e.target.value + }) + } + componentDidMount() { + if(this.props.status===2){ + + } + let id = this.props.match.params.shixunId; + let checkpointId=this.props.match.params.checkpointId; + + this.setState({ + mancheckpointId:id, + }) + + let newchoice_url= "/shixuns/"+id+"/challenges/newquestion"; + let newpractice_url= "/shixuns/"+id+"/challenges/new"; + let newgo_back_url="/shixuns/"+id+"/challenges"; + + if(this.props.match.params.choose_id===undefined){ + if(checkpointId===undefined){ + //新建模式 + let nurl = "/shixuns/" + id + "/challenges/new.json" + axios.get(nurl).then((response) => { + + if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { + + }else { + this.setState({ + choice_url: newchoice_url, + practice_url: newpractice_url, + go_back_url: newgo_back_url, + position: response.data.position, + task_pass_default: response.data.task_pass_default, + submit_url: response.data.submit_url, + power:true, + activetype:"first", + + }) + if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { + this.questioMD("", "questioMD"); + + this.setState({ + questioMD:"" + }) + } else { + this.questioMD("", "questioMD"); + + // this.create_mackdown(response.data.task_pass_default, "questioMD","") + this.setState({ + questioMD:response.data.task_pass_default + }) + } + this.shixunsautoHeight() + } + + }).catch((error) => { + console.log(error) + }); + + }else{ + //编辑模式 + let url = "/shixuns/"+ id +"/challenges/"+checkpointId+"/edit.json?st=1" + axios.get(url).then((response) => { + // if(choose_idlist!=undefined){ + // + // for(var i=0; i { + console.log(error) + }); + } + + }else{ + $('html').animate({ + scrollTop:10 + }, 500); + + let{challenge_id} =this.state; + + let id = this.props.match.params.shixunId; + let url = "/shixuns/"+ id +"/challenges/"+checkpointId+"/edit.json?st=1" + axios.get(url).then((response) => { + // if(choose_idlist!=undefined){ + // + // for(var i=0; i { + console.log(error) + }); + + let zrl ='/shixuns/'+this.props.match.params.shixunId+'/challenges/'+this.props.match.params.checkpointId+'/edit_choose_question.json?choose_id='+this.props.match.params.choose_id; + axios.get(zrl).then((response) => { + if(response.status===200){ + let choose_contents=response.data.choose_contents; + let newchoose_contentslist=[] + for(var i=0; i { + }); + + } + } + + clickquestionsumit=()=>{ + this.setState({ + sumittype:true + }) + let checkpointId=this.props.match.params.checkpointId; + if(this.props.status===2&&checkpointId===undefined){ + this.props.showSnackbar("该实训已经发布不能新建") + this.setState({ + sumittype:false + }) + return + } + let {questionInputvalue} =this.state; + const exercise_editormdvalue = this.questio_editormd.getValue(); + let id = this.props.match.params.shixunId; + + if(questionInputvalue===undefined||questionInputvalue===null||questionInputvalue===""){ + this.setState({ + questionInputvaluetype:true + }) + $('html').animate({ + scrollTop: 10 + }, 1000); + this.setState({ + sumittype:false + }) + return + } + + + if(exercise_editormdvalue===null ||exercise_editormdvalue===""){ + this.setState({ + questionInputvaluetypes:true + }) + $('html').animate({ + scrollTop: 500 + }, 1000); + this.setState({ + sumittype:false + }) + return + } + if(checkpointId===undefined){ + + let url = "/shixuns/" + id + "/challenges.json"; + + axios.post(url, { + identifier:id, + subject: questionInputvalue, + task_pass: exercise_editormdvalue, + st: 1 + }).then((response) => { + this.props.showSnackbar(response.data.messages); + // if(response.data.status===1){ + // + // this.setState({ + // questionaddtype:false, + // challenge_id:response.data.challenge_id + // }) + // + // this.questionadd() + // } + window.location.href = '/shixuns/'+id+'/challenges/'+response.data.challenge_id+'/editquestion'; + + }).catch((error) => { + console.log(error) + }); + }else{ + let url ="/shixuns/"+id+"/challenges/"+checkpointId+".json"; + axios.put(url, { + tab:0, + subject: questionInputvalue, + task_pass: exercise_editormdvalue, + }).then((response) => { + if(response.data.status===1){ + this.setState({ + questionaddtype:false, + challenge_id:response.data.challenge_id + }) + } + $('html').animate({ + scrollTop: 10 + }, 200); + this.props.showSnackbar(response.data.messages); + window.location.href = '/shixuns/'+id+'/challenges/'+response.data.challenge_id+'/editquestion'; + }).catch((error) => { + console.log(error) + }); + } + + } + + questionall=()=>{ + let {task_pass_default}=this.state; + this.setState({ + activetype:"first", + newquestionaddtype:false, + editquestionaddtype:false + }) + this.questioMD(task_pass_default, "questioMD"); + } + questionadd=()=>{ + $('html').animate({ + scrollTop: 10 + }, 200); + let{questionaddarray}=this.state; + + let questionaddsums=questionaddarray.length; + + if(questionaddarray.length-1>9){ + return + } + + let questionaddarrays=questionaddarray; + questionaddarrays.push({type:0,choose_id:0}); + this.setState({ + activetype:0, + questionaddarray:questionaddarrays, + questionaddtype:true, + newquestionaddtype:true, + editquestionaddtype:false, + questionlists:[{str:"A",val:"",type:false},{str:"B",val:"",type:false},{str:"C",val:"",type:false},{str:"D",val:"",type:false}], + answeshixunsGroup: 1, + answeoptions:[10,20], + answeonshixunsmark:10, + shixunssanswerkillvalue:"", + shixunsskillanswerlist:[] + }) + + this.newanswerMD("","challenge_choose_answer") + this.newquestioMD("","newquestioMDs") + // this.create_mackdown("", "newquestioMDs","请输入选择题的题干内容","newanswerMD_editormd") + // this.create_mackdown("", "challenge_choose_answer","请输入各个选项的具体解析或其他相关信息","newquestioMD_editormd") + this.shixunsautoHeight() + } + + editquestionlists=(newquestionlists)=>{ + let newlist=newquestionlists; + let list=[] + for(var i=0; i{ + let{questionlists} = this.state; + let newquestionlists=questionlists; + let newli={str:letterArr[questionlists.length],val:"",type:false}; + newquestionlists.push(newli); + this.editquestionlists(newquestionlists); + } + + + delquestionlists=(key)=>{ + let{questionlists} = this.state; + let newquestionlists=questionlists; + newquestionlists.splice(key,1); + for(var i=0; i{ + let{questionlists} = this.state; + let newquestionlists=questionlists; + if(newquestionlists[key].type===true){ + newquestionlists[key].type=false; + }else if(newquestionlists[key].type===false){ + newquestionlists[key].type=true; + } + + this.editquestionlists(newquestionlists); + } + + onshixunGroupanswe=(e)=> { + let optionsum; + let onshixunsmark; + if(e.target.value===1){ + optionsum=[10,20]; + onshixunsmark=10; + }else if(e.target.value===2){ + optionsum=[30,40,50,60]; + onshixunsmark=30; + }else if(e.target.value===3){ + optionsum=[70,80,90,100] + onshixunsmark=70; + } + this.setState({ + answeshixunsGroup: e.target.value, + answeoptions:optionsum, + answeonshixunsmark:onshixunsmark + }) + } + shixunssanswerkill = (e) => { + this.setState({ + shixunssanswerkillvalue: e.target.value + }) + + } + clickshixunsanswerskill = () => { + + let {shixunssanswerkillvalue, shixunsskillanswerlist} = this.state; + if (shixunssanswerkillvalue === "") { + return + } else if (shixunssanswerkillvalue === undefined) { + return + } + + if(shixunssanswerkillvalue == "" || shixunssanswerkillvalue == undefined || shixunssanswerkillvalue == null || (shixunssanswerkillvalue.length>0 && shixunssanswerkillvalue.trim().length == 0)){ + message.error("输入为空,不能保存!"); + return + } + + let list = shixunsskillanswerlist; + list.push(shixunssanswerkillvalue); + this.setState({ + shixunsskillanswerlist: list, + shixunssanswerkillvalue: "" + }) + } + delshixunssnswerllist=(key)=>{ + let {shixunsskillanswerlist} = this.state; + let newshixunsskillanswerlist = shixunsskillanswerlist; + newshixunsskillanswerlist.splice(key, 1); + this.setState({ + shixunsskillanswerlist: newshixunsskillanswerlist + }) + } + onInputoquestionption=(e,key)=>{ + + $.fn.autoHeight = function(){ + function autoHeight(elem){ + elem.style.height = 'auto'; + elem.style.maxHeight = '140px'; + elem.scrollTop = 0; //防抖动 + elem.style.height = elem.scrollHeight + 'px'; + } + this.each(function(){ + autoHeight(this); + $(this).on('keyup', function(){ + autoHeight(this); + }); + }); + } + $("#"+e.target.id).autoHeight(); + + let {questionlists}=this.state; + let newquestionlists=questionlists; + newquestionlists[key].val=e.target.value; + this.editquestionlists(newquestionlists); + } + + onshixunsansweSelect=(value)=>{ + this.setState({ + answeonshixunsmark: value + }) + } + + answer_subit=(sumtype,challenge_choose_id)=>{ + + let {challenge_id,questionlists,shixunsskillanswerlist,answeonshixunsmark,answeshixunsGroup,questionaddarray} =this.state; + if(challenge_id===undefined){ + message.error("关卡id为空"); + return + } + let newquestionlists=questionlists; + let newlist=""; + let newtype=[]; + let newcnt=[]; + let list=0; + for(var i=0; i { + console.log(error) + }); + }else{ + let newquestioMDvalue = this.newquestioMD_editormd.getValue(); + + if(newquestioMDvalue===""||newquestioMDvalue==="请输入选择题的题干内容"){ + this.setState({ + newquestioMDvaluetype:true, + }) + $('html').animate({ + scrollTop:100 + }, 200); + message.error("题干为空"); + return + } + let newnewanswerMDvalue = this.newanswerMD_editormd.getValue(); + // + // if(newnewanswerMDvalue===""||newnewanswerMDvalue==="请输入选择题的题干内容"){ + // this.setState({ + // newquestioMDvaluetypes:true, + // }) + // + // $('html').animate({ + // scrollTop:1300 + // }, 200); + // this.props.showSnackbar("参考答案为空"); + // return + // } + if(newnewanswerMDvalue===""||newnewanswerMDvalue===" "){ + newnewanswerMDvalue=newlist + } + url="/shixuns/" + id + "/challenges/" + challenge_id + "/create_choose_question.json"; + axios.post(url, { + challenge_choose: {subject: newquestioMDvalue, answer: newnewanswerMDvalue, standard_answer:newlist , score: answeonshixunsmark, difficult: answeshixunsGroup}, + challenge_tag: shixunsskillanswerlist, + question: {cnt: newcnt}, + choice: {answer: newtype} + }).then((response) => { + + let questionaddsums=questionaddarray.length; + let questionaddarrays=questionaddarray; + questionaddarrays[questionaddsums-1].choose_id=response.data.challenge_choose_id; + if(newlist.length===1){ + questionaddarrays[questionaddsums-1].type=1; + }else if(newlist.length>1){ + questionaddarrays[questionaddsums-1].type=2; + } + this.setState({ + challenge_choose_id:response.data.challenge_choose_id, + questionaddtype:false, + editquestionaddtype:false, + newquestioMDvaluetype:false, + newquestioMDvaluetypes:false, + questionaddarray:questionaddarrays + }) + // $('html').animate({ + // scrollTop: 10 + // }, 200); + message.success("新建成功"); + // this.getanswer_subitlist() + this.gochooseid("/shixuns/"+this.props.match.params.shixunId+"/challenges/"+this.props.match.params.checkpointId+"/editquestion"+"/"+response.data.challenge_choose_id) + }).catch((error) => { + console.log(error) + }); + } + + + } + + // getanswer_subitlist=()=>{ + // let{challenge_choose_id,challenge_id,questionaddarray} =this.state + // let id = this.props.match.params.shixunId; + // let url ='/shixuns/'+id+'/challenges/'+challenge_id+'/edit_choose_question.json?choose_id='+challenge_choose_id; + // axios.get(url).then((response) => { + // if(response.status===200){ + // this.create_mackdown(response.data.subject, "neweditanswer","","neweditanswer_editormd") + // this.create_mackdown(response.data.standard_answer, "editanswers","","editanswersMD_editormd") + // let choose_contents=response.data.choose_contents; + // let newchoose_contentslist=[] + // for(var i=0; i { + // }); + // } + + questionlist=(key,challenge_choose_id,type)=>{ + + $('html').animate({ + scrollTop:10 + }, 500); + + let{challenge_id} =this.state; + + if(challenge_choose_id===""||type===0){ + + this.newanswerMD("","neweditanswer") + this.editanswersMD("","editanswers") + this.setState({ + activetype:challenge_choose_id, + editquestionaddtype:true, + questionaddtype:true, + newquestionaddtype:false, + questionlists:[{str:"A",val:"",type:false},{str:"B",val:"",type:false},{str:"C",val:"",type:false},{str:"D",val:"",type:false}], + answeshixunsGroup: 1, + answeoptions:[10,20], + answeonshixunsmark:10, + shixunssanswerkillvalue:"", + shixunsskillanswerlist:[] + }) + + // this.create_mackdown("", "newquestioMDs","请输入选择题的题干内容","newanswerMD_editormd") + // this.create_mackdown("", "challenge_choose_answer","请输入各个选项的具体解析或其他相关信息","newquestioMD_editormd") + + }else{ + let id = this.props.match.params.shixunId; + let url ='/shixuns/'+id+'/challenges/'+challenge_id+'/edit_choose_question.json?choose_id='+challenge_choose_id; + axios.get(url).then((response) => { + if(response.status===200){ + let choose_contents=response.data.choose_contents; + let newchoose_contentslist=[] + for(var i=0; i { + }); + + } + + } + + shixunsautoHeight=()=>{ + $.fn.autoHeight = function(){ + function autoHeight(elem){ + elem.style.height = 'auto'; + elem.style.maxHeight = '140px'; + elem.scrollTop = 0; //防抖动 + if(elem.scrollHeight===0){ + elem.style.height = 62 + 'px'; + }else{ + // if(elem.style.height>140){ + // + // } + elem.style.height = elem.scrollHeight + 'px'; + } + + } + this.each(function(){ + autoHeight(this); + $(this).on('keyup', function(){ + autoHeight(this); + }); + }); + } + $('textarea[autoHeight]').autoHeight(); + } + + gochooseid=(url)=>{ + window.location.href =url + } + onshixunsmarks=()=> { + this.setState({ + marktype:true + }) + } + + onshixunsmarkss=()=> { + this.setState({ + marktype:false + }) + } + render() { + + let {choice_url, + practice_url, + go_back_url, + position, + questionInputvalue, + challenge_tagtype, + questionInputvaluetype, + answeshixunsGroup, + answeoptions, + answeonshixunsmark, + shixunssanswerkillvalue, + questionlistss,power, + questionaddarray, + questionaddtype, + activetype, + newquestionaddtype, + newquestioMDvaluetype, + editquestionaddtype, + questionlists, + shixunsskillanswerlist, + newcnttype, + challenge_choose_id, + mancheckpointId, + challenge_id, + questioMD, + standard_answer, + subject, + newquestioMDvaluetypes, + questionInputvaluetypes, + prev_challenge, + next_challenge, + newcnttypesum, + marktype, + answer, + sumittype + } = this.state; + + let options; + + + options = answeoptions.map((d, k) => { + return ( + + ) + }) + console.log(answer) + return ( + +
    + + +
    + +
  • + 本关任务 +
  • + + { + questionaddarray.length===0?"":questionaddarray.map((item,key)=>{ + return( +
  • this.questionlist(key,item.choose_id,item.type):""} + > + + { + item.choose_id!=0? + this.gochooseid("/shixuns/"+this.props.match.params.shixunId+"/challenges/"+this.props.match.params.checkpointId+"/editquestion"+"/"+item.choose_id)}> + {key+1}.{item.type===2?"多选题":item.type===1?"单选题":'选择题'} + :{key+1}.{item.type===2?"多选题":item.type===1?"单选题":'选择题'} + } + +
  • + ) + }) + } + + +
  • + + + + +
  • + +
    + +
    + +
    +
    +

    任务名称

    +
    + * +
    + +
    +
    + 必填项 +
    +
    +
    +
    + + +
    +

    过关任务

    +
    + * +
    +
    + +
    +
    +
    + {/**/} +
    +
    + 必填项 +
    +
    +

    +

    +
    + + +
    3||this.props.identity===undefined||power===false?"none":"block"}}> + 提交 + 取消 + +
    + +
    + + + {/*新建*/} + + {newquestionaddtype===true?
    + +
    +
    +

    题干

    +
    + * +
    +
    + {/**/} + {/*
    */} + {/*
    */} + {/**/} +
    + +
    + + +
    + 必填项 +
    + +
    +

    +

    + + +
    + { + questionlists===undefined||questionlists.length===0?"":questionlists.map((item,key)=>{ + return( +
  • + + + this.delquestionlists(key)}> + + + + + +
  • + ) + }) + } +

    + 新增选项 + + + {newcnttypesum===0?"请选择答案":"选项内容不能为空"} + +

    +
  • + + +
  • +
    +
    +
    + + +
    +
    +

    参考答案

    +
    +
    + {/**/} + {/*
    */} + {/*
    */} +
    + +
    + 必填项 +
    +
    +

    +

    + +
    +
    + +
    +

    难度系数

    +
    + + + 简单 + 中等 + 困难 + + +
    +

    奖励经验值

    +
    + * + + + +

    + 如果学员答题错误,则不能得到相应的经验值
    + 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币 +

    + + 必填项 +
    +
    + +
    +

    技能标签

    +
    + * +
    + + {/*+ 添加*/} +
    学员答题正确将获得技能,否则不能获得技能 + + 必填项 + +
    +
    + + { + shixunsskillanswerlist.length === 0 ? "" : shixunsskillanswerlist.map((itme, key) => { + return ( +
  • {itme} + this.delshixunssnswerllist(key)}>× +
  • + ) + }) + } + + +
    + +
    + +
    +
    + + +
    3||this.props.identity===undefined||power===false?"none":"block"}}> + 提交 + 取消 +
    + +
    :""} + + + {/*修改*/} + {editquestionaddtype===true?
    + +
    +
    +

    题干

    +
    + * +
    +
    + +
    +
    +
    +
    + + +
    + 必填项 +
    + +
    +

    +

    +
    + { + questionlists===undefined||questionlists.length===0?"":questionlists.map((item,key)=>{ + return( +
  • + + + this.delquestionlists(key)}> + + +
  • + ) + }) + } +

    + 新增选项 + + + {newcnttypesum===0?"请选择答案":"选项内容不能为空"} + +

    +
  • + + +
  • +
    +
    +
    + + +
    +
    +

    参考答案

    +
    +
    + {/**/} + {/*
    */} + {/*
    */} +
    +
    + 必填项 +
    +
    +

    +

    +
    +
    + +
    +

    难度系数

    +
    + + + 简单 + 中等 + 困难 + + +
    +

    奖励经验值

    +
    + * + + + +

    + 如果学员答题错误,则不能得到相应的经验值
    + 如果学员成功得到经验值,那么将同时获得等值的金币奖励,如:+10经验值、+10金币 +

    + + 必填项 +
    +
    + +
    +

    技能标签

    +
    + * +
    + + {/*+ 添加*/} +
    学员答题正确将获得技能,否则不能获得技能 + + 必填项 + +
    +
    + + { + shixunsskillanswerlist.length === 0 ? "" : shixunsskillanswerlist.map((itme, key) => { + return ( +
  • {itme} + this.delshixunssnswerllist(key)}>× +
  • + ) + }) + } + + +
    + +
    + +
    +
    + + +
    3||this.props.identity===undefined||power===false?"none":"block"}}> + this.answer_subit("edit",challenge_choose_id)}>提交 + 取消 +
    + +
    + :""} + +
    +
    + ) + } +} + + diff --git a/public/react/src/modules/tpm/newshixuns/Newshixuns.js b/public/react/src/modules/tpm/newshixuns/Newshixuns.js index 495287838..fd3097c3f 100644 --- a/public/react/src/modules/tpm/newshixuns/Newshixuns.js +++ b/public/react/src/modules/tpm/newshixuns/Newshixuns.js @@ -635,7 +635,7 @@ class Newshixuns extends Component { this.setState({ opers: true }) - e.stopPropagation();//阻止冒泡 + } bigopens = (e) => { @@ -644,21 +644,21 @@ class Newshixuns extends Component { operss: false, opensmail: false }) - e.stopPropagation();//阻止冒泡 + } bigopensmal = (e) => { this.setState({ opensmail: true }) - e.stopPropagation();//阻止冒泡 + } sbigopen = (e) => { this.setState({ operss: true }) - e.stopPropagation();//阻止冒泡 + } // sbigopens=()=>{ @@ -1196,6 +1196,7 @@ class Newshixuns extends Component { showToday={false} showTime locale={locale} + style={{"width": "184px"}} format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开启时间" onChange={this.onChangeTimePicker}