import React, {Component} from 'react'; import {TPMIndexHOC} from '../TPMIndexHOC'; import {SnackbarHOC} from 'educoder'; import {Select, Radio, Input, Modal, Button, Form, Tooltip, Upload, Icon,notification} from 'antd'; import axios from 'axios'; import {getUploadActionUrl} from 'educoder'; import './css/Newshixuns.css'; import TPMMDEditor from "../challengesnew/TPMMDEditor"; import Bottomsubmit from "../../modals/Bottomsubmit"; const Option = Select.Option; class Newshixuns extends Component { constructor(props) { super(props) this.contentMdRef = React.createRef(); this.state = { shixunName: undefined, NAME_COUNT: 60, is_jupyter: "1", newshixunlist: undefined, language: undefined, runtime: undefined, run_method: undefined, postapplyvisible: undefined, fileList: [], } } componentDidMount() { this.props.form.setFieldsValue({ is_jupyter: `1`, }); 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.contentMdRef.current.setValue(!response.data.sample[0][1] ? "" : 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) }); } shixunNameInput = (e) => { this.setState({ shixunName: e.target.value }) this.props.form.setFieldsValue({ name: e.target.value, }); } RadiovalueonChange = (e) => { this.setState({ Radiovalue: e.target.value, }); }; handleSubmit = (e) => { const mdContnet = this.contentMdRef.current.getValue().trim(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { console.log('Received values of form: ', values); let Url = `/shixuns.json`; axios.post(Url, { description: mdContnet, main_type: values.main_type, sub_type: values.sub_type, shixun: { name: values.name, trainee: values.select, is_jupyter: values.is_jupyter === "2" ? true : false, } } ).then((response) => { if (response.status === 200) { window.location.href = "/shixuns/" + response.data.shixun_identifier + "/challenges"; // window.open("/shixuns/"+response.data.shixun_identifier+"/challenges"); } else { this.setState({ bottonloading: false }) } }).catch((error) => { console.log(error) this.setState({ bottonloading: false }) }) } }); }; Selectthestudent = (value) => { this.props.form.setFieldsValue({ select: value, }); } main_type = (value, e) => { this.props.form.setFieldsValue({ main_type: value, }); this.setState({ mainvalues: e.props.name }) } sub_type = (value, e) => { this.props.form.setFieldsValue({ sub_type: value, }); let newlist = "" e.map((item, key) => { if(item.props.name!=""){ newlist = newlist + `${item.props.name}` } }) this.setState({ subvalues: newlist }) } post_apply = () => { this.setState({ postapplyvisible: true }) } sendhideModaly = () => { this.setState({ postapplyvisible: false, }) if (this.state.file !== undefined) { // this.deleteAttachment(this.state.file); this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } else { this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } } sendsure_apply = () => { let {language, runtime, run_method} = this.state; if (!language || language === "") { // this.props.showNotification(`请填写该镜像是基于什么语言`); this.setState({ languagewritetype: true }) return } if (!runtime || runtime === "") { // this.props.showNotification(`请填写该镜像是基于什么语言系统环境`); this.setState({ systemenvironmenttype: true }) return; } if (!run_method || run_method === "") { // 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) { this.setState({ attachmentidstype: true }) return; } var data = { language: language, runtime: runtime, run_method: run_method, attachment_id: attachment_ids[0], } var url = `/shixuns/apply_shixun_mirror.json`; axios.post(url, data ).then((response) => { try { if (response.data) { if (this.state.file !== undefined) { this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } else { this.setState({ file: undefined, deleteisnot: true, language: "", runtime: "", run_method: "", fileList: [] }) } notification.open( { message: '提示', description: '提交成功!', } ) this.sendhideModaly() } } catch (e) { } }) } setlanguage = (e) => { this.setState({ language: e.target.value }) if (e.target.value) { this.setState({ languagewritetype: false }) } } setruntime = (e) => { this.setState({ runtime: e.target.value }) if (e.target.value) { this.setState({ systemenvironmenttype: false }) } } setrun_method = (e) => { this.setState({ run_method: e.target.value }) if (e.target.value) { this.setState({ testcoderunmodetype: false }) } } // 附件相关 START handleChange = (info) => { if(info.file.status === 'uploading' || info.file.status === 'done' || info.file.status === 'removed') { let {fileList} = this.state; if (info.file.status === 'uploading' || info.file.status === 'done' || info.file.status === 'removed') { console.log("handleChange1"); // if(fileList.length===0){ let fileLists = info.fileList; this.setState({ // fileList:appendFileSizeToUploadFileAll(fileList), fileList: fileLists, deleteisnot: false }); // } } } } onAttachmentRemove = (file) => { if(!file.percent || file.percent == 100){ 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); }); } render() { const {getFieldDecorator} = this.props.form; const {newshixunlist, fileList, postapplytitle, postapplyvisible} = this.state; const uploadProps = { width: 600, fileList, multiple: true, action: `${getUploadActionUrl()}`, onChange: this.handleChange, onRemove: this.onAttachmentRemove, beforeUpload: (file, fileList) => { if (this.state.fileList.length >= 1) { return false } const isLt150M = file.size / 1024 / 1024 < 50; if (!isLt150M) { notification.open( { message: '提示', description: '文件大小必须小于50MB', } ) } if (this.state.file !== undefined) { this.setState({ file: file }) } else { this.setState({ file: file }) } return isLt150M; }, } return (
新建实训项目 {this.props.user && this.props.user.main_site === true ? 实训制作指南 : ""}
{getFieldDecorator('is_jupyter')( 普通实训 Jupyter实训 , )} {getFieldDecorator('name', { rules: [{ required: true, message: '请输入选题名称', }, { max: 60, message: '请输入名称,最大限制60个字符', }, { whitespace: true, message: '请勿输入空格' }], })( )} {getFieldDecorator('select', { rules: [{required: true, message: '请选择难易度'}], })(
)} (实训的难易程度)
{getFieldDecorator('main_type', { rules: [{required: true, message: '请选择主类别'}], })(
)}
{getFieldDecorator('sub_type')(
)}
{this.state.mainvalues === undefined && this.state.subvalues === undefined ? "" :
{`已安装软件:${this.state.mainvalues===undefined?"":this.state.mainvalues}${this.state.subvalues===undefined?"":this.state.subvalues}`} {` 说明:添加了${this.state.mainvalues===undefined?"":this.state.mainvalues}${this.state.subvalues===undefined?"":this.state.subvalues}`}
}
没有实验环境? 申请新建
{postapplyvisible === true ? : ""}
  • {this.state.languagewritetype === true ? "请填写该镜像语言" : ""}
  • {this.state.systemenvironmenttype === true ? "请填写该镜像语言系统环境" : ""}
  • {this.state.testcoderunmodetype === true ? "请填写该镜像测试代码运行方式" : ""}
  • 上传附件 (单个文件50M以内)
  • {this.state.attachmentidstype === true ? "请上传附件" : ""}
  • this.sendhideModaly()} >取消
  • {/**/}

    新建申请已提交,请等待管理员的审核

  • 我们将在1-2个工作日内与您联系
  • this.handleSubmit()}/>
    ); } } const NewshixunsNew = Form.create({name: 'newshixun'})(Newshixuns); export default SnackbarHOC()(TPMIndexHOC(NewshixunsNew));