2020-04-28 17:23:34 +08:00
|
|
|
|
import React, { Component } from "react";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
import { Input } from 'antd';
|
2020-03-16 14:12:11 +08:00
|
|
|
|
import TPMMDEditor from "../tpm/challengesnew/TPMMDEditor";
|
2020-04-28 17:23:34 +08:00
|
|
|
|
import { Link } from "react-router-dom";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
require('codemirror/lib/codemirror.css');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const $ = window.$;
|
|
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
class PathNew extends Component {
|
|
|
|
|
|
constructor(props) {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
super(props);
|
|
|
|
|
|
this.contentMdRef = React.createRef();
|
|
|
|
|
|
this.Point_editMD = React.createRef();
|
2020-04-28 17:23:34 +08:00
|
|
|
|
this.state = {
|
|
|
|
|
|
pathName: "",
|
|
|
|
|
|
description: "",
|
|
|
|
|
|
point: "",
|
|
|
|
|
|
flag_name: true,
|
|
|
|
|
|
bottonloading: false
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 提交
|
2020-04-28 17:23:34 +08:00
|
|
|
|
submitNewPath = () => {
|
|
|
|
|
|
let { pathName } = this.state;
|
|
|
|
|
|
if (pathName === "") {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.props.showSnackbar("请输入实践课程名称");
|
2020-04-28 17:23:34 +08:00
|
|
|
|
window.location.href = "#part_Name";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.setState({
|
2020-04-28 17:23:34 +08:00
|
|
|
|
flag_name: false
|
2020-03-16 14:12:11 +08:00
|
|
|
|
})
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-04-28 17:23:34 +08:00
|
|
|
|
let des = this.contentMdRef.current.getValue().trim();
|
|
|
|
|
|
if (des === "") {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.props.showSnackbar("请输入实践课程的简介");
|
2020-04-28 17:23:34 +08:00
|
|
|
|
window.location.href = "#part_Des";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (des.length > 8000) {
|
|
|
|
|
|
this.props.showSnackbar("实践课程的简介最大限制8000个字符");
|
2020-04-28 17:23:34 +08:00
|
|
|
|
window.location.href = "#part_Des";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let point = this.Point_editMD.current.getValue().trim();
|
2020-04-28 17:23:34 +08:00
|
|
|
|
if (point === "") {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.props.showSnackbar("请输入实践课程的学习须知");
|
2020-04-28 17:23:34 +08:00
|
|
|
|
window.location.href = "#part_point";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-04-28 17:23:34 +08:00
|
|
|
|
if (point.length > 2000) {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.props.showSnackbar("实践课程的学习须知最大限制2000个字符");
|
2020-04-28 17:23:34 +08:00
|
|
|
|
window.location.href = "#part_point";
|
2020-03-16 14:12:11 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.isEditPage == true) {
|
2020-04-28 17:23:34 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
|
bottonloading: true
|
|
|
|
|
|
})
|
2020-03-16 14:12:11 +08:00
|
|
|
|
let pathId = this.props.match.params.pathId;
|
|
|
|
|
|
|
|
|
|
|
|
const editUrl = `/paths/${pathId}.json`
|
2020-04-28 17:23:34 +08:00
|
|
|
|
axios.put(editUrl, {
|
|
|
|
|
|
name: pathName,
|
|
|
|
|
|
description: des,
|
|
|
|
|
|
learning_notes: point
|
|
|
|
|
|
}).then((response) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
// console.log(response.data.subject_id);
|
|
|
|
|
|
if (response.data.subject_id) {
|
|
|
|
|
|
this.props.history.push(`/paths/${response.data.subject_id}`)
|
2020-04-28 17:23:34 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
bottonloading: false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch((error) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
console.log(error);
|
2020-04-28 17:23:34 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
|
bottonloading: false
|
|
|
|
|
|
})
|
2020-03-16 14:12:11 +08:00
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2020-04-28 17:23:34 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
|
bottonloading: true
|
|
|
|
|
|
})
|
|
|
|
|
|
let url = "/paths.json"
|
|
|
|
|
|
axios.post(url, {
|
|
|
|
|
|
name: pathName,
|
|
|
|
|
|
description: des,
|
|
|
|
|
|
learning_notes: point
|
|
|
|
|
|
}).then((response) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
// console.log(response.data.subject_id);
|
|
|
|
|
|
if (response.data.subject_id) {
|
|
|
|
|
|
this.props.history.push(`/paths/${response.data.subject_id}`)
|
2020-04-28 17:23:34 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
bottonloading: false
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch((error) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
console.log(error);
|
2020-04-28 17:23:34 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
|
bottonloading: false
|
|
|
|
|
|
})
|
2020-03-16 14:12:11 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2020-04-28 17:23:34 +08:00
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
let url = "/paths/new.json"
|
|
|
|
|
|
axios.get(url).then((result) => {
|
|
|
|
|
|
console.log(result)
|
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
console.log(error);
|
|
|
|
|
|
})
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let pathId = this.props.match.params.pathId;
|
|
|
|
|
|
if (pathId) {
|
|
|
|
|
|
this.isEditPage = true
|
|
|
|
|
|
|
|
|
|
|
|
// const url = `/paths/${pathId}.json`
|
|
|
|
|
|
const url = `/paths/${pathId}/edit.json`
|
2020-04-28 17:23:34 +08:00
|
|
|
|
axios.get(url).then((response) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
/**
|
|
|
|
|
|
description:
|
|
|
|
|
|
id: 13
|
|
|
|
|
|
learning_notes:
|
|
|
|
|
|
name:
|
2020-04-28 17:23:34 +08:00
|
|
|
|
*/
|
|
|
|
|
|
if (response.data.name) {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.setState({
|
|
|
|
|
|
pathName: response.data.name
|
|
|
|
|
|
})
|
2020-04-28 17:23:34 +08:00
|
|
|
|
this.contentMdRef.current.setValue(response.data && response.data.description);
|
|
|
|
|
|
this.Point_editMD.current.setValue(response.data && response.data.learning_notes);
|
2020-03-16 14:12:11 +08:00
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).catch((error) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
console.log(error);
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.isEditPage = false
|
|
|
|
|
|
|
|
|
|
|
|
this.contentMdRef.current.setValue("");
|
|
|
|
|
|
this.Point_editMD.current.setValue("");
|
|
|
|
|
|
}
|
2020-04-28 17:23:34 +08:00
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
InputName = (e) => {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
this.setState({
|
2020-04-28 17:23:34 +08:00
|
|
|
|
pathName: e.target.value,
|
2020-03-16 14:12:11 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
render() {
|
2020-03-16 14:12:11 +08:00
|
|
|
|
let pathId = this.props.match.params.pathId;
|
|
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
let { pathName, description, point, flag_name } = this.state;
|
|
|
|
|
|
return (
|
2020-03-16 14:12:11 +08:00
|
|
|
|
<div className="newContainer">
|
|
|
|
|
|
<div className="newMain clearfix">
|
|
|
|
|
|
<div className="educontent mt10 mb50">
|
|
|
|
|
|
<div className="mb10 edu-back-white">
|
|
|
|
|
|
<p className="padding20 bor-bottom-greyE font-18 color-grey-3">{pathId ? '编辑' : '创建'}实践课程</p>
|
|
|
|
|
|
<div className="padding30-20" id="part_Name">
|
|
|
|
|
|
<p className="color-grey-6 font-16 mb15">实践课程名称</p>
|
|
|
|
|
|
<div className="df">
|
|
|
|
|
|
<span className="mr30 color-orange pt10">*</span>
|
|
|
|
|
|
<div className="flex1 mr20">
|
2020-04-28 17:23:34 +08:00
|
|
|
|
<Input className={flag_name === true ? "input-100-45 greyInput" : "input-100-45 greyInput bor-red"}
|
2020-03-16 14:12:11 +08:00
|
|
|
|
maxLength="60"
|
|
|
|
|
|
placeholder="例如:从Python程序设计-入门精通"
|
|
|
|
|
|
value={pathName}
|
|
|
|
|
|
onInput={this.InputName}
|
|
|
|
|
|
></Input>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mb10 edu-back-white padding30-20" id="part_Des">
|
|
|
|
|
|
<p className="color-grey-6 font-16 mb15">简介</p>
|
|
|
|
|
|
<div className="df">
|
|
|
|
|
|
<span className="mr30 color-orange pt10">*</span>
|
|
|
|
|
|
<div className="flex1 mr20">
|
|
|
|
|
|
<div id="shixun_introduction" className="new_li">
|
|
|
|
|
|
{/*<textarea className="input-100-45" name="description" placeholder="请在此输入实践课程的简介" value={description}></textarea>*/}
|
|
|
|
|
|
<TPMMDEditor ref={this.contentMdRef} placeholder="请在此输入实践课程的简介,最大限制8000个字符" mdID={'courseContentMD'}
|
2020-04-28 17:23:34 +08:00
|
|
|
|
refreshTimeout={1500}
|
|
|
|
|
|
className="courseMessageMD"
|
|
|
|
|
|
// initValue={this.state.description === null ? "" : this.state.description}
|
2020-03-16 14:12:11 +08:00
|
|
|
|
></TPMMDEditor>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p id="e_tip_shixun_introduction" className="edu-txt-right color-grey-cd font-12"></p>
|
|
|
|
|
|
<p id="e_tips_shixun_introduction" className="edu-txt-right color-grey-cd font-12"></p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mb10 edu-back-white padding30-20" id="part_point">
|
|
|
|
|
|
<p className="color-grey-6 font-16 mb15" id="learning_notes">学习须知</p>
|
|
|
|
|
|
<div className="df">
|
|
|
|
|
|
<span className="mr30 color-orange pt10">*</span>
|
|
|
|
|
|
<div className="flex1 mr20">
|
|
|
|
|
|
<div id="shixun_propaedeutics" className="new_li ">
|
|
|
|
|
|
{/*<textarea name="learning_notes" placeholder="请在此输入实践课程的学习须知" value={point}></textarea>*/}
|
|
|
|
|
|
<TPMMDEditor ref={this.Point_editMD} placeholder="请在此输入实践课程的学习须知,最大限制2000个字符" mdID={'Point_editMDs'}
|
2020-04-28 17:23:34 +08:00
|
|
|
|
refreshTimeout={1500}
|
|
|
|
|
|
className="courseMessageMD"
|
|
|
|
|
|
// initValue={this.state.description === null ? "" : this.state.description}
|
2020-03-16 14:12:11 +08:00
|
|
|
|
></TPMMDEditor>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p id="e_tip_shixun_propaedeutics" className="edu-txt-right color-grey-cd font-12"></p>
|
|
|
|
|
|
<p id="e_tips_shixun_propaedeutics" className="edu-txt-right color-grey-cd font-12"></p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2020-04-28 17:23:34 +08:00
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
<div className="clearfix mb30 mt30">
|
|
|
|
|
|
<button className="defalutSubmitbtn fl mr20" loading={this.state.bottonloading} onClick={this.submitNewPath}>提交</button>
|
2020-04-28 17:23:34 +08:00
|
|
|
|
{this.isEditPage ?
|
|
|
|
|
|
<Link to={`/paths/${this.props.match.params.pathId}`}
|
|
|
|
|
|
className="defalutCancelbtn fl">取消</Link>
|
2020-03-16 14:12:11 +08:00
|
|
|
|
: <Link to={`/paths`} className="defalutCancelbtn fl">取消</Link>
|
2020-04-28 17:23:34 +08:00
|
|
|
|
}
|
2020-03-16 14:12:11 +08:00
|
|
|
|
</div>
|
2020-04-28 17:23:34 +08:00
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2020-04-28 17:23:34 +08:00
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
export default PathNew;
|