From a10a7608dab2aaae7040cfa47eb4dccbb76e8afa Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 24 Sep 2019 11:25:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=BB=9A=E5=8A=A8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/courses/busyWork/NewWorkForm.js | 44 ++++++++++++------- .../src/modules/courses/common/CBreadcrumb.js | 4 +- .../modules/tpm/challengesnew/TPMMDEditor.js | 18 +++++--- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/public/react/src/modules/courses/busyWork/NewWorkForm.js b/public/react/src/modules/courses/busyWork/NewWorkForm.js index bc74576d3..c52350c78 100644 --- a/public/react/src/modules/courses/busyWork/NewWorkForm.js +++ b/public/react/src/modules/courses/busyWork/NewWorkForm.js @@ -70,10 +70,23 @@ class NewWorkForm extends Component{ contentFileList, answerFileList, }, () => { - setTimeout(() => { - this.contentMdRef.current.setValue(data.description || '') - this.answerMdRef.current.setValue(data.reference_answer || '') - }, 2000) + // setTimeout(() => { + // this._scrollToTop() + // 阻止setValue的滚动 + // $(window).scroll( function() { + // $("html").scrollTop(0) + // $(window).unbind("scroll"); + // }); + /** + setValue会调用到 codemirror的 o.scrollIntoView(i), 会导致滚动条跳动 + */ + // $('.editormd').parent().css('position', 'fixed').css('left', '-1000px') + // this.contentMdRef.current.setValue(data.description || '') + // this.answerMdRef.current.setValue(data.reference_answer || '') + // setTimeout(() => { + // $('.editormd').parent().css('position', '').css('left', 'auto') + // }, 100); + // }, 500) this.props.form.setFieldsValue({ title: data.name, @@ -85,12 +98,13 @@ class NewWorkForm extends Component{ } else { // new } - this._scrollToTop() + // this._scrollToTop() } _scrollToTop = () => { - setTimeout(() => { - $("html").animate({ scrollTop: 0 }) - }, 1500) + // setTimeout(() => { + $("html").scrollTop(0) + // $("html").animate({ scrollTop: 0 }) + // }, 1000) } // 输入title @@ -303,15 +317,13 @@ class NewWorkForm extends Component{ 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, - - isEdit + title_num, course_name, category, has_commit, has_project }=this.state const { current_user } = this.props const courseId = this.state.course_id || this.props.match.params.coursesId ; - - if ((isEdit) && !this.state.workLoaded) { + this.isEdit = this.isEdit || this.props.match.url.indexOf('/edit') != -1 + if ((this.isEdit) && !this.state.description) { return '' } const uploadProps = { @@ -439,7 +451,8 @@ class NewWorkForm extends Component{ }], })( + initValue={this.state.description} noSetValueOnInit={!!this.isEdit} + className="courseMessageMD" > )} } @@ -507,7 +520,8 @@ class NewWorkForm extends Component{ }], })( + initValue={this.state.reference_answer || ''} noSetValueOnInit={!!this.isEdit} + className="courseMessageMD" refreshTimeout={1500} > )} diff --git a/public/react/src/modules/courses/common/CBreadcrumb.js b/public/react/src/modules/courses/common/CBreadcrumb.js index 6e3343edf..bf98a3a36 100644 --- a/public/react/src/modules/courses/common/CBreadcrumb.js +++ b/public/react/src/modules/courses/common/CBreadcrumb.js @@ -16,7 +16,7 @@ class CBreadcrumb extends Component{ return '' } if (item.to) { - return + return {item.name} {separator ? {separator} : @@ -24,7 +24,7 @@ class CBreadcrumb extends Component{ } } else { - return {item.name} + return {item.name} } })}

diff --git a/public/react/src/modules/tpm/challengesnew/TPMMDEditor.js b/public/react/src/modules/tpm/challengesnew/TPMMDEditor.js index 91cb34954..5d54f514b 100644 --- a/public/react/src/modules/tpm/challengesnew/TPMMDEditor.js +++ b/public/react/src/modules/tpm/challengesnew/TPMMDEditor.js @@ -236,19 +236,24 @@ export default class TPMMDEditor extends Component { setTimeout(() => { if (that.props.needRecreate == true) { - __editorName.recreate() + __editorName.recreate() // 注意 必须在setValue之前触发,不然会清空 } else { __editorName.resize() } console.log('timeout', __editorName.id) __editorName.cm && __editorName.cm.refresh() }, that.props.refreshTimeout || 500) - if (that.props.initValue != undefined && that.props.initValue != '') { - __editorName.setValue(that.props.initValue) - } - if (that.state.initValue) { - __editorName.setValue(that.state.initValue) + if (this.props.noSetValueOnInit) { + that.onEditorChange() + } else { + if (that.props.initValue != undefined && that.props.initValue != '') { + __editorName.setValue(that.props.initValue) + } + if (that.state.initValue) { + __editorName.setValue(that.state.initValue) + } } + __editorName.cm.on("change", (_cm, changeObj) => { that.contentChanged = true; if (that.state.showError) { @@ -277,6 +282,7 @@ export default class TPMMDEditor extends Component { onEditorChange = () => { if (!this.answers_editormd) return; const val = this.answers_editormd.getValue(); + //console.log('onEditorChange', this.props.id, val) try { this.props.onChange && this.props.onChange(val) } catch(e) {