diff --git a/public/react/src/modules/courses/busyWork/NewWork.js b/public/react/src/modules/courses/busyWork/NewWork.js index 2aa8e4742..ec7c04969 100644 --- a/public/react/src/modules/courses/busyWork/NewWork.js +++ b/public/react/src/modules/courses/busyWork/NewWork.js @@ -121,49 +121,11 @@ class NewWork extends Component{ console.log(error); }); } - - // 输入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, 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` @@ -391,156 +353,12 @@ class NewWork extends Component{

- {/* onSubmit={this.handleSubmit} */} - -
- - {getFieldDecorator('title', { - rules: [{ - required: true, message: '请输入标题' - }], - })( - - )} - - - - - { - {getFieldDecorator('description', { - rules: [{ - required: true, message: '请输入作业内容和要求' - }], - })( - - )} - } - - - (单个文件150M以内) - - - - { isGroup && - - {getFieldDecorator('personNum', { - rules: [{ - required: false - // required: true, message: '请输入最小人数和最大人数' - }], - })( -
-

- - {/* max={has_commit ? init_min_num : null } */} - - - - ~ - {/* min={has_commit ? init_max_num : (min_num == undefined ? 2 : min_num + 1) } */} - - - - -

-

- - 基于项目实施 - - - -

-
- )} -
- } - - {getFieldDecorator('reference_answer', { - rules: [{ - required: false - }], - })( - - )} - - - (单个文件150M以内) - - - -
- {/* htmlType="submit" */} - - this.props.toListPage(this.props.match.params, category.category_id)}>取消 -
-
- + {this.newWorkFormRef = ref}} + {...this.props} + onCancel={this.onCancel} + doNew={this.doNew} + doEdit={this.doEdit} + >
diff --git a/public/react/src/modules/courses/busyWork/NewWorkForm.js b/public/react/src/modules/courses/busyWork/NewWorkForm.js index c4f6c4eed..57d1666e1 100644 --- a/public/react/src/modules/courses/busyWork/NewWorkForm.js +++ b/public/react/src/modules/courses/busyWork/NewWorkForm.js @@ -10,6 +10,11 @@ import CBreadcrumb from '../common/CBreadcrumb' const confirm = Modal.confirm; const $ = window.$ const MAX_TITLE_LENGTH = 60; + +/** + 需要注意的props + isGroup +*/ class NewWorkForm extends Component{ constructor(props){ super(props); @@ -453,7 +458,7 @@ class NewWorkForm extends Component{
{/* htmlType="submit" */} - this.props.toListPage(this.props.match.params, category.category_id)}>取消 + this.props.onCancel()}>取消
diff --git a/public/react/src/modules/user/usersInfo/banks/BanksIndex.js b/public/react/src/modules/user/usersInfo/banks/BanksIndex.js index 58100c41a..6b636dca2 100644 --- a/public/react/src/modules/user/usersInfo/banks/BanksIndex.js +++ b/public/react/src/modules/user/usersInfo/banks/BanksIndex.js @@ -30,6 +30,10 @@ const GtopicBanksEdit = Loadable({ loader: () => import('./GtopicBanksEdit'), loading: Loading, }) +const HomeworkBanksEdit = Loadable({ + loader: () => import('./HomeworkBanksEdit'), + loading: Loading, +}) class BanksIndex extends Component{ constructor(props){ @@ -75,7 +79,13 @@ class BanksIndex extends Component{

- + { + return () + } + }> + { diff --git a/public/react/src/modules/user/usersInfo/banks/HomeworkBanksEdit.js b/public/react/src/modules/user/usersInfo/banks/HomeworkBanksEdit.js new file mode 100644 index 000000000..c94e8d740 --- /dev/null +++ b/public/react/src/modules/user/usersInfo/banks/HomeworkBanksEdit.js @@ -0,0 +1,100 @@ +import React, { Component } from 'react'; +import axios from 'axios' + + +import NewWorkForm from '../../../courses/busyWork/NewWorkForm' + +class HomeworkBanksEdit extends Component { + constructor(props){ + super(props); + this.state = { + isPublic: undefined, + isGroup: false + } + } + componentDidMount = () =>{ + let workId = this.props.match.params.workId; + + this.initData(workId); + } + + initData = (workId) =>{ + let url = `/homework_banks/${workId}.json`; + axios.get(url).then((result)=>{ + if(result){ + const crumbData={ + title:'编辑', + is_public:result && result.data && result.data.is_public, + crumbArray:[ + {to:`/banks/homework/${workId}/edit`,content:'详情'}, + {content:'编辑'} + ] + } + this.props.initPublic(crumbData); + result.data.isEdit = true; + result.data.ref_attachments = result.data.reference_attachments + this.setState({ isGroup: result.data.min_num || result.data.max_num }) + this.newWorkFormRef.initValue(result.data); + } + }).catch((error)=>{ + console.log(error) + }) + } + + + doNew = () => { + } + doEdit = (params) => { + const workId = this.props.match.params.workId + const newUrl = `/homework_banks/${workId}.json` + + // const isGroup = this.props.isGroup() + axios.put(newUrl, params) + .then((response) => { + if (response.data.status == 0) { + this.props.showNotification('保存成功') + this.toWorkDetail() + } + }) + .catch(function (error) { + console.log(error); + }); + } + toWorkDetail = () => { + this.props.history.push(`/banks/homework/${this.props.match.params.workId}`) + } + onCancel = () => { + this.toWorkDetail() + } + isGroup = () => { + return this.state.isGroup; + } + render(){ + let { bankId } = this.props.match.params + const common = { + onCancel:this.onCancel, + isGroup: this.isGroup, + doNew: this.doNew, + doEdit: this.doEdit, + } + return( +
+ + this.newWorkFormRef = ref} + topicId={bankId} + > +
+ ) + } +} +export default HomeworkBanksEdit; \ No newline at end of file