From df76d7afea9c9ce7e1227a61b1be014486a9bf5a Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 3 Sep 2019 15:37:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/courses/busyWork/NewWork.js | 415 ++---------------- .../modules/courses/busyWork/NewWorkForm.js | 18 +- .../user/usersInfo/banks/HomeworkBanksEdit.js | 1 - 3 files changed, 44 insertions(+), 390 deletions(-) diff --git a/public/react/src/modules/courses/busyWork/NewWork.js b/public/react/src/modules/courses/busyWork/NewWork.js index 8000de59f..a17dc8ed2 100644 --- a/public/react/src/modules/courses/busyWork/NewWork.js +++ b/public/react/src/modules/courses/busyWork/NewWork.js @@ -7,6 +7,7 @@ import { WordsBtn, getUrl, ConditionToolTip, appendFileSizeToUploadFile, appendF , getUploadActionUrl } from 'educoder' import TPMMDEditor from '../../tpm/challengesnew/TPMMDEditor'; import CBreadcrumb from '../common/CBreadcrumb' +import NewWorkForm from './NewWorkForm' const confirm = Modal.confirm; const $ = window.$ @@ -18,15 +19,8 @@ class NewWork extends Component{ this.answerMdRef = React.createRef(); this.state={ - title_value:"", - title_num: 0, - contentFileList: [], - answerFileList: [], - workLoaded: false, - base_on_project: true, category: {}, - min_num: 2, - max_num: 10, + course_name: '' } } componentDidMount () { @@ -66,56 +60,13 @@ class NewWork extends Component{ .then((response) => { if (response.data.name) { const data = response.data; - - const contentFileList = data.attachments.map(item => { - return { - id: item.id, - uid: item.id, - name: appendFileSizeToUploadFile(item), - url: item.url, - filesize: item.filesize, - status: 'done' - } - }) - const answerFileList = data.ref_attachments.map(item => { - return { - id: item.id, - uid: item.id, - name: appendFileSizeToUploadFile(item), - url: item.url, - filesize: item.filesize, - status: 'done' - } - }) - + data.isEdit = this.isEdit this.setState({ - ...data, - // course_id: data.course_id, - // course_name: data.course_name, - // category: data.category, - title_num: parseInt(data.name.length), - workLoaded: true, - init_min_num: data.min_num, - init_max_num: data.max_num, - // description: data.description, - reference_answer: data.reference_answer, - contentFileList, - answerFileList, - }, () => { - setTimeout(() => { - this.contentMdRef.current.setValue(data.description || '') - this.answerMdRef.current.setValue(data.reference_answer || '') - - }, 2000) - - this.props.form.setFieldsValue({ - title: data.name, - description: data.description || '', - reference_answer: data.reference_answer || '', - }); - + course_id: data.course_id, + course_name: data.course_name, + category: data.category, }) - + this.newWorkFormRef.initValue(response.data) } }) .catch(function (error) { @@ -123,72 +74,15 @@ class NewWork extends Component{ }); } - // 输入title - changeTitle=(e)=>{ - console.log(e.target.value.length); - this.setState({ - title_num: parseInt(e.target.value.length) - }) + onCancel = () => { + this.props.toListPage(this.props.match.params, this.state.category.category_id) } - handleSubmit = () => { - const courseId = this.state.course_id || this.props.match.params.coursesId ; - - this.props.form.validateFieldsAndScroll((err, values) => { - console.log(values) - const mdContnet = this.contentMdRef.current.getValue().trim(); - console.log(mdContnet) - values.description = mdContnet; - // return; - - {/* max={has_commit ? init_min_num : null } */} - {/* min={has_commit ? init_max_num : (min_num == undefined ? 2 : min_num + 1) } */} - // 已有提交作品,人数范围只能扩大 - const { has_commit, max_num, init_max_num, min_num, init_min_num } = this.state; - if (has_commit) { - if (max_num < init_max_num || min_num > init_min_num) { - this.props.showNotification(`已有提交作品,人数范围只能扩大(原设置为:${init_min_num} - ${init_max_num})`) - return; - } - } - // const errKeys = Object.keys(err); // || errKeys.length == 1 && errKeys[0] == 'content' && mdContnet - if (!err) { - if (this.isEdit) { - this.doEdit(courseId, values) - } else { - this.doNew(courseId, values) - } - - } else { - $("html").animate({ scrollTop: $('html').scrollTop() - 100 }) - } - }) - } - doEdit = (courseId, values) => { + doEdit = (params) => { const workId = this.props.match.params.workId const newUrl = `/homework_commons/${workId}.json` - let attachment_ids = this.state.contentFileList.map(item => { - return item.response ? item.response.id : item.id - }) - let reference_attachment_ids = this.state.answerFileList.map(item => { - return item.response ? item.response.id : item.id - }) - - const { min_num, max_num, base_on_project, category } = this.state - const isGroup = this.props.isGroup() - axios.put(newUrl, { - type: isGroup ? 3 : 1, - name: values.title, - description: values.description, - reference_answer: values.reference_answer, - attachment_ids, - reference_attachment_ids, - - min_num, - max_num, - base_on_project - }) + axios.put(newUrl, params) .then((response) => { if (response.data.status == 0) { this.props.showNotification('保存成功') @@ -199,30 +93,11 @@ class NewWork extends Component{ console.log(error); }); } - doNew = (courseId, values) => { - const newUrl = `/courses/${courseId}/homework_commons.json` - - let attachment_ids = this.state.contentFileList.map(item => { - return item.response ? item.response.id : item.id - }) - let reference_attachment_ids = this.state.answerFileList.map(item => { - return item.response ? item.response.id : item.id - }) - const isGroup = this.props.isGroup() - const { min_num, max_num, base_on_project, category } = this.state - - axios.post(newUrl, { - type: isGroup ? 3 : 1, - name: values.title, - description: values.description, - reference_answer: values.reference_answer, - attachment_ids, - reference_attachment_ids, + doNew = (params) => { + const coursesId = this.props.match.params.coursesId + const newUrl = `/courses/${coursesId}/homework_commons.json` - min_num, - max_num, - base_on_project - }) + axios.post(newUrl, params) .then((response) => { if (response.data.status == 0) { this.props.showNotification('保存成功') @@ -265,119 +140,31 @@ class NewWork extends Component{ } } - deleteAttachment = (file, stateName) => { - // 初次上传不能直接取uid - const url = `/attachments/${file.response ? file.response.id : file.uid}.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[stateName].indexOf(file); - const newFileList = state[stateName].slice(); - newFileList.splice(index, 1); - return { - [stateName]: newFileList, - }; - }); - } - } - }) - .catch(function (error) { - console.log(error); - }); - } - max_num_change = (val) => { - if (val < 2) { - this.setState({ - max_num: 2, - }) - return; - } - const { min_num } = this.state; - this.setState({ - max_num: val, - min_num: val <= min_num ? val - 1 : min_num - }) - } - min_num_change = (val) => { - this.setState({ min_num: val }) - } - base_on_project_change = () => { - this.setState({ base_on_project: !this.state.base_on_project }) - } render(){ let {typeId,coursesId,pageType}=this.props.match.params; - const { getFieldDecorator } = this.props.form; + const isGroup = this.props.isGroup() const moduleName = !isGroup? "普通作业":"分组作业"; const moduleEngName = this.props.getModuleName() let{ - title_value, contentFileList, answerFileList, max_num, min_num, base_on_project, - init_max_num, init_min_num, - title_num, course_name, category, has_commit, has_project + course_name, category }=this.state const { current_user } = this.props - const courseId = this.state.course_id || this.props.match.params.coursesId ; + const courseId = this.state.course_id || coursesId ; const isEdit = this.isEdit; - if ((isEdit == undefined || isEdit) && !this.state.workLoaded) { - return '' - } - const uploadProps = { - width: 600, - fileList: contentFileList, - multiple: true, - // https://github.com/ant-design/ant-design/issues/15505 - // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 - // showUploadList: false, - action: `${getUploadActionUrl()}`, - onChange: this.handleContentUploadChange, - onRemove: (file) => this.onAttachmentRemove(file, 'contentFileList'), - beforeUpload: (file) => { - console.log('beforeUpload', file.name); - const isLt150M = file.size / 1024 / 1024 < 150; - if (!isLt150M) { - this.props.showNotification('文件大小必须小于150MB!'); - } - return isLt150M; - }, - }; - const answerUploadProps = { - width: 600, - fileList: answerFileList, - multiple: true, - // https://github.com/ant-design/ant-design/issues/15505 - // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 - // showUploadList: false, - action: `${getUrl()}/api/attachments.json`, - onChange: this.handleAnswerUploadChange, - onRemove: (file) => this.onAttachmentRemove(file, 'answerFileList'), - beforeUpload: (file) => { - console.log('beforeUpload', file.name); - const isLt150M = file.size / 1024 / 1024 < 150; - if (!isLt150M) { - this.props.showNotification('文件大小必须小于150MB!'); - } - return isLt150M; - }, - }; + + const common = { + onCancel:this.onCancel, + isGroup: this.props.isGroup, + doNew: this.doNew, + doEdit: this.doEdit, + } return(
-
-
-