import React, {Component} from 'react'; import {TPMIndexHOC} from '../TPMIndexHOC'; import {SnackbarHOC} from 'educoder'; import {Input, Select, Radio, Checkbox, Modal, Icon, DatePicker,Upload,Button,message,Form,notification} from 'antd'; // import "antd/dist/antd.css"; import locale from 'antd/lib/date-picker/locale/zh_CN'; import axios from 'axios'; import './css/Newshixuns.css'; import {getUrl} from 'educoder' import moment from 'moment'; let path = getUrl("/editormd/lib/") const $ = window.$; let timeout; let currentValue; const Option = Select.Option; const RadioGroup = Radio.Group; const confirm = Modal.confirm; // 处理整点 半点 // 取传入时间往后的第一个半点 export function handleDateStrings(dateString) { if (!dateString) return dateString; const ar = dateString.split(':') if (ar[1] == '00' || ar[1] == '30') { return dateString } const miniute = parseInt(ar[1]); if (miniute < 30 || miniute == 60) { return [ar[0], '30'].join(':') } if (miniute < 60) { // 加一个小时 const tempStr = [ar[0], '00'].join(':'); const format = "YYYY-MM-DD HH:mm"; const _moment = moment(tempStr, format) _moment.add(1, 'hours') return _moment.format(format) } return dateString } // 恢复数据 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, `memoNew_${id}`, "memoNew"); callback && callback() } }); return editorName; } function range(start, end) { const result = []; for (let i = start; i < end; i++) { result.push(i); } return result; } function disabledDateTime() { return { // disabledHours: () => range(0, 24).splice(4, 20), disabledMinutes: () => range(1, 30).concat(range(31, 60)), // disabledSeconds: () => [0, 60], }; } function disabledDate(current) { return current && current < moment().endOf('day').subtract(1, 'days'); } class Newshixuns extends Component { constructor(props) { super(props) this.state = { fileList: [], newshixunlist: undefined, departmentslist: undefined, name: "", main_type: "", small_type: "", trainee: "", webssh: 0, use_scope: 0, can_copy: "", scope_partment: undefined, vnc: "", scopetype: false, postapplyvisible: false, sendsure_applyvalue: undefined, postapplytitle: false, shixun_nametype: false, main_types: false, trainee_types: false, SelectTheCommandtype: false, opers: false, operss: false, TimePickervalue: "", opensmail: false, onSearchvalue: "", scope_partmenttype: false, languagewrite: undefined, systemenvironment:undefined, testcoderunmode:undefined, file:undefined, deleteisnot:true, languagewritetype:false, systemenvironmenttype:false, testcoderunmodetype:false, attachmentidstype:false, datalisttype:false } } initMD(initValue) { this.contentChanged = false; const placeholder = ""; // amp; // 编辑时要传memoId const imageUrl = `/api/attachments.json`; // 创建editorMd const taskpass_editormd = create_editorMD("memoMD", '100%', 400, placeholder, imageUrl, () => { setTimeout(() => { taskpass_editormd.resize() taskpass_editormd.cm && taskpass_editormd.cm.refresh() }, 500) if (initValue) { taskpass_editormd.setValue(initValue) } taskpass_editormd.cm.on("change", (_cm, changeObj) => { // console.log('....contentChanged') this.contentChanged = true; }) }); this.taskpass_editormd = taskpass_editormd; window.taskpass_editormd = taskpass_editormd; } componentDidMount() { let newshixunUrl = `/shixuns/new.json`; axios.get(newshixunUrl).then((response) => { if (response.status === 200) { if (response.data.message===undefined) { this.setState({ newshixunlist: response.data }); this.initMD(response.data.sample[0][1]); } } }).catch((error) => { console.log(error) }); let departmentsUrl = `/shixuns/departments.json`; axios.get(departmentsUrl).then((response) => { if (response.status === 200) { if (response.data.message===undefined) { this.setState({ departmentslist: response.data.shools_name }); } } }).catch((error) => { console.log(error) }); } setlanguagewrite = (e)=>{ this.setState({ languagewrite: e.target.value }) } setsystemenvironment = (e) => { this.setState({ systemenvironment: e.target.value }) } settestcoderunmode = (e) => { this.setState({ testcoderunmode: e.target.value }) } shixunname = (e) => { this.setState({ name: e.target.value, shixun_nametype: false }); } bigClass = (value) => { this.setState({ main_type: value }) } littleClass = (value) => { this.setState({ small_type: value }) } Selectthestudent = (value) => { this.setState({ trainee: value }) } SelectTheCommand = (e) => { this.setState({ webssh: e.target.value, }); if (e.target.value === 2) { this.setState({ SelectTheCommandtype: true, multi_webssh: false }); } else { this.setState({ SelectTheCommandtype: false, multi_webssh: false }); } } Selectpublic = (e) => { this.setState({ scopetype: false, use_scope: e.target.value, }); if (e.target.value === 1) { this.setState({ scopetype: true }); } } Teacherscopy = (e) => { let sum = "" if (e.target.checked === false) { sum = 0 } else if (e.target.checked === true) { sum = 1 } this.setState({ can_copy: sum, }); } TeachersUbuntu = (e) => { let sum = "" if (e.target.checked === false) { sum = 0 } else if (e.target.checked === true) { sum = 1 } this.setState({ vnc: sum, }); } adduse_scopeinput = () => { let {scope_partment} = this.state; let array = scope_partment; let newarray = "" array.push(newarray) this.setState({ scope_partment: array, }); } shixunScopeInput = (e, id) => { let types=false let {scope_partment} = this.state; let datalist = scope_partment; if (datalist === undefined) { datalist = [] } datalist.map((item,key)=>{ if(e===item){ types=true this.setState({ datalisttype:true }) return } }) if(types===false){ datalist.push(e) this.setState({ scope_partment: datalist, onSearchvalue: "" }); } } deleteScopeInput = (key) => { let {scope_partment} = this.state; let datalist = scope_partment; datalist.splice(key, 1); this.setState({ scope_partment: datalist }); } //提交数据 submit_new_shixun = () => { const mdVal = this.taskpass_editormd.getValue(); let {can_copy, main_type, name, scope_partment, small_type, trainee, use_scope, vnc, webssh, multi_webssh, TimePickervalue} = this.state; let Url = `/shixuns.json` if (name === "") { this.setState({ shixun_nametype: true }) this.props.showSnackbar("实训名称为空"); $('html').animate({ scrollTop: 10 }, 1000); return } if (main_type === "") { this.setState({ main_types: true }) $('html').animate({ scrollTop: 700 }, 1000); this.props.showSnackbar("请选择技术平台大类别"); return } if (use_scope === 1) { if (scope_partment === undefined || scope_partment.length === 0) { this.setState({ scope_partmenttype: true }) $('html').animate({ scrollTop: 900 }, 1000); this.props.showSnackbar("公开程度,指定单位为空"); return } } if (trainee === "") { this.setState({ trainee_types: true }) // $('html').animate({ // scrollTop: 700 // }, 1000); this.props.showSnackbar("请选择发布信息"); return } let newmulti_webssh = multi_webssh; if (newmulti_webssh === true) { newmulti_webssh = 1 } else { newmulti_webssh = "" } axios.post(Url, { name: name, can_copy: can_copy, description: mdVal, main_type: main_type, scope_partment: scope_partment, small_type: small_type, trainee: trainee, use_scope: use_scope, vnc: vnc, webssh: webssh, multi_webssh: newmulti_webssh, task_pass: 1, opening_time: TimePickervalue } ).then((response) => { if (response.status === 200) { window.location.href = "/shixuns/" + response.data.shixun_identifier + "/challenges"; // window.open("/shixuns/"+response.data.shixun_identifier+"/challenges"); } }).catch((error) => { console.log(error) }) } shixunsfetch = (value, callback) => { if (timeout) { clearTimeout(timeout); timeout = null; } currentValue = value; function fake() { let departmentsUrl = `/shixuns/departments.json?q=` + currentValue; axios.get(departmentsUrl).then((response) => { if (response.data.message===undefined) { callback(response.data.shools_name); } }).catch((error) => { console.log(error) }); } timeout = setTimeout(fake, 300); } shixunHandleSearch = (value) => { this.shixunsfetch(value, departmentslist => this.setState({departmentslist})); this.setState({ onSearchvalue: "" }) } post_apply = () => { this.setState({ postapplyvisible: true }) } sendsure_apply = () => { let {languagewrite,systemenvironment,testcoderunmode} = this.state; // console.log("点击确定") // console.log("languagewrite"+languagewrite); // console.log("systemenvironment"+systemenvironment); // console.log("testcoderunmode"+testcoderunmode); // let attachment_ids = undefined // if (this.state.fileList) { // attachment_ids = this.state.fileList.map(item => { // return item.response ? item.response.id : item.id // }) // } if(languagewrite === undefined || languagewrite === "" ){ // this.props.showNotification(`请填写该镜像是基于什么语言`); this.setState({ languagewritetype:true }) return } if(systemenvironment === undefined || systemenvironment === ""){ // this.props.showNotification(`请填写该镜像是基于什么语言系统环境`); this.setState({ systemenvironmenttype:true }) return; } if(testcoderunmode === undefined || testcoderunmode === "") { // this.props.showNotification(`请填写该镜像中测试代码运行方式`); this.setState({ testcoderunmodetype:true }) return; } var attachment_ids=undefined; if (this.state.fileList) { attachment_ids = this.state.fileList.map(item => { return item.response ? item.response.id : item.id }) } if( attachment_ids === undefined || attachment_ids.length===0){ // notification.open( // { // message: '提示', // description: // '请上传附件!', // // } // ) this.setState({ attachmentidstype:true }) return; } // console.log("attachment_ids"+attachment_ids); // alert(languagewrite +" "+systemenvironment +" "+testcoderunmode + " "+attachment_ids); var data={ language:languagewrite, runtime:systemenvironment, run_method:testcoderunmode, attachment_id:attachment_ids[0], } var url =`/shixuns/apply_shixun_mirror.json`; axios.post(url,data ).then((response) => { try { if (response.data) { // const { id } = response.data; // if (id) { if(this.state.file !== undefined){ console.log("549"); // this.deleteAttachment(this.state.file); this.setState({ file:undefined, languagewrite:"", systemenvironment:"", testcoderunmode:"", }) }else { this.setState({ file:undefined, languagewrite:"", systemenvironment:"", testcoderunmode:"", }) } // this.props.showNotification('提交成功!'); notification.open( { message: '提示', description: '提交成功!', } ) this.sendhideModaly() // this.props.history.push(`/courses/${cid}/graduation_topics`); // } } }catch (e) { } }) } sendhideModaly = () => { this.setState({ postapplyvisible: false, }) if(this.state.file !== undefined){ console.log("580"); // this.deleteAttachment(this.state.file); this.setState({ file:undefined, languagewrite:"", systemenvironment:"", testcoderunmode:"", }) }else { this.setState({ file:undefined, languagewrite:"", systemenvironment:"", testcoderunmode:"", }) } } sendsure_applyvalues = (e) => { this.setState({ sendsure_applyvalue: e.target.value }) } yeshidemodel = () => { this.setState({ postapplytitle: false }) } SelectTheCommandonChange = (e) => { this.setState({ multi_webssh: e.target.checked }) } bigopen = (e) => { this.setState({ opers: true }) } bigopens = (e) => { this.setState({ opers: false, operss: false, opensmail: false }) } bigopensmal = (e) => { this.setState({ opensmail: true }) } sbigopen = (e) => { this.setState({ operss: true }) } // sbigopens=()=>{ // this.setState({ // operss:false // }) // } onChangeTimePicker = (value, dateString) => { this.setState({ TimePickervalue: dateString=== ""?"":moment(handleDateStrings(dateString)) }) } // 附件相关 START handleChange = (info) => { console.log("handleChange1"); let fileList = info.fileList; this.setState({ fileList:fileList, deleteisnot:false}); } onAttachmentRemove = (file) => { confirm({ title: '确定要删除这个附件吗?', okText: '确定', cancelText: '取消', // content: 'Some descriptions', onOk: () => { console.log("665") this.deleteAttachment(file) }, onCancel() { console.log('Cancel'); }, }); return false; } deleteAttachment = (file) => { console.log(file); let id=file.response ==undefined ? file.id : file.response.id const url = `/attachments/${id}.json` axios.delete(url, { }) .then((response) => { if (response.data) { const { status } = response.data; if (status == 0) { // console.log('--- success') this.setState((state) => { const index = state.fileList.indexOf(file); const newFileList = state.fileList.slice(); newFileList.splice(index, 1); return { fileList: newFileList, deleteisnot:true }; }); } } }) .catch(function (error) { console.log(error); }); } handleSubmit=()=>{ // console.log(this.state.languagewrite) // console.log(this.state.systemenvironment) // console.log(this.state.testcoderunmode) var attachment_ids; if (this.state.fileList) { attachment_ids = this.state.fileList.map(item => { return item.response ? item.response.id : item.id }) } // console.log(attachment_ids); // var data={ // language:"", // runtime:"", // run_method:"", // attachment_id:"", // } // axios.post(url,data // ).then((response) => { // if (response.data) { // // const { id } = response.data; // // if (id) { // this.props.showNotification('提交成功!'); // // this.props.history.push(`/courses/${cid}/graduation_topics`); // // } // } // }) } render() { const { getFieldDecorator } = this.props.form; const thiss=this; let {testcoderunmode ,systemenvironment,languagewrite,deleteisnot, fileList,TimePickervalue, scope_partmenttype, opensmail, newshixunlist, name, scope_partment, departmentslist, postapplyvisible, sendsure_applyvalue, postapplytitle, shixun_nametype, main_types, trainee_types, SelectTheCommandtype, opers, datalisttype, onSearchvalue} = this.state; let options if (departmentslist != undefined) { options = this.state.departmentslist.map((d, k) => { return ( ) }) } const uploadProps = { width: 600, fileList, multiple: true, // https://github.com/ant-design/ant-design/issues/15505 // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // showUploadList: false, action: `${getUrl()}/api/attachments.json`, onChange: this.handleChange, onRemove: this.onAttachmentRemove, beforeUpload: (file) => { // console.log('beforeUpload', file.name); const isLt150M = file.size / 1024 / 1024 < 50; if (!isLt150M) { // this.props.showNotification(`文件大小必须小于50MB`); notification.open( { message: '提示', description: '文件大小必须小于50MB', } ) } if(thiss.state.file !== undefined){ console.log("763") // thiss.deleteAttachment(thiss.state.file); thiss.setState({ file:file }) }else { thiss.setState({ file:file }) } console.log("handleChange2"); return isLt150M; }, } // const uploadProps = { // width: 600, // fileList, // multiple: true, // // https://github.com/ant-design/ant-design/issues/15505 // // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // // showUploadList: false, // action: `${getUrl()}/api/attachments.json`, // onChange: this.handleChange, // onRemove: this.onAttachmentRemove, // beforeUpload: (file) => { // // console.log('beforeUpload', file.name); // const isLt50M = file.size / 1024 / 1024 < 50; // if (!isLt50M) { // message.error('文件大小必须小于150MB!'); // } // return isLt50M; // }, // }; return (
创建实训 实训制作指南
实训名称
简介
命令行
公开程度
发布信息
VNC图形化
*/} {/*