diff --git a/public/react/config/webpack.config.dev.js b/public/react/config/webpack.config.dev.js index 1adf3aef9..eaacd9f1e 100644 --- a/public/react/config/webpack.config.dev.js +++ b/public/react/config/webpack.config.dev.js @@ -32,7 +32,7 @@ module.exports = { // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.s // devtool: "cheap-module-eval-source-map", // 开启调试 - // devtool: "source-map", // 开启调试 + // devtool: "source-map", // 开启调试 // These are the "entry points" to our application. // This means they will be the "root" imports that are included in JS bundle. // The first two entry points enable "hot" CSS and auto-refreshes for JS. diff --git a/public/react/src/modules/courses/Index.js b/public/react/src/modules/courses/Index.js index 9f278e807..bfe82dad4 100644 --- a/public/react/src/modules/courses/Index.js +++ b/public/react/src/modules/courses/Index.js @@ -283,6 +283,11 @@ const Completetaskpage =Loadable({ loader: () => import('../../modules/courses/completetaskdetails/Completetaskpage'), loading: Loading, }); +//问卷编辑 +const PollNewQuestbank =Loadable({ + loader: () => import('../../modules/courses/poll/PollNewQuestbank'), + loading: Loading, +}); class CoursesIndex extends Component{ constructor(props) { super(props) @@ -461,13 +466,19 @@ class CoursesIndex extends Component{ // console.log(commons) return ( + {/*题库问卷编辑详情*/} + () + } + > {/*毕设任务题库详情*/} () } > - {/*毕设内容题库详情*/} + {/*毕设选题题库详情*/} () diff --git a/public/react/src/modules/courses/busyWork/CommonWorkPost.js b/public/react/src/modules/courses/busyWork/CommonWorkPost.js index 1859d6b70..796249bcd 100644 --- a/public/react/src/modules/courses/busyWork/CommonWorkPost.js +++ b/public/react/src/modules/courses/busyWork/CommonWorkPost.js @@ -320,8 +320,11 @@ class CommonWorkPost extends Component{ // ModalSave: ()=>this.deleteAttachment(file), // ModalCancel:this.cancelAttachment // }) - this.deleteAttachment(file) - return false; + if(file.response!=undefined){ + this.deleteAttachment(file) + return false; + } + } cancelAttachment=()=>{ diff --git a/public/react/src/modules/courses/busyWork/NewWork.js b/public/react/src/modules/courses/busyWork/NewWork.js index 09b029044..2aa8e4742 100644 --- a/public/react/src/modules/courses/busyWork/NewWork.js +++ b/public/react/src/modules/courses/busyWork/NewWork.js @@ -3,11 +3,11 @@ import { Input, InputNumber, Form, Button, Checkbox, Upload, Icon, message, Moda import axios from 'axios' import '../css/busyWork.css' import '../css/Courses.css' -import { WordsBtn, getUrl, ConditionToolTip } from 'educoder' - +import { WordsBtn, getUrl, ConditionToolTip, appendFileSizeToUploadFile, appendFileSizeToUploadFileAll } from 'educoder' +import TPMMDEditor from '../../tpm/challengesnew/TPMMDEditor'; import CBreadcrumb from '../common/CBreadcrumb' -import NewWorkForm from './NewWorkForm' +const confirm = Modal.confirm; const $ = window.$ const MAX_TITLE_LENGTH = 60; class NewWork extends Component{ @@ -17,6 +17,15 @@ 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, } } componentDidMount () { @@ -41,6 +50,7 @@ class NewWork extends Component{ course_id: data.course_id, course_name: data.course_name, category: data.category, + }) } }) @@ -55,26 +65,129 @@ class NewWork extends Component{ .then((response) => { if (response.data.name) { const data = response.data; - data.isEdit = true; - this.setState({ - category: data.category, - course_id: data.course_id, - course_name: data.course_name, + + 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' + } }) - this.newWorkFormRef.initValue(data); + + 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 || '', + }); + + }) + } }) .catch(function (error) { console.log(error); }); } - - doEdit = (params) => { + + // 输入title + changeTitle=(e)=>{ + console.log(e.target.value.length); + this.setState({ + title_num: parseInt(e.target.value.length) + }) + } + 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) => { 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, params) + 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 + }) .then((response) => { if (response.data.status == 0) { this.props.showNotification('保存成功') @@ -85,11 +198,30 @@ class NewWork extends Component{ console.log(error); }); } - doNew = (params) => { - const courseId = this.props.match.params.coursesId ; + doNew = (courseId, values) => { const newUrl = `/courses/${courseId}/homework_commons.json` - axios.post(newUrl, params) + 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, + + min_num, + max_num, + base_on_project + }) .then((response) => { if (response.data.status == 0) { this.props.showNotification('保存成功') @@ -100,26 +232,147 @@ class NewWork extends Component{ console.log(error); }); } + + handleContentUploadChange = (info) => { + let contentFileList = info.fileList; + this.setState({ contentFileList: appendFileSizeToUploadFileAll(contentFileList) }); + } + handleAnswerUploadChange = (info) => { + let answerFileList = info.fileList; + this.setState({ answerFileList: appendFileSizeToUploadFileAll(answerFileList) }); + } + onAttachmentRemove = (file, stateName) => { + if(file.response!=undefined){ + this.props.confirm({ + content: '是否确认删除?', + + onOk: () => { + this.deleteAttachment(file, stateName) + }, + onCancel() { + console.log('Cancel'); + }, + }); + + + return false; + } + + } + 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{ - category + 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 }=this.state const { current_user } = this.props - const courseId = this.props.match.params.coursesId ; + const courseId = this.state.course_id || this.props.match.params.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: `${getUrl()}/api/attachments.json`, + 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) { + message.error('文件大小必须小于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) { + message.error('文件大小必须小于150MB!'); + } + return isLt150M; + }, + }; + return(
- + {/*

+ {course_name} + > + {typeId==1 ?"普通作业":"分组作业"} + > + {pageType==="new"?"新建":"编辑"} +

*/}

- {this.newWorkFormRef = ref}} - {...this.props} - onSave={this.onSave} - doNew={this.doNew} - doEdit={this.doEdit} - > + {/* 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以内) + + + + + +
) } } -export default NewWork; \ No newline at end of file +const WrappedBoardsNew = Form.create({ name: 'NewWork' })(NewWork); +export default WrappedBoardsNew; \ No newline at end of file diff --git a/public/react/src/modules/courses/completetaskdetails/Completetaskdetails.js b/public/react/src/modules/courses/completetaskdetails/Completetaskdetails.js index 850ed2b89..05bb600e9 100644 --- a/public/react/src/modules/courses/completetaskdetails/Completetaskdetails.js +++ b/public/react/src/modules/courses/completetaskdetails/Completetaskdetails.js @@ -57,20 +57,22 @@ class Groupjobbandetails extends Component { render() { - + let{datas}=this.props; return (
-
+
+ + {datas.attachments === undefined ? "" : datas.attachments.map((item, key) => { + return ( + + ) + })} + + - -
diff --git a/public/react/src/modules/courses/completetaskdetails/Completetaskpage.js b/public/react/src/modules/courses/completetaskdetails/Completetaskpage.js index d7cd7a62c..c09e8cf66 100644 --- a/public/react/src/modules/courses/completetaskdetails/Completetaskpage.js +++ b/public/react/src/modules/courses/completetaskdetails/Completetaskpage.js @@ -18,17 +18,20 @@ class Completetaskpage extends Component { constructor(props) { super(props); // this.answerMdRef = React.createRef(); - this.setState({ + this.state={ workid:1, isSpin:false, datas:[], - }) + } } componentDidMount() { // console.log("父组件加载框"); + this.getonedata(); + } + getonedata(){ if( this.props.match.params.workid){ this.setState({ workid: this.props.match.params.workid, @@ -47,13 +50,13 @@ class Completetaskpage extends Component { this.setState({ isSpin:true, }) - let url = `/homework_banks/${workids}.json`; + let url = `/task_banks/${workids}.json`; // axios.get(url).then((response) => { if(response){ if(response.data){ this.setState({ - datas:response.data.informs, + datas:response.data, }) }else { this.setState({ @@ -86,6 +89,7 @@ class Completetaskpage extends Component { ///////////////教师截止 render() { + let{datas}=this.state; const isAdmin = this.props.isAdmin(); // console.log(119) @@ -108,10 +112,10 @@ class Completetaskpage extends Component {

- MySQL数据库编程开发实训(基础篇) + {datas&&datas.name}

@@ -126,7 +130,7 @@ class Completetaskpage extends Component {
- + diff --git a/public/react/src/modules/courses/comtopicdetails/CompletetopicdePage.js b/public/react/src/modules/courses/comtopicdetails/CompletetopicdePage.js index cde4f5f5e..d952b82aa 100644 --- a/public/react/src/modules/courses/comtopicdetails/CompletetopicdePage.js +++ b/public/react/src/modules/courses/comtopicdetails/CompletetopicdePage.js @@ -19,11 +19,11 @@ class CompletetopicdePage extends Component { constructor(props) { super(props); // this.answerMdRef = React.createRef(); - this.setState({ + this.state={ workid:1, isSpin:false, datas:[], - }) + } } @@ -48,13 +48,13 @@ class CompletetopicdePage extends Component { this.setState({ isSpin:true, }) - let url = `/homework_banks/${workids}.json`; + let url = `/gtopic_banks/${workids}.json`; // axios.get(url).then((response) => { if(response){ if(response.data){ this.setState({ - datas:response.data.informs, + datas:response.data, }) }else { this.setState({ @@ -88,7 +88,7 @@ class CompletetopicdePage extends Component { ///////////////教师截止 render() { - + let{datas}=this.state; const isAdmin = this.props.isAdmin(); // console.log(119) @@ -110,10 +110,10 @@ class CompletetopicdePage extends Component {

- MySQL数据库编程开发实训(基础篇) + {datas&&datas.name}

@@ -128,7 +128,7 @@ class CompletetopicdePage extends Component { - + {/*{parseInt(tab) === 1 ? :""}*/} diff --git a/public/react/src/modules/courses/comtopicdetails/Completetopicdetails.js b/public/react/src/modules/courses/comtopicdetails/Completetopicdetails.js index 15b4c24cf..5b15bc7f6 100644 --- a/public/react/src/modules/courses/comtopicdetails/Completetopicdetails.js +++ b/public/react/src/modules/courses/comtopicdetails/Completetopicdetails.js @@ -56,52 +56,52 @@ class Completetopicdetails extends Component { render() { - + let{datas}=this.props; return (
-
+
- + {datas.attachment_list === undefined ? "" : datas.attachment_list.map((item, key) => { + return ( + + ) + })}

课题类型: - 设计 + {datas&&datas.topic_type===1?"设计":datas&&datas.topic_type===2?"论文":datas&&datas.topic_type===3?"创作":"设计"}

课题来源: - 生产/社会实践 + {datas&&datas.topic_source===1?"生产/社会实际":datas&&datas.topic_source===2?"结合科研":datas&&datas.topic_source===3?"其它":"生产/社会实际"}

课题性质1: - 设计 + {datas&&datas.topic_property_first===1?"真题":datas&&datas.topic_property_first===2?"模拟题":"真题"}

课题性质2: - 设计 + {datas&&datas.topic_property_second===1?"纵向课题":datas&&datas.topic_property_second===2?"横向课题":datas&&datas.topic_property_second===3?"自选":"纵向课题"}

课题重复情况: - 新需求 + {datas&&datas.topic_repeat===1?"新题":datas&&datas.topic_repeat===2?"往届题,有新要求":datas&&datas.topic_repeat===3?"往届题,无新要求":"新题"}

调研或实习地点: - 长沙 + {datas&&datas.province}{datas&&datas.city}

课题单位来源: - 湖南省据C++创始人Stroustrup有限公司 + {datas&&datas.source_unit}

diff --git a/public/react/src/modules/courses/coursesPublic/AccessoryModal.js b/public/react/src/modules/courses/coursesPublic/AccessoryModal.js index 71d92cd0c..82cf1cea9 100644 --- a/public/react/src/modules/courses/coursesPublic/AccessoryModal.js +++ b/public/react/src/modules/courses/coursesPublic/AccessoryModal.js @@ -73,8 +73,9 @@ class AccessoryModal extends Component{ // ModalCancel:this.cancelAttachment // }) // return false; - - this.deleteAttachment(file); + if(file.response!=undefined){ + this.deleteAttachment(file); + } } diff --git a/public/react/src/modules/courses/coursesPublic/AccessoryModal2.js b/public/react/src/modules/courses/coursesPublic/AccessoryModal2.js index 6808ded8a..efec92e0a 100644 --- a/public/react/src/modules/courses/coursesPublic/AccessoryModal2.js +++ b/public/react/src/modules/courses/coursesPublic/AccessoryModal2.js @@ -64,8 +64,10 @@ class AccessoryModal2 extends Component{ // ModalCancel:this.cancelAttachment // }) // return false; + if(file.response!=undefined){ + this.deleteAttachment(file); + } - this.deleteAttachment(file); } diff --git a/public/react/src/modules/courses/coursesPublic/SelectSetting.js b/public/react/src/modules/courses/coursesPublic/SelectSetting.js index 2870c5d12..b3c85838d 100644 --- a/public/react/src/modules/courses/coursesPublic/SelectSetting.js +++ b/public/react/src/modules/courses/coursesPublic/SelectSetting.js @@ -296,37 +296,39 @@ class Selectsetting extends Component{ onAttachmentRemove = (file) => { + if(file.response!=undefined){ + 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) { - // const url = `/attachments/${file.response ? file.response.id : file.uid}.json` - 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) { - - this.setState({ - fileListtype:false, - fileList:[] - }) - // this.setState((state) => { - // const index = state.fileList.indexOf(file); - // const newFileList = state.fileList.slice(); - // newFileList.splice(index, 1); - // return { - // fileList: newFileList, - // }; - // }); + this.setState({ + fileListtype:false, + fileList:[] + }) + // this.setState((state) => { + // const index = state.fileList.indexOf(file); + // const newFileList = state.fileList.slice(); + // newFileList.splice(index, 1); + // return { + // fileList: newFileList, + // }; + // }); + } } - } + }) + .catch(function (error) { + console.log(error); + }); + this.setState({ + fileListtype:false, }) - .catch(function (error) { - console.log(error); - }); - this.setState({ - fileListtype:false, - }) + } + // const url = `/attachments/${file.response ? file.response.id : file.uid}.json` + } onChangeTimepublishs= (date, dateString,key) => { diff --git a/public/react/src/modules/courses/coursesPublic/sendResource.js b/public/react/src/modules/courses/coursesPublic/sendResource.js index 715e4acf9..2b7b63e99 100644 --- a/public/react/src/modules/courses/coursesPublic/sendResource.js +++ b/public/react/src/modules/courses/coursesPublic/sendResource.js @@ -132,28 +132,29 @@ class Sendresource extends Component{ onAttachmentRemove = (file) => { -debugger - 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) { - this.setState({ - fileListtype:false, - fileList:[] - }) - } - - } - }) - .catch(function (error) { - console.log(error); - }); - this.setState({ - fileListtype:false, - }) + if(file.response!=undefined){ + 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) { + this.setState({ + fileListtype:false, + fileList:[] + }) + } + + } + }) + .catch(function (error) { + console.log(error); + }); + this.setState({ + fileListtype:false, + }) + } } ModalCancelModalCancel=()=>{ diff --git a/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitedit.js b/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitedit.js index ce704ef6e..467fdce25 100644 --- a/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitedit.js +++ b/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitedit.js @@ -157,49 +157,52 @@ class GraduationTasksSubmitedit extends Component{ } onAttachmentRemove = (file) => { - let {attachments,fileList}=this.state; - const url = `/attachments/${file}.json` - axios.delete(url, { - }) - .then((response) => { - if (response.data) { - // const { status } = response.data; - if (response.data.status === 0) { - console.log('--- success') - let newattachments=attachments; - if(file.uid===undefined){ - for(var i=0; i { + if (response.data) { + // const { status } = response.data; + if (response.data.status === 0) { + console.log('--- success') + let newattachments=attachments; + if(file.uid===undefined){ + for(var i=0; i { - const index = state.fileList.indexOf(file); - const newFileList = state.fileList.slice(); - newFileList.splice(index, 1); - return { - fileList: newFileList, - }; - }); - } - } - }) - .catch(function (error) { - console.log(error); - }); + this.setState((state) => { + const index = state.fileList.indexOf(file); + const newFileList = state.fileList.slice(); + newFileList.splice(index, 1); + return { + fileList: newFileList, + }; + }); + } + } + }) + .catch(function (error) { + console.log(error); + }); + } + } inputSearchValue=(e)=>{ diff --git a/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitnew.js b/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitnew.js index 3c8318796..3dc1d699f 100644 --- a/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitnew.js +++ b/public/react/src/modules/courses/graduation/tasks/GraduationTasksSubmitnew.js @@ -146,14 +146,16 @@ class GraduationTasksSubmitnew extends Component{ // }, // }); // return false; + if(file.response!=undefined){ + this.setState({ + Modalstype:true, + Modalstopval:'确定要删除这个附件吗?', + ModalSave: ()=>this.deleteAttachment(file), + ModalCancel:this.cancelAttachment + }) + return false; + } - this.setState({ - Modalstype:true, - Modalstopval:'确定要删除这个附件吗?', - ModalSave: ()=>this.deleteAttachment(file), - ModalCancel:this.cancelAttachment - }) - return false; } cancelAttachment=()=>{ diff --git a/public/react/src/modules/courses/graduation/tasks/GraduationTasksnew.js b/public/react/src/modules/courses/graduation/tasks/GraduationTasksnew.js index fae87fb65..f7914bf2a 100644 --- a/public/react/src/modules/courses/graduation/tasks/GraduationTasksnew.js +++ b/public/react/src/modules/courses/graduation/tasks/GraduationTasksnew.js @@ -173,30 +173,33 @@ class GraduationTasksnew extends Component { } onAttachmentRemove = (file) => { - const url = `/attachments/${file.response ? file.response.id : file.uid}.json` - // const url = `/attachments/${file}.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, - }; - }); - this.cancelAttachment() + if(file.response!=undefined){ + const url = `/attachments/${file.response ? file.response.id : file.uid}.json` + // const url = `/attachments/${file}.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, + }; + }); + this.cancelAttachment() + } } - } - }) - .catch(function (error) { - console.log(error); - }); + }) + .catch(function (error) { + console.log(error); + }); + } + } //滚动 diff --git a/public/react/src/modules/courses/groupjobbank/GroupPackage.js b/public/react/src/modules/courses/groupjobbank/GroupPackage.js index 8014585d1..73132b3fa 100644 --- a/public/react/src/modules/courses/groupjobbank/GroupPackage.js +++ b/public/react/src/modules/courses/groupjobbank/GroupPackage.js @@ -21,7 +21,9 @@ class GroupPackage extends Component { } } - + DownloadOpenPdf=(type,url)=>{ + type===true?window.open(url):window.location.href=url; + } componentDidMount() { console.log("Groupjobquesanswer"); console.log("componentDidMount"); @@ -54,9 +56,9 @@ class GroupPackage extends Component { render() { - + let{attachments}=this.props; return ( -
+ ) diff --git a/public/react/src/modules/courses/groupjobbank/GroupPackage2.js b/public/react/src/modules/courses/groupjobbank/GroupPackage2.js index 6a48a51c8..349c2b97e 100644 --- a/public/react/src/modules/courses/groupjobbank/GroupPackage2.js +++ b/public/react/src/modules/courses/groupjobbank/GroupPackage2.js @@ -54,18 +54,42 @@ class GroupPackage extends Component { render() { + let{datas,bool}=this.props; return ( + bool===true? +
-

- 分组要求: - 2~ 5(学生提交作品时需要关联同组成员,组内成员作品共享) -

+ { + datas===undefined?"":datas.min_num===undefined||datas.max_num===undefined?"":datas.min_num===null||datas.max_num===null?"": +

+ 分组要求: + {datas&&datas.min_num}~ {datas&&datas.max_num}(学生提交作品时需要关联同组成员,组内成员作品共享) +

+ }

基于项目实施 (学生必须在本平台创建项目,项目管理员可以提交作品)

+ :
+ { + datas===undefined?"":datas.group_info===undefined?"":datas.group_info.min_number===undefined||datas.group_info.max_number===undefined?"": + datas.group_info.min_number===null||datas.group_info.max_number===null?"": +

+ 分组要求: + {datas&&datas.group_info&&datas.group_info.min_number}~ {datas&&datas.group_info&&datas.group_info.max_number}(学生提交作品时需要关联同组成员,组内成员作品共享) +

+ } + { + datas&&datas.group_info&&datas.group_info.base_on_project? +

+ 基于项目实施 + (学生必须在本平台创建项目,项目管理员可以提交作品) +

+ :"" + } +
) } } diff --git a/public/react/src/modules/courses/groupjobbank/Groupjobbandetails.js b/public/react/src/modules/courses/groupjobbank/Groupjobbandetails.js index 772752def..6b3e817c1 100644 --- a/public/react/src/modules/courses/groupjobbank/Groupjobbandetails.js +++ b/public/react/src/modules/courses/groupjobbank/Groupjobbandetails.js @@ -57,20 +57,21 @@ class Groupjobbandetails extends Component { render() { + let{datas}=this.props; return (
-
+
- + {datas.attachments === undefined ? "" : datas.attachments.map((item, key) => { + return ( + + ) + })} - +
diff --git a/public/react/src/modules/courses/groupjobbank/GroupjobbankPage.js b/public/react/src/modules/courses/groupjobbank/GroupjobbankPage.js index 27827eb28..60255ad7b 100644 --- a/public/react/src/modules/courses/groupjobbank/GroupjobbankPage.js +++ b/public/react/src/modules/courses/groupjobbank/GroupjobbankPage.js @@ -14,6 +14,7 @@ import "../common/formCommon.css"; import '../css/Courses.css'; import '../css/busyWork.css'; import '../poll/pollStyle.css'; +import Generaljobdetails from "../questionbank/Generaljobdetails"; class GroupjobbankPage extends Component { //分组作业内容详情 @@ -43,7 +44,7 @@ class GroupjobbankPage extends Component { console.log(e); console.log("44"); } - + this.getonedata(); } @@ -64,6 +65,9 @@ class GroupjobbankPage extends Component { this.setState({ shixuntypes: types[3] }) + this.getonedata(); + } + getonedata=()=>{ if( this.props.match.params.workid){ this.setState({ workid: this.props.match.params.workid, @@ -88,7 +92,7 @@ class GroupjobbankPage extends Component { if(response){ if(response.data){ this.setState({ - datas:response.data.informs, + datas:response.data, }) }else { this.setState({ @@ -120,7 +124,7 @@ class GroupjobbankPage extends Component { ///////////////教师截止 render() { - let {tab} = this.state; + let {tab,datas} = this.state; const isAdmin = this.props.isAdmin(); // console.log(119) @@ -143,10 +147,10 @@ class GroupjobbankPage extends Component {

- MySQL数据库编程开发实训(基础篇) + {datas&&datas.name}

@@ -155,15 +159,15 @@ class GroupjobbankPage extends Component {
- {parseInt(tab) === 0 ? :""} - {parseInt(tab) === 1 ? :""} + {parseInt(tab) === 0 ? :""} + {parseInt(tab) === 1 ? :""}
diff --git a/public/react/src/modules/courses/groupjobbank/Groupjobquesanswer.js b/public/react/src/modules/courses/groupjobbank/Groupjobquesanswer.js index c6a0f787f..f0b2be9cd 100644 --- a/public/react/src/modules/courses/groupjobbank/Groupjobquesanswer.js +++ b/public/react/src/modules/courses/groupjobbank/Groupjobquesanswer.js @@ -56,20 +56,20 @@ class Groupjobquesanswer extends Component { render() { - + let{datas}=this.props; return (
-
+
- + {datas.attachments === undefined ? "" : datas.attachments.map((item, key) => { + return ( + + ) + })} - +
diff --git a/public/react/src/modules/courses/members/modal/CreateGroupByImportModal.js b/public/react/src/modules/courses/members/modal/CreateGroupByImportModal.js index 9b3d72e00..77a41e47d 100644 --- a/public/react/src/modules/courses/members/modal/CreateGroupByImportModal.js +++ b/public/react/src/modules/courses/members/modal/CreateGroupByImportModal.js @@ -73,18 +73,21 @@ class CreateGroupByImportModal extends Component{ } onAttachmentRemove = (file) => { - this.props.confirm({ - content: '是否确认删除?', - - onOk: () => { - this.deleteAttachment(file) - }, - onCancel() { - console.log('Cancel'); - }, - }); - - return false; + if(file.response!=undefined){ + this.props.confirm({ + content: '是否确认删除?', + + onOk: () => { + this.deleteAttachment(file) + }, + onCancel() { + console.log('Cancel'); + }, + }); + + return false; + } + } deleteAttachment = (file) => { const url = `/attachments/${file.response ? file.response.id : file.uid}.json` diff --git a/public/react/src/modules/courses/poll/PollNewQuestbank.js b/public/react/src/modules/courses/poll/PollNewQuestbank.js new file mode 100644 index 000000000..de9d461dc --- /dev/null +++ b/public/react/src/modules/courses/poll/PollNewQuestbank.js @@ -0,0 +1,3567 @@ +import React, {Component} from "react"; +import {Form, Input, Tooltip, Checkbox, Radio, Select, message, Modal, Button} from 'antd' +import {WordsBtn, ActionBtn} from 'educoder' + +import {Link} from 'react-router-dom' + +import '../css/members.css' +import "../common/formCommon.css" + +import './pollStyle.css' +import '../css/Courses.css' +import axios from 'axios' +import moment from "../new/CoursesNew"; +import Modals from "../../modals/Modals"; +import PollListItem from "./PollListItem"; + +const TextArea = Input.TextArea +const RadioGroup = Radio.Group +const CheckboxGroup = Checkbox.Group +const Option = Select.Option; +const maps = {1: "未发布", 2: "提交中", 3: "已截止"} +const confirm = Modal.confirm; + +class PollNewQuestbank extends Component { + // 问卷新建和编辑 + // + // * addonAfter 字数限制 + // * q_counts 题目总数 + // * mysingles 单选题数量 + // * mydoubles 多选题数量 + // * mymainsint 主观题数量 + // * adddom 添加编辑的数据 页面点击新增题目 + // * editentry 编辑条目 新增的题目点击到条目中 + //* questionnair 问卷是否存在 默认不存在 + // * + + constructor(props) { + super(props); + this.state = { + visible: false, + poll_questions: [], + user_permission: "", + addonAfter: 0, + addonAftertwo: 100, + mysingles: 0, + mydoubles: 0, + mymainsint: 0, + adddom: [], + editentry: [], + questionnair: false, + polls_name: undefined, + polls_nametest: "", + polls_description: "", + polls_descriptiontest: "", + storagedesc:"", + storagedesctwo:"", + coursesId: "", + pollid: undefined, + polls_status: undefined, + q_countst: 0, + Newedit: true, + Insertposition: undefined, + Modalstype: false, + mysave: false, + readOnlys: "readOnly", + problemtopic: null, + problemtopicbool: false, + newoption: false, + cancellation: false, + bindingid:undefined, + Newdisplay:false, + first_category_url:"", + left_banner_id:"", + } + // console.log("试卷新建和编辑"); + // console.log(JSON.stringify(props)); + + } + + changeTopicName = (e) => { + // console.log("调用了changeTopicName"); + let num = parseInt(e.target.value.length); + if(num>60){ + return; + } + this.setState({ + addonAfter: num < 0 ? 0 : num + }); + this.setState({ + polls_nametest: e.target.value + }) + } + + + changeTopicNametwo = (e) => { + // console.log("获取的值" + e.target.value); + let num = 100 - parseInt(e.target.value.length); + this.setState({ + addonAftertwo: num < 0 ? 0 : num + }) + this.setState({ + polls_descriptiontest: e.target.value + }) + } + + // 初始化数据 + componentDidMount = () => { + // console.log("componentDidMount 50") + if( this.props.isStudent() === true){ + + this.props.history.push("/403") + + return + } + // if (this.props.match.params.news !== undefined) { + // if (this.props.match.params.news === "new") { + // this.state.Newedit === true; + // this.setState({ + // Newedit: true, + // mysave: true, + // readOnlys: "", + // cancellation: true, + // }) + // } else { + this.Initializatio_data(); + this.state.Newedit === false; + this.setState({ + Newedit: false, + mysave: false, + readOnlys: "readOnly", + }) + // } + // } + + console.log("问卷返回"); + console.log(this.props); + try { + if(this.props.current_user!==undefined){ + this.setState({ + first_category_url :this.props.current_user.first_category_url, + }); + console.log("======================="); + console.log(this.props.current_user.first_category_url); + } + }catch (e) { + console.log("12312312312") + console.log(e); + } + + }; + componentDidUpdate = (prevProps) => { + // console.log("componentDidUpdate"); + // console.log(prevProps); + // console.log(this.props); + if(prevProps.current_user!=this.props.current_user){ + if(this.props.current_user!==undefined){ + // console.log(this.props.current_user.login); + // console.log(prevProps.current_user.login); + this.setState({ + first_category_url :this.props.current_user.first_category_url, + }) + } + } + } + + //获取权限 + // getPollInfo(){ + // // console.log(this.props.match); + // let pollId=this.props.match.params.pollId; + // let url=`/polls/${pollId}/common_header.json` + // axios.get(url).then((result)=>{ + // if(result.status==200){ + // this.setState({ + // pollDetail:result.data, + // user_permission:result.data.user_permission + // }) + // } + // }).catch((error)=>{ + // console.log(error); + // }) + // } + //初始化请求网络 + Initializatio_data = () => { + console.log("Initializatio_data 582") + //课堂id + let coursesId = this.props.match.params.coursesId; + //时间id + let pollid = this.props.match.params.workid; + console.log(pollid); + // let coursesId = 557; + if (pollid === undefined) { + // console.log("没有问卷新建问卷~~~") + // let coursesId=this.props.match.params.coursesId; + // // to={`/courses/${coursesId}/polls/new`} + // + // const urll = `/courses/${coursesId}/polls/new.json` + // axios.get(urll).then((result) => { + // if (result.status === 200) { + // console.log(urll) + // console.log("问卷新建成功") + // console.log(JSON.stringify(result)) + // // var path=`/courses/${coursesId}/polls/new`; + // // + // // this.props.history.push({ pathname: path, state: { } }); + // } + // }).catch((error) => { + // console.log(error) + // }) + + // const urlls = `/courses/${coursesId}/polls.json` + // axios.post(urlls,{ + // polls_name: "这是标题", + // polls_description:"这是标题须知" + // }).then((result)=>{ + // console.log("创建问卷++++++") + // console.log(result) + // try { + // if(result.data.status===0){ + // console.log("创建问卷") + // console.log(JSON.stringify(result.data)) + // } + // }catch (e) { + // + // } + // + // }) + //没有问卷 + this.setState({ + projects: [], + polls_name: "", + polls_description: "", + poll_questions: [], + question_types: [], + pollid: undefined, + mysingles: 0, + mydoubles: 0, + mymainsint: 0, + polls_nametest: "", + polls_descriptiontest: "", + coursesId: 0, + questionnair: false + }) + } else { + const url = `/exercise_banks/${pollid}.json`; + axios.get(url).then((result) => { + if (result) + console.log("247"); + console.log(result); + + // if(result.data){ + // if(result.data.poll){ + // if(result.data.poll.polls_name){ + // let num = parseInt(result.data.poll.polls_name.length); + // this.setState({ + // addonAfter: num < 0 ? 0 : num + // }) + // } + // } + // + // } + // + // this.setState({ + // projects: result.data, + // pollid: pollid, + // polls_status: result.data.poll.polls_status, + // polls_name: result.data.poll.polls_name, + // polls_description: result.data.poll.polls_description, + // poll_questions: result.data.poll_questions, + // question_types: result.data.question_types, + // mysingles: result.data.question_types.q_singles, + // mydoubles: result.data.question_types.q_doubles, + // mymainsint: result.data.question_types.q_mains, + // polls_nametest: result.data.poll.polls_name, + // polls_descriptiontest: result.data.poll.polls_description, + // questionnair: true, + // left_banner_id:result.data.left_banner_id + // }) + + }).catch((error) => { + console.log(error) + }) + } + + } + + //重新获取数据 + thisinitializationdatanew = () => { + var pollidsy = null; + if (this.state.pollid !== undefined) { + pollidsy = this.state.pollid; + if (pollidsy === null || pollidsy === undefined) { + pollidsy = this.props.match.params.workid; + } + } + + if (pollidsy === null || pollidsy === undefined) { + return + } + + const url = `/exercise_banks/${pollidsy}.json`; + axios.get(url).then((result) => { + if (result !== undefined){ + + } + + // console.log("有问卷~~~") + + // this.setState({ + // projects: result.data, + // pollid: pollidsy, + // polls_status: result.data.poll.polls_status, + // polls_name: result.data.poll.polls_name, + // polls_description: result.data.poll.polls_description, + // poll_questions: result.data.poll_questions, + // question_types: result.data.question_types, + // mysingles: result.data.question_types.q_singles, + // mydoubles: result.data.question_types.q_doubles, + // mymainsint: result.data.question_types.q_mains, + // polls_nametest: result.data.poll.polls_name, + // polls_descriptiontest: result.data.poll.polls_description, + // questionnair: true, + // }) + + // } + }).catch((error) => { + console.log(error) + }) + } + //新建问卷 + newword = () => { + if (this.state.polls_nametest === undefined || this.state.polls_nametest === "") { + this.props.showNotification(`请输入标题`); + return + } + let coursesId = this.props.match.params.coursesId; + const urlls = `/courses/${coursesId}/polls.json` + axios.post(urlls, { + polls_name: this.state.polls_nametest, + polls_description: this.state.polls_descriptiontest + }).then((result) => { + if (result.data.status === 0) { + this.state.Newedit === false; + // this.props.showNotification(`试卷创建成功`); + this.setState({ + pollid: result.data.data.id, + Newedit: false, + }) + this.props.history.push(`/courses/${this.props.match.params.coursesId}/polls/${result.data.data.id}/detail?tab=2`) + } + }) + } + //添加单选题目 + addmysingles = () => { + + if (this.state.newoption === true) { + this.setState({ + newoption: false + }) + } + this.setState({ + Newdisplay:true, + }) + var Insertposition = this.state.poll_questions.length; + // console.log(JSON.stringify(this.state.poll_questions)); + for (var i = 0; i < this.state.poll_questions.length; i++) { + if (this.state.poll_questions[i].question.question_type === 1) { + Insertposition = i; + } + + } + this.addMytopic(1, this.state.pollid, Insertposition, false, 0); + // } + } + + //添加多选题目 + addmydoubles = () => { + // console.log("addmymainsint 70") + if (this.state.newoption === true) { + this.setState({ + newoption: false + }) + } + this.setState({ + Newdisplay:true, + }) + var Insertposition = this.state.poll_questions.length; + // console.log(JSON.stringify(this.state.poll_questions)); + for (var i = 0; i < this.state.poll_questions.length; i++) { + if (this.state.poll_questions[i].question.question_type === 2) { + Insertposition = i; + } + + + } + this.addMytopic(2, this.state.pollid, Insertposition, false, 0); + + // } + } + + //添加主观题目 + addmymainsint = () => { + this.setState({ + Newdisplay:true, + }) + var Insertposition = this.state.poll_questions.length; + // console.log(JSON.stringify(this.state.poll_questions)); + for (var i = 0; i < this.state.poll_questions.length; i++) { + if (this.state.poll_questions[i].question.question_type === 3) { + Insertposition = i; + } + + + } + + this.addMytopic(3, this.state.pollid, Insertposition, false, 0); + // } + } + + //编辑方法 + adddomedit = (object) => { + // console.log("adddomedit 76"); + if (this.state.q_countst > 0) { + this.props.showNotification(`不能同时编辑两题`); + + return; + } + var anserbool = false; + this.setState({ + q_countst: 1, + bindingid:object.question.id + }) + // window.scrollTo(0, this.refs.targetElement.offsetTops) + let {adddom} = this.state; + // var arr =new Object(objects); + // console.log(arr) + // adddom.push(arr); + var question = {}; + var Insertposition = this.state.poll_questions.length; + if (object.question.question_type === 1) { + var answers = []; + var questiontwo = {}; + ///////////////////////////daying + for (var y = 0; y < object.question.answers.length; y++) { + var answerstwo; + if (object.question.answers[y].answer_text === "其他") { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + anserbool = true; + } else { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } + answers.push(answerstwo); + + + } + // 插入单选题 + questiontwo = { + // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 1, + "question_title": object.question.question_title, + "question_type": 1, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + adddom.push(question); + for (var i = 0; i < this.state.poll_questions.length; i++) { + if (this.state.poll_questions[i].question.question_type === 1) { + Insertposition = i; + } + } + } else if (object.question.question_type === 2) { + //插入多选题 + var answers = []; + var questiontwo = {}; + + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + anserbool = true; + } else { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } + answers.push(answerstwo); + } + questiontwo = { + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 2, + "question_title": object.question.question_title, + "question_type": 2, + "max_choices": object.question.max_choices, + "min_choices": object.question.min_choices, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + adddom.push(question); + for (var i = 0; i < this.state.poll_questions.length; i++) { + if (this.state.poll_questions[i].question.question_type === 2) { + Insertposition = i; + } + } + } else if (object.question.question_type === 3) { + //插入主观题 + var answers = []; + var questiontwo = {}; + + if (object.question.answers.length > 0) { + for (var y = 0; y < object.question.answers.length; y++) { + var answerstwo; + if (object.question.answers[y].answer_text === "其他") { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } else { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } + answers.push(answerstwo); + } + } + questiontwo = { + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 3, + "question_title": object.question.question_title, + "question_type": 3, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + adddom.push(question); + for (var i = 0; i < this.state.poll_questions.length; i++) { + if (this.state.poll_questions[i].question.question_type === 3) { + Insertposition = i; + } + } + } + this.setState({ + adddom: adddom, + newoption: anserbool, + Insertposition: Insertposition + }) + + } + + //新增添加题目 有new + addMytopic = (index, pollid, Insertposition, Whether, id) => { + //Whether 是否插入 + // console.log("addMytopic 90") + // console.log(index) + // console.log(pollid) + // console.log(Insertposition) + // console.log(Whether) + console.log("addMytopic"); + console.log(id); + if (this.state.q_countst > 0) { + this.props.showNotification(`不能同时编辑两题`); + + return; + } + this.state.Insertposition = Insertposition; + var Whethername = null; + if (Whether === true) { + Whethername = id; + } + this.setState({ + Insertposition: Insertposition, + q_countst: 1, + }) + // window.scrollTo(0, this.refs.targetElement.offsetTop) + var arrr = this.state.adddom; + let newarrr = [...arrr]; + + var arr = this.state.poll_questions; + let newarr = [...arr]; + + if (newarr.length > 0) { + if (index === 1) { + // 插入单选题 + // console.log(this.state.poll_questions[newarr.length - 1].question.id); + var question = {} + var questiontwo = { + // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, + "id": Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id, + "is_necessary": 1, + "question_number": 1, + "question_title": "", + "question_type": 1, + "new": "new", + "newid":Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id + 1, + "answers": [ + {"answer_id": 1, "answer_position": 1, "answer_text": ""}, + {"answer_id": 2, "answer_position": 2, "answer_text": ""}, + {"answer_id": 3, "answer_position": 3, "answer_text": ""}, + {"answer_id": 4, "answer_position": 4, "answer_text": ""}, + // {"answer_id": 5, "answer_position": 5, "answer_text": "其他"}, + ] + }; + question = {"question": questiontwo}; + newarrr.push(question); + + this.setState({ + adddom: newarrr, + problemtopic: Whethername, + problemtopicbool: Whether, + }) + + } else if (index === 2) { + //插入多选题 + var question = {} + var questiontwo = { + "id": Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id, + "is_necessary": 1, + "question_number": 2, + "question_title": "", + "question_type": 2, + "max_choices": 0, + "min_choices": 0, + "new": "new", + "newid":Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id + 1, + "answers": [ + {"answer_id": 1, "answer_position": 1, "answer_text": ""}, + {"answer_id": 2, "answer_position": 2, "answer_text": ""}, + {"answer_id": 3, "answer_position": 3, "answer_text": ""}, + {"answer_id": 4, "answer_position": 4, "answer_text": ""}, + // {"answer_id": 5, "answer_position": 5, "answer_text": "其他"}, + ] + }; + question = {"question": questiontwo}; + newarrr.push(question); + + this.setState({ + adddom: newarrr, + problemtopic: Whethername, + problemtopicbool: Whether, + }) + + } else if (index === 3) { + //插入主观题 + // console.log(this.state.poll_questions[newarr.length - 1].question.id); + var question = {} + var questiontwo = { + "id": Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id, + "is_necessary": 1, + "question_number": 3, + "question_title": "", + "question_type": 3, + "new": "new", + "newid":Whether=== true? id :this.state.poll_questions[newarr.length - 1].question.id + 1, + "answers": [] + }; + question = {"question": questiontwo}; + newarrr.push(question); + this.setState({ + adddom: newarrr, + problemtopic: Whethername, + problemtopicbool: Whether, + }) + + } + } else { + /////上面视图全部删除后 要加载的 + if (index === 1) { + // 插入单选题 + var ids; + try { + ids = this.state.poll_questions[newarr.length - 1].question.id; + } catch (e) { + ids= 1; + } + var questiontwo = { + // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, + "id": Whether=== true? id :ids, + "is_necessary": 1, + "question_number": 1, + "question_title": "", + "question_type": 1, + "new": "new", + "newid":Whether=== true? id :ids+ 1, + "answers": [ + {"answer_id": 1, "answer_position": 1, "answer_text": ""}, + {"answer_id": 2, "answer_position": 2, "answer_text": ""}, + {"answer_id": 3, "answer_position": 3, "answer_text": ""}, + {"answer_id": 4, "answer_position": 4, "answer_text": ""}, + // {"answer_id": 5, "answer_position": 5, "answer_text": "其他"}, + ] + }; + question = {"question": questiontwo}; + newarrr.push(question); + + this.setState({ + adddom: newarrr, + problemtopic: Whethername, + problemtopicbool: Whether, + }) + + } else if (index === 2) { + //插入多选题 + var ids; + try { + ids = this.state.poll_questions[newarr.length - 1].question.id; + } catch (e) { + ids = 1; + } + var questiontwo = { + "id": Whether=== true? id :ids, + "is_necessary": 1, + "question_number": 2, + "question_title": "", + "question_type": 2, + "max_choices": 0, + "min_choices": 0, + "new": "new", + "newid":Whether=== true? id :ids+1, + "answers": [ + {"answer_id": 1, "answer_position": 1, "answer_text": ""}, + {"answer_id": 2, "answer_position": 2, "answer_text": ""}, + {"answer_id": 3, "answer_position": 3, "answer_text": ""}, + {"answer_id": 4, "answer_position": 4, "answer_text": ""}, + // {"answer_id": 5, "answer_position": 5, "answer_text": "其他"}, + ] + }; + question = {"question": questiontwo}; + newarrr.push(question); + + this.setState({ + adddom: newarrr, + problemtopic: Whethername, + problemtopicbool: Whether, + }) + + } else if (index === 3) { + //插入主观题 + var ids; + try { + ids= this.state.poll_questions[newarr.length - 1].question.id; + } catch (e) { + ids = 1; + } + var questiontwo = { + "id":Whether=== true? id : ids, + "is_necessary": 1, + "question_number": 3, + "question_title": "", + "question_type": 3, + "new": "new", + "newid":Whether=== true? id :ids + 1, + "answers": [] + }; + question = {"question": questiontwo}; + newarrr.push(question); + this.setState({ + adddom: newarrr, + problemtopic: Whethername, + problemtopicbool: Whether, + }) + } + } + } + + //删除指定条目 + Deleteadddom = (indexo,bool) => { + // console.log("deleteadddom 259") + + var arr = this.state.adddom; + let newarr = [...arr]; + newarr.splice(indexo, 1); + if(bool === true) { + this.setState({ + adddom: newarr, + q_countst: 0, + problemtopic: null, + problemtopicbool: false, + bindingid:undefined, + Newdisplay:false, + }) + + }else{ + this.setState({ + adddom: newarr, + q_countst: 0, + problemtopic: null, + problemtopicbool: false, + Newdisplay:false, + }) + } + + } + //保存并继续 + //保存并继续,即提交本题的新建并继续创建一个相同的题(该新题处于编辑模式,题目和选项不要清空) + Deleteadddomtwo = (indexo, object,bool) => { + var thiss = this; + if(bool === true){ + this.setState({ + q_countst: 1, + bindingid:undefined, + Newdisplay:false, + + }) + }else { + this.setState({ + q_countst: 1, + Newdisplay:false, + }) + } + + var poll_questionslength = this.state.poll_questions.length; + // console.log("deleteadddomtwo|||||||||||||||||||||||||||||||||||||||||\\"); + // console.log(indexo); + // console.log(object); + // console.log(object.question.question_type); + let arr = this.state.adddom; + let arrpoll = this.state.poll_questions; + let newarr = [...arr]; + let newarrpoll = [...arrpoll]; + + //选项内容不能为空 + let max = 0; + let maxtie = newarr[indexo].question.answers.length; + for (var k = 0; k < newarr[indexo].question.answers.length; k++) { + try { + if (newarr[indexo].question.answers[k].answer_text != undefined) { + if (newarr[indexo].question.answers[k].answer_text === "") { + max = max + 1; + } + } + } catch (e) { + // console.log("PollNew281") + console.log(e) + } + } + if (newarr[indexo].question.question_title === "") { + this.props.showNotification(`题目不能为空`); + + return + } + if (max > 0) { + if (object.question.question_type === 1) { + this.props.showNotification(`选项内容不能为空`); + + return + } else if (object.question.question_type === 2) { + this.props.showNotification(`选项内容不能为空`); + + return + } + + } + + if (object.question.question_type === 1) { + if (maxtie < 2) { + this.props.showNotification(`选项不能少于2个!`); + return + } + } else if (object.question.question_type === 2) { + if (maxtie < 3) { + this.props.showNotification(`选项不能少于3个!`); + return + } + } + + + + + if (object.question.question_type === 2) { + if (object.question.max_choices > 0) { + // if (object.question.min_choices < 2) { + // this.props.showNotification(`可选最小不能少于2个`); + // + // return; + // + // } + } + + } + if (object.question.new === "new") { + // 根据数组里面的new 来确定是否是新增还是 修改 + //添加道数组上 + //不能共用数组 所以自己写个新数组 然后push 上面卷子中 + var question = {}; + if (object.question.question_type === 1) { + + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + ///////////////////////////daying + // 这个是装选项和其他的 + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + + + } + + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + // 插入单选题 + // var id + // try { + // id = newarrpoll[newarrpoll.length - 1].question.id + 1; + // } catch (e) { + // id = 1; + // } + questiontwo = { + // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, + "id": null, + "is_necessary": object.question.is_necessary, + "question_number": 1, + "question_title": object.question.question_title, + "question_type": 1, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + var insindex = null; + // if (poll_questionslength !== thiss.state.Insertposition) { + // insindex = newarrpoll[thiss.state.Insertposition].question.id; + // } + if (this.state.problemtopicbool === true) { + insindex = this.state.problemtopic; + } + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex); + // newarrpoll.push(question); + newarrpoll.splice(thiss.state.Insertposition, 0, question); + + } else if (object.question.question_type === 2) { + //插入多选题 + if (object.question.max_choices < object.question.min_choices) { + this.props.showNotification(`可选的最大限制不能小于最小限制`); + + return; + } + + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + } + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + // var id + // try { + // id = newarrpoll[newarrpoll.length - 1].question.id + 1; + // } catch (e) { + // id = 1; + // } + questiontwo = { + "id": null, + "is_necessary": object.question.is_necessary, + "question_number": 2, + "question_title": object.question.question_title, + "question_type": 2, + "max_choices": object.question.max_choices, + "min_choices": object.question.min_choices, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + var insindex = null; + if (this.state.problemtopicbool === true) { + insindex = this.state.problemtopic; + } + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex); + //插入多选题 + // if (object.question.max_choices > arrc.length) { + // // console.log("选择题的最大可选项不能大于选项数") + // this.props.showNotification(`选择题的最大可选项不能大于选项数`); + // + // return; + // } + // if (object.question.min_choices === 0) { + // // console.log("选择题的最大可选项不能小于2项目") + // this.props.showNotification(`选择题的最大可选项不能小于2项目`); + // + // return; + // + // } + // newarrpoll.push(question); + newarrpoll.splice(thiss.state.Insertposition, 0, question); + } else if (object.question.question_type === 3) { + //插入主观题 + var answers = []; + var questiontwo = {}; + var answerstwos = []; + var answerstwoss = []; + if (object.question.answers.length > 0) { + for (var y = 0; y < object.question.answers.length; y++) { + var answerstwo; + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + answerstwoss.push(datatwo); + } + } + } + + answers = answerstwoss.concat(answerstwos); + // var id + // try { + // id = newarrpoll[newarrpoll.length - 1].question.id + 1; + // } catch (e) { + // id = 1; + // } + questiontwo = { + "id": null, + "is_necessary": object.question.is_necessary, + "question_number": 3, + "question_title": object.question.question_title, + "question_type": 3, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + // var insindex = null; + // if (poll_questionslength !== thiss.state.Insertposition) { + // insindex = newarrpoll[thiss.state.Insertposition].question.id; + // } + //主观题不需要可选选项 + var insindex = null; + if (this.state.problemtopicbool === true) { + insindex = this.state.problemtopic; + } + this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex); + // newarrpoll.push(question); + newarrpoll.splice(thiss.state.Insertposition, 0, question); + } + //////////////////////////////////////////////////////////////////////////////////////////////////// 上面是新增 + } else { + ///////////////////////////////////////////////////////////////////////////////////////////////////修改点了编辑 + // console.log("点了编辑") + var uuk = -1 + //这个地方判断 点了编辑上面题目又把他删除了 保存的时候就只能是插入新增了 + for (var uk = 0; uk < newarrpoll.length; uk++) { + if (object.question.id === newarrpoll[uk].question.id) { + uuk = uk; + } + } + + + var question = {}; + if (object.question.question_type === 1) { + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + ///////////////////////////daying + //这个装选项和其他的 + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + + + } + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + // 插入单选题 + questiontwo = { + // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 1, + "question_title": object.question.question_title, + "question_type": 1, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + if (uuk !== -1) { + // console.log("修改") + this.edittotheserver(object, 1, arrc, null, 0, 0); + newarrpoll.splice(uuk, 1, question); + } else { + // console.log("他原来的删除掉了") + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id); + newarrpoll.push(question); + } + newarr[indexo].question.new = "new" + // console.log(newarrpoll) + } else if (object.question.question_type === 2) { + //插入多选题 + + if (object.question.max_choices < object.question.min_choices) { + this.props.showNotification('可选的最大限制不能小于最小限制!'); + + return; + } + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + } + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + questiontwo = { + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 2, + "question_title": object.question.question_title, + "question_type": 2, + "max_choices": object.question.max_choices, + "min_choices": object.question.min_choices, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + //插入多选题 + // if (object.question.max_choices > arrc.length) { + // // console.log("选择题的最大可选项不能大于答案数") + // this.props.showNotification('选择题的最大可选项不能大于选项数!'); + // + // return; + // } + // if (object.question.min_choices === 0) { + // // console.log("选择题的最大可选项不能小于2项目") + // this.props.showNotification('选择题的最大可选项不能小于2项目!'); + // + // return; + // + // } + if (uuk !== -1) { + // console.log("修改") + this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices); + newarrpoll.splice(uuk, 1, question); + } else { + // console.log("删除") + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id); + newarrpoll.push(question); + } + // console.log(newarrpoll) + newarr[indexo].question.new = "new" + } else if (object.question.question_type === 3) { + //插入主观题 + var answers = []; + var questiontwo = {}; + + if (object.question.answers.length > 0) { + for (var y = 0; y < object.question.answers.length; y++) { + var answerstwo; + if (object.question.answers[y].answer_text === "其他") { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } else { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } + answers.push(answerstwo); + } + } + questiontwo = { + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 3, + "question_title": object.question.question_title, + "question_type": 3, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + + if (uuk !== -1) { + // console.log("修改") + this.edittotheserver(object, 3, null, null, 0, 0); + newarrpoll.splice(uuk, 1, question); + } else { + // console.log("删除") + this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id); + newarrpoll.push(question); + } + // console.log(newarrpoll) + newarr[indexo].question.new = "new" + } + + } + + + //添加到上面列表中 + //改变题目总数 + if (object.question.question_type === 1) { + //单选题 + this.state.mysingles = this.state.mysingles + 1; + } else if (object.question.question_type === 2) { + //多选题 + this.state.mydoubles = this.state.mydoubles + 1; + } else if (object.question.question_type === 3) { + //主观题 + this.state.mymainsint = this.state.mymainsint + 1; + + } + this.setState({ + // poll_questions: newarrpoll, + adddom: newarr, + problemtopic: null, + problemtopicbool: false, + // mysingles: this.state.mysingles, + // mydoubles: this.state.mydoubles, + // mymainsint: this.state.mymainsint + }) + + } + + + //保存 后期可以考虑和保存并继续 合并 + //保存,即完成新建并退出本题编辑 + // indexo 第几个数组 + //object 单个数组数据 + Deleteadddomthree = (indexo, object,bool) => { + if(bool === true) { + this.setState({ + bindingid:undefined, + }) + } + this.setState({ + Newdisplay:false, + }) + // console.log("deleteadddom 349") + var thiss = this; + let arr = this.state.adddom; + let arrpoll = this.state.poll_questions; + let newarr = [...arr]; + let newarrpoll = [...arrpoll]; + var poll_questionslength = this.state.poll_questions.length; //获取单前问题最大长度 + //选项内容不能为空 + let max = 0; + let maxtie = newarr[indexo].question.answers.length; + //判断选项值是否不为空 + for (var k = 0; k < newarr[indexo].question.answers.length; k++) { + try { + if (newarr[indexo].question.answers[k].answer_text != undefined) { + if (newarr[indexo].question.answers[k].answer_text === "") { + max = max + 1; + } + } + } catch (e) { + // console.log("PollNew281") + // console.log(e) + } + } + if (newarr[indexo].question.question_title === "") { + this.props.showNotification('题目不能为空!'); + return + } + if (max > 0) { + if (object.question.question_type === 1) { + this.props.showNotification('选项内容不能为空!'); + return + } else if (object.question.question_type === 2) { + this.props.showNotification('选项内容不能为空!'); + return + } + + } + if (object.question.question_type === 1) { + if (maxtie < 2) { + this.props.showNotification('选项不能少于2个!'); + return + } + } else if (object.question.question_type === 2) { + if (maxtie < 3) { + this.props.showNotification('选项不能少于3个!'); + return + } + } + + + + if (object.question.question_type === 2) { + if (object.question.max_choices > 0) { + // if (object.question.min_choices < 2) { + // this.props.showNotification(`可选最小不能少于2个`); + // return; + // } + } + } + if (object.question.new === "new") { + ///////////////////////////////////////////////////////////////////新增模式 + // 根据数组里面的new 来确定是否是新增还是 修改 + //添加道数组上 + //不能共用数组 所以自己写个新数组 然后push 上面卷子中 + var question = {}; + if (object.question.question_type === 1) { + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + ///////////////////////////daying + // 这个是装选项和其他的 + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + } + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + // 插入单选题' + // var id; + // try { + // id = newarrpoll[newarrpoll.length - 1].question.id + 1 + // } catch (e) { + // id = 1; + // } + questiontwo = { + // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, + "id": null, + "is_necessary": object.question.is_necessary, + "question_number": 1, + "question_title": object.question.question_title, + "question_type": 1, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + //获取指定id 号 用来插入,如果不是就是在最后添加 + + //执行新增操作 + var insindex = null; + if (this.state.problemtopicbool === true) { + insindex = this.state.problemtopic; + } + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, insindex); + newarrpoll.splice(thiss.state.Insertposition, 0, question); + } else if (object.question.question_type === 2) { + //插入多选题 + if (object.question.max_choices < object.question.min_choices) { + this.props.showNotification(`可选的最大限制不能小于最小限制`); + + return; + } + + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + } + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + + questiontwo = { + "id": null, + "is_necessary": object.question.is_necessary, + "question_number": 2, + "question_title": object.question.question_title, + "question_type": 2, + "max_choices": object.question.max_choices, + "min_choices": object.question.min_choices, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + + var insindex = null; + if (this.state.problemtopicbool === true) { + insindex = this.state.problemtopic; + } + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, insindex); + //插入多选题 + // if (object.question.max_choices > arrc.length) { + + newarrpoll.splice(thiss.state.Insertposition, 0, question); + } else if (object.question.question_type === 3) { + //插入主观题 + var answers = []; + var questiontwo = {}; + var answerstwos = []; + var answerstwoss = []; + if (object.question.answers.length > 0) { + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + answerstwoss.push(datatwo); + } + } + } + answers = answerstwoss.concat(answerstwos); + + questiontwo = { + "id": null, + "is_necessary": object.question.is_necessary, + "question_number": 3, + "question_title": object.question.question_title, + "question_type": 3, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + //主观题不需要可选选项 + + var insindex = null; + if (this.state.problemtopicbool === true) { + insindex = this.state.problemtopic; + } + this.createquestionsandanswers(object, 3, null, null, 0, 0, insindex); + // newarrpoll.push(question); + newarrpoll.splice(thiss.state.Insertposition, 0, question); + } + ///////////////////////////////////////////////////////////////////新增模式 + } else { + //////////////////////////////////////////////////////////////////////////////修改模式 + //修改 + var uuk = -1 + for (var uk = 0; uk < newarrpoll.length; uk++) { + if (object.question.id === newarrpoll[uk].question.id) { + uuk = uk; + // console.log("删除了数据=-09876543234567890-111111111111") + } + } + + + var question = {}; + if (object.question.question_type === 1) { + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + ///////////////////////////daying + //这个装选项和其他的 + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + } + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + // 插入单选题 + questiontwo = { + // "id": this.state.poll_questions[arr.length - 1].question.id + 1 + arrr.length, + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 1, + "question_title": object.question.question_title, + "question_type": 1, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + if (uuk !== -1) { + // console.log("修改") + this.edittotheserver(object, 1, arrc, null, 0, 0); + newarrpoll.splice(uuk, 1, question); + } else { + // console.log("删除") + this.createquestionsandanswers(object, 1, arrc, null, 0, 0, object.question.id); + newarrpoll.push(question); + } + // console.log(newarrpoll) + } else if (object.question.question_type === 2) { + //插入多选题 + if (object.question.max_choices < object.question.min_choices) { + this.props.showNotification(`可选的最大限制不能小于最小限制`); + + return; + } + var questiontwo = {}; + var other = []; + var option = []; + var answerstwos = []; + var answerstwoss = []; + for (var y = 0; y < object.question.answers.length; y++) { + if (object.question.answers[y].answer_text === "其他") { + var dataone = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + other.push(object.question.answers[y].answer_text); + answerstwos.push(dataone); + } else { + var datatwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + option.push(object.question.answers[y].answer_text) + answerstwoss.push(datatwo); + } + } + var arrc = option.concat(other); + var answers = answerstwoss.concat(answerstwos); + questiontwo = { + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 2, + "question_title": object.question.question_title, + "question_type": 2, + "max_choices": object.question.max_choices, + "min_choices": object.question.min_choices, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + //插入多选题 + if (uuk !== -1) { + // console.log("修改") + this.edittotheserver(object, 2, arrc, null, object.question.max_choices, object.question.min_choices); + newarrpoll.splice(uuk, 1, question); + } else { + // console.log("删除") + this.createquestionsandanswers(object, 2, arrc, null, object.question.max_choices, object.question.min_choices, object.question.id); + newarrpoll.push(question); + } + // console.log(newarrpoll) + + } else if (object.question.question_type === 3) { + //插入主观题 + var answers = []; + var questiontwo = {}; + + if (object.question.answers.length > 0) { + for (var y = 0; y < object.question.answers.length; y++) { + var answerstwo; + if (object.question.answers[y].answer_text === "其他") { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } else { + answerstwo = { + "answer_id": object.question.answers[y].answer_id, + "answer_position": object.question.answers[y].answer_position, + "answer_text": object.question.answers[y].answer_text + } + } + answers.push(answerstwo); + } + } + questiontwo = { + "id": object.question.id, + "is_necessary": object.question.is_necessary, + "question_number": 3, + "question_title": object.question.question_title, + "question_type": 3, + "new": "", + "answers": answers + }; + question = {"question": questiontwo}; + if (uuk !== -1) { + // console.log("修改") + this.edittotheserver(object, 3, null, null, 0, 0); + newarrpoll.splice(uuk, 1, question); + } else { + // console.log("删除") + this.createquestionsandanswers(object, 3, null, null, 0, 0, object.question.id); + newarrpoll.push(question); + } + // console.log(newarrpoll) + + } + + } + + + //添加到上面列表中 + //改变题目总数 + if (object.question.question_type === 1) { + //单选题 + this.state.mysingles = this.state.mysingles + 1; + } else if (object.question.question_type === 2) { + //多选题 + this.state.mydoubles = this.state.mydoubles + 1; + } else if (object.question.question_type === 3) { + //主观题 + this.state.mymainsint = this.state.mymainsint + 1; + + } + + //这里更新数据 + if (this.state.q_countst == 1) { + this.setState({ + q_countst: 0, + }) + } + this.Deleteadddom(indexo); + // console.log(indexo) + } + + + ////新增到服务器中 + createquestionsandanswers = (object, number, option, other, max_choices, min_choices, insert_id) => { + var thiss = this; + var poll_id = this.state.pollid; + var urlly = `/polls/${poll_id}/poll_questions.json` + var max_choicess = null; + var min_choicess = null; + if (max_choices === 0 && min_choices === 0) { + max_choicess = null; + min_choicess = null; + } else { + max_choicess = max_choices; + min_choicess = min_choices; + } + axios.post(urlly, { + question_title: object.question.question_title, + question_type: number, + is_necessary: object.question.is_necessary, + max_choices: max_choicess, + min_choices: min_choicess, + question_answers: option, + question_other_answer: null, + insert_id: insert_id + }).then((result) => { + // try { + if (result !== undefined) { + if (result.data.status === 0) { + this.props.showNotification(`已完成`); + thiss.thisinitializationdatanew(); + // console.log("确认创建问题") + // console.log(result) + // try { + // if (result.data.status === 0) { + // console.log("确认创建问题") + // console.log(JSON.stringify(result.data)) + // } + // } catch (e) { + // + // } + } + } + // } catch (e) { + // + // } + + }) + + + } + ///编辑修改到服务器当中 + edittotheserver = (object, number, option, other, max_choices, min_choices) => { + // console.log("调用了edittotheserver") + var url = `/poll_questions/${object.question.id}.json` + var thiss = this; + axios.put(url, { + // debug: true, + question_title: object.question.question_title, + question_type: number, + is_necessary: object.question.is_necessary, + max_choices: max_choices, + min_choices: min_choices, + question_answers: option, + question_other_answer: null, + }).then((result) => { + try { + if (result.data.status === 0) { + this.props.showNotification(`编辑题目成功`); + thiss.thisinitializationdatanew(); + } + } catch (e) { + // console.log("调用了edittotheserver") + console.log(e) + } + }) + } + + //删除到服务器当中 + eletetoserver = (pollid, newarr, type, index) => { + // console.log("调用了eletetoserver") + var id = pollid; + var url = `/poll_questions/${id}.json` + let {mysingles, mydoubles, mymainsint} = this.state + var thiss = this; + + axios + .delete(url, {}) + .then(function (response) { + // console.log(response) + if (response === undefined) { + return; + } + if (response.data.message === "删除成功") { + thiss.props.showNotification(`删除成功`); + + newarr.splice(index, 1); + if (type === 1) { + mysingles = mysingles - 1; + } else if (type === 2) { + mydoubles = mydoubles - 1; + + } else if (type === 3) { + mymainsint = mymainsint - 1; + + } + // thiss.setState({ + // poll_questions: newarr, + // mysingles: mysingles, + // mydoubles: mydoubles, + // mymainsint: mymainsint + // }); + thiss.thisinitializationdatanew(); + } + }) + } + + //上下移到服务器中 + Upanddownmovementof = (bool, poll_question_id) => { + // console.log("调用了Upanddownmovementofr") + // console.log(poll_question_id) + var thiss = this; + if (bool === true) { + var url = `/poll_questions/${poll_question_id}/up_down.json`; + axios.post(url, { + opr: "up", + }).then((result) => { + try { + if (result.data.status === 0) { + this.props.showNotification(`上移成功`); + thiss.thisinitializationdatanew(); + } + // console.log(JSON.stringify(result)) + } catch (e) { + // console.log("上移题目成功 错误") + console.log(e) + } + + }) + } else { + var url = `/poll_questions/${poll_question_id}/up_down.json`; + axios.post(url, { + opr: "down", + }).then((result) => { + try { + if (result.data.status === 0) { + // message.success("下移题目成功", 1) + this.props.showNotification(`下移成功`); + thiss.thisinitializationdatanew(); + } + // console.log(JSON.stringify(result)) + } catch (e) { + // console.log("下移题目成功 错误") + console.log(e) + } + }) + } + + } + + //删除编辑新增条目 + //id 条目的唯一id + //i 为要删除的子条目 + Deleteentrys = (id, i, stirngname) => { + // console.log(id) + // console.log(stirngname); + var arrtwoy = this.state.adddom; + let newarrtwoy = [...arrtwoy]; + for (var k = 0; k < newarrtwoy.length; k++) { + if (newarrtwoy[k] != undefined) { + if (newarrtwoy[k].question.id === id) { + for (var c = 0; c < newarrtwoy[k].question.answers.length; c++) { + if (c === i) { + // console.log("删除了") + // console.log(c) + newarrtwoy[k].question.answers.splice(c, 1); + } + } + } + } + } + if (stirngname === true) { + // console.log(stirngname); + this.setState({ + newoption: false, + adddom: newarrtwoy, + + }) + } else { + // console.log(stirngname); + this.setState({ + adddom: newarrtwoy, + }); + } + + + } + + + // 新增选项 + Ewoption = (id, object) => { + // console.log("ewoption 440") + // console.log("是否是新建题目还是编辑") + // console.log(object.question.new) + + + let arrtwo = this.state.adddom; + let newarrtwo = [...arrtwo]; + + + for (var k = 0; k < newarrtwo.length; k++) { + // console.log(arrtwo[k].question.id); + if (newarrtwo[k] != undefined) { + if (newarrtwo[k].question.id === id) { + var data = { + "answer_id": newarrtwo[k].question.answers.length + 1, + "answer_position": newarrtwo[k].question.answers.length + 1, + "answer_text": "" + }; + //向头部添加元素 + // newarrtwo[k].question.answers.unshift(data); + //如果有其他这一项就删除掉 + if (newarrtwo[k].question.answers.length > 0) { + for (var o = 0; o < newarrtwo[k].question.answers.length; o++) { + if (newarrtwo[k].question.answers[o].answer_text != undefined) { + if (newarrtwo[k].question.answers[o].answer_text === "其他") { + newarrtwo[k].question.answers.splice(o, 0, data); + this.setState({ + adddom: newarrtwo + }) + return + } else { + if (o === newarrtwo[k].question.answers.length - 1) { + newarrtwo[k].question.answers.push(data); + this.setState({ + adddom: newarrtwo + }) + return + } + } + } + } + } else { + newarrtwo[k].question.answers.push(data); + this.setState({ + adddom: newarrtwo + }) + } + + } + } + } + + } + + + swapArray = (arr, index1, index2) => { + arr[index1] = arr.splice(index2, 1, arr[index1])[0]; + return arr; + } + + //新增其他选项 + Addanotheroption = (id) => { + // console.log("addanotheroption 457") + let arrtwo = this.state.adddom; + let newarrtwo = [...arrtwo]; + // console.log(newarrtwo) + for (var k = 0; k < newarrtwo.length; k++) { + if (newarrtwo[k] != undefined) { + if (newarrtwo[k].question.id === id) { + var data = { + "answer_id": newarrtwo[k].question.answers.length + 1, + "answer_position": newarrtwo[k].question.answers.length + 1, + "answer_text": "其他" + }; + newarrtwo[k].question.answers.push(data); + } + } + } + this.setState({ + adddom: newarrtwo, + newoption: true, + }) + } + + + //点击向上排序按钮事件 + handleClickBySortUp = (index, object) => { + // console.log("handleClickBySortUp 521") + let arr = this.state.poll_questions; + let newarr = [...arr]; + // console.log(newarr) + if (index != 0) { + this.Upanddownmovementof(true, object.question.id); + let temp = newarr[index - 1]; + newarr[index - 1] = newarr[index]; + newarr[index] = temp; + this.setState({ + poll_questions: newarr, + }); + } + } + + //点击向下排序按钮事件 + handleClickBySortDown = (index, object) => { + // console.log("handleClickBySortDown 536") + let arr = this.state.poll_questions; + let newarr = [...arr]; + // + if (index != newarr.length - 1) { + this.Upanddownmovementof(false, object.question.id); + let temp = newarr[index + 1]; + newarr[index + 1] = newarr[index]; + newarr[index] = temp; + this.setState({ + poll_questions: newarr, + }); + } else { + // console.log("2222index==arr.length"); + // console.log(this.state.poll_questions); + } + } + + //点击删除按钮事件 + handleClickByDelete = (type, index, object) => { + // console.log("handleClickByDelete 556") + // console.log("object.question.id") + // console.log(object.question.id) + let arr = this.state.poll_questions; + let newarr = [...arr]; + this.eletetoserver(object.question.id, newarr, type, index) + + } + + // 数字输入监听 + //e为获取组件对象 + //i外层数组 + //k为内层数组 + HandleInputChanges = (e, i, k) => { + console.log("handleInputChanges"+" "+e); + console.log("handleInputChanges"+" "+i); + console.log("handleInputChanges"+" "+k); + // console.log("handleInputChanges 612") + + let value = e.target.value;//取到input的数据 + // console.log("handleInputChanges value is :" + value); + // console.log(k); + let arr = this.state.adddom; + let newarr = [...arr]; + + newarr[i].question.answers[k].answer_text = value + this.setState({ + adddom: newarr + }) + + } + + //标题输入监听 + HandleInputTopic = (e, i) => { + // console.log("handleInputTopic 633") + + let value = e.target.value;//取到input的数据 + // console.log("handleInputTopic value is :" + value); + // console.log(i); + let arr = this.state.adddom; + let newarr = [...arr]; + newarr[i].question.question_title = value + this.setState({ + adddom: newarr + }) + } + + //最小值 + HandleGradationGroupChangee = (value, index, max, length) => { + // debugger + var minbool = false; + var maxbool = false; + let arr = this.state.adddom; + if (parseInt(value) === 0 || parseInt(value) === "0" || parseInt(value) === null || parseInt(value) === undefined || parseInt(value) < 1) { + minbool = true; + } + if (max === 0 || max === "0" || max === null || max === undefined) { + maxbool = true; + } + + if (minbool === true && maxbool === true) { + for (var i = 0; i < arr.length; i++) { + if (index === i) { + arr[i].question.min_choices = parseInt(value); + } + } + this.setState({ + adddom: arr + }) + } else { + for (var i = 0; i < arr.length; i++) { + if (index === i) { + try { + if(parseInt(value)===0){ + arr[i].question.min_choices = 2; + arr[i].question.max_choices = length; + }else{ + arr[i].question.min_choices = parseInt(value); + arr[i].question.max_choices = length; + } + }catch (e) { + arr[i].question.min_choices = 2; + arr[i].question.max_choices = length; + } + break; + } + } + this.setState({ + adddom: arr + }) + } + + } + + //最大值 + HandleGradationGroupChangeee = (value, index,minchoices) => { + // console.log("2112"); + // console.log(value); + // console.log(minchoices); + let arr = this.state.adddom; + for (var i = 0; i < arr.length; i++) { + if (index === i) { + if(parseInt(value)===0&&parseInt(minchoices)===0){ + arr[i].question.min_choices= parseInt(minchoices); + arr[i].question.max_choices = parseInt(value); + }else { + arr[i].question.min_choices= minchoices===null?2:minchoices===undefined?2:minchoices===0?2:parseInt(minchoices); + arr[i].question.max_choices = parseInt(value); + } + } + } + // console.log(2119); + // console.log(arr); + this.setState({ + adddom: arr + }) + // console.log(this.state.adddom); + } + + //提交题目//没有就创建新的题库,新建问newz题和保存题目不一样不能同时保存 这里只是新建 和编辑 标题和须知 + submitQuestionnaire = () => { + // console.log("调用了submitQuestionnaire") + if (this.state.Newedit === true) { + + this.newword(); + + } else { + if (this.state.polls_nametest === undefined || this.state.polls_nametest === "") { + this.props.showNotification("请输入标题"); + return + } + + if (this.state.polls_descriptiontest.length > 100) { + + } + var pollid; + if (this.state.pollid === undefined) { + pollid = this.props.match.params.workid; + } else { + pollid = this.state.pollid; + } + + // if(mews ==="new"){ + if(this.state.poll_questions&&this.state.poll_questions.length===0){ + this.props.showNotification("至少创建1个题目"); + return; + } + // } + + var url = `/polls/${pollid}.json`; + axios.put(url, { + polls_name: this.state.polls_nametest, + polls_description: this.state.polls_descriptiontest + }).then((result) => { + try { + // console.log(JSON.stringify(result)) + if (result.data.status === 0) { + // console.log("更新题目成功") + // this.props.showNotification("保存成功"); + this.props.history.push(`/courses/${this.props.match.params.coursesId}/polls/${pollid}/detail?tab=2`) + } + } catch (e) { + + } + }) + } + } + + cancelmodel = () => { + + this.setState({ + Modalstype: false, + Modalstopval: "", + ModalsBottomval: "", + }) + + } + savedelete = (question_type, index, item) => { + // console.log("savedelete"); + this.handleClickByDelete(question_type, index, item); + this.setState({ + Modalstype: false, + Modalstopval: "", + ModalsBottomval: "", + }) + } + // 问题的类型,1单选题,2为多选题,3为主观题 + showDeleteConfirm = (question_type, index, item) => { + this.setState({ + Modalstype: true, + Modalstopval: "是否确认删除?", + ModalsBottomval: "", + ModalCancel: this.cancelmodel, + ModalSave: () => this.savedelete(question_type, index, item), + }) + + } + //必答选项 + OnCheckAllChange = (e, index) => { + // console.log("onCheckAllChange"); + // console.log(e.target.checked); + // console.log(e.target.value); + let arr = this.state.adddom; + for (var i = 0; i < arr.length; i++) { + if (index === i) { + if (e.target.checked === true) { + arr[i].question.is_necessary = 1; + + } else { + arr[i].question.is_necessary = 0; + } + } + } + this.setState({ + adddom: arr + }) + } + + //重新编辑标题和须知 + adddomeditit = () => { + if (this.state.mysave === true) { + this.setState({ + mysave: false, + readOnlys: "readOnly", + storagedesc:this.state.polls_nametest, + storagedesctwo:this.state.polls_descriptiontest, + }) + } else if (this.state.mysave === false) { + this.setState({ + mysave: true, + readOnlys: "", + storagedesc:this.state.polls_nametest, + storagedesctwo:this.state.polls_descriptiontest, + }) + } + } + //取消保存 + onSaveExercisetwo = () => { + if (this.state.mysave === true) { + this.setState({ + mysave: false, + Newedit: false, + readOnlys: "readOnly", + polls_nametest:this.state.storagedesc, + polls_descriptiontest:this.state.storagedesctwo, + }) + } else { + this.setState({ + mysave: false, + Newedit: false, + readOnlys: "readOnly", + polls_nametest:this.state.storagedesc, + polls_descriptiontest:this.state.storagedesctwo, + }) + } + } + // 创建问卷 + onSaveExercise = () => { + if (this.state.Newedit === true) { + + if (this.state.polls_nametest === undefined || this.state.polls_nametest === "") { + this.props.showNotification(`请输入标题`); + return + } + let coursesId = this.props.match.params.coursesId; + const urlls = `/courses/${coursesId}/polls.json` + axios.post(urlls, { + polls_name: this.state.polls_nametest, + polls_description: this.state.polls_descriptiontest + }).then((result) => { + if (result === undefined) { + return; + } + this.state.Newedit === false; + this.props.showNotification(`问卷创建成功!`); + this.setState({ + pollid: result.data.data.id, + Newedit: false, + mysave: false, + readOnlys: "readOnly", + cancellation: false, + }); + // var currenturl = window.location.href; + // var newUrl = (currenturl.split("?"))[0]; + // var newr=(newUrl.slice("new"))[0]; + // console.log(newUrl); + // console.log("2301"); + // console.log(newr); + // window.history.pushState('','',newUrl+'?tab='+e); + window.location.href = `/courses/${coursesId}/polls/${result.data.data.id}/edit`; + + }) + } else { + if (this.state.polls_nametest === undefined || this.state.polls_nametest === "") { + this.props.showNotification("请输入标题"); + return + } + + var pollid; + if (this.state.pollid === undefined) { + pollid = this.props.match.params.workid; + } else { + pollid = this.state.pollid; + } + + + var url = `/polls/${pollid}.json`; + axios.put(url, { + polls_name: this.state.polls_nametest, + polls_description: this.state.polls_descriptiontest + }).then((result) => { + if (result !== undefined) { + this.props.showNotification(`问卷更新成功!`); + this.setState({ + mysave: false, + readOnlys: "readOnly", + }) + } + + }) + } + + } + gotohome=()=>{ + // const { current_user} = this.props + if(this.state.first_category_url){ + window.location.href=this.state.first_category_url; + }else{ + this.props.history.goBack(); + } + + // + // let courseId=this.props.match.params.coursesId; + // if(courseId===undefined){ + // this.props.history.push("/courses"); + // }else{ + // this.props.history.push(this.props.current_user.first_category_url); + // } + } + //试图 + render() { + let { + addonAfter, + user_permission, + polls_status, + Modalstype, + mysave, + readOnlys, + newoption, + cancellation, + left_banner_id + } = this.state + //获取老师权限 + // console.log("[`${maps[polls_status && polls_status]}`]]"); + // console.log(polls_status); + // console.log([[`${maps[polls_status && polls_status]}`]] + ""); + + const IsAdmin = this.props.isAdmin(); + // const {getFieldDecorator} = this.props.form; + const formItemLayout = { + labelCol: { + xs: {span: 24}, + // sm: { span: 8 }, + sm: {span: 24}, + }, + wrapperCol: { + xs: {span: 24}, + // sm: { span: 16 }, + sm: {span: 24}, + }, + }; + + const radioStyle = { + display: 'block', + height: '30px', + lineHeight: '30px', + }; + + // console.log(this.state.projects===undefined?"":this.state.projects.poll_questions) + var displaymysave = (mysave === true) ? "" : "display:none;"; + return ( +
+ {/*提示*/} + {Modalstype && Modalstype === true ? : ""} +
+

+ this.gotohome()}>{this.props.coursedata.name} + > + {/*{*/} + {/* this.props.match.params.news === "new"?*/} + {/* 问卷*/} + {/* :*/} + 问卷 + {/*}*/} + + > + {/*{this.props.match.params.news === undefined ? "新建" : this.props.match.params.news === "new" ? "新建" : "编辑"}*/} + 编辑 + +

+
+ {/*

{this.props.match.params.news === undefined ? "新建问卷" : this.props.match.params.news === "new" ? "新建问卷" : "编辑问卷"}

*/} +

编辑问卷

+ {/*{*/} + {/* this.props.match.params.news === "new" ?*/} + {/* 返回*/} + {/* :*/} + 返回 + {/*}*/} +
+ + {/*
*/} + { + this.state.mysave === false ? +
+ +
+ +
+ :"" + } + { + this.state.mysave === true ? +
+
+ + +
+
*问卷标题 +
+ { + // this.props.match.params.news === undefined ? "" : this.props.match.params.news === "new" ? + // ( + this.state.mysave === false ? + + : "" + // ) + // :"" + } + +
+ {/*suffix={String(addonAfter)}*/} + + + +
+
+ + +
问卷须知
+ + + { + this.state.Newedit === true || this.state.mysave === true ? +
+ + {cancellation === false ? + + : ""} + +
+ : "" + } + +
+ +
:"" + } + + + +

+ + + { + this.state.mysingles + this.state.mydoubles + this.state.mymainsint === 0 ? "" : +

+ + {this.state.mysingles === 0 ? "" : 单选题{this.state.mysingles === undefined ? "" : this.state.mysingles} 题} + + {this.state.mydoubles === 0 ? "" : + 多选题{this.state.mydoubles === undefined ? "" : this.state.mydoubles}题} + {this.state.mymainsint === 0 ? "" : + + 主观题{this.state.mymainsint === undefined ? "" : this.state.mymainsint}题 + + } + + + 合计 {this.state.mysingles === undefined ? "" : this.state.mydoubles === undefined ? "" : this.state.mymainsint === undefined ? "" : this.state.mysingles + this.state.mydoubles + this.state.mymainsint} +
+ + } + +

+ + {polls_status === undefined || polls_status === 1 ? +
+
+
+ this.addmysingles()}>单选题 + this.addmydoubles()}>多选题 + this.addmymainsint()}>主观题 +
+
+ :
} + +
+ + {/*自动生成修改好的获取到的*/} + {/**************************************************************************/} + {this.state.poll_questions === undefined ? "" : this.state.poll_questions.map((item, index) => { + console.log('打印this.state.poll_questions'); + console.log(this.state.poll_questions); + console.log(this.state.adddom); + let resultDom; + resultDom =
+

+ 第{index + 1}题: + {item.question.question_type === 1 ? "(单选题)" : item.question.question_type === 2 ? "(多选题)" : "(主观题)"} + {item.question.is_necessary === 1 ? "必答" : item.question.question_type === 2 ? "选答" : "选答"} + {(item.question.min_choices === undefined && item.question.max_choices === undefined ? "" : item.question.min_choices === null && item.question.max_choices === null ? "" : item.question.min_choices === 0 && item.question.max_choices === 0 ? "" : "可选" + item.question.min_choices + "-" + item.question.max_choices + "项")} + { + polls_status === undefined || polls_status === 1 ? + + this.showDeleteConfirm(item.question.question_type, index, item)}> + {index === 0 ? "" : + this.handleClickBySortUp(index, item)}>} + {index === this.state.poll_questions.length - 1 ? "" : + this.handleClickBySortDown(index, item)}>} + this.addMytopic(item.question.question_type, this.state.pollid, index + 1, true, item.question.id)}> + this.adddomedit(item)}> + : this.adddomedit(item)}> + } + +

+

{item.question.question_title}

+ {/*
{item.question.question_title}
*/} + {item.question.question_type === 1 ? +
+ + {item.question.answers === undefined ? "" : item.question.answers.map((items, i) => { + return ( +
+ + {items.answer_text} + +
+ ) + })} +
+ {/*单选题*/} + + +
+ : item.question.question_type === 2 ? +
+ + {item.question.answers === undefined ? "" : item.question.answers.map((items, i) => { + return ( +
+ + {items.answer_text} +
+ ) + })} +
+ {/*多选题*/} +
+ + : item.question.question_type === 3 ? + // 主观题 + (
+
) : (
)} +
+ + return ( +
+ {/*这里是编辑和新增的地方*/} + { + this.state.bindingid && this.state.bindingid===item.question.id? + (this.state.Newdisplay === false? +
+
+ {this.state.adddom === undefined ? "" :this.state.adddom===undefined?"": this.state.adddom.length===0?"":item.question.id === this.state.adddom[0].question.id&&this.state.adddom.map((itemo, indexo) => { + let arrid = itemo.question.id; + let resultDomtwo; + resultDomtwo = +
+ {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"} + this.OnCheckAllChange(e, indexo)} + className="lineh-40" + style={{"marginLeft": "20px"}}>必答 + + + + + {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { + return ( +
+ {itemt.answer_text === undefined ? ( +
) : itemt.answer_text === "其他" ? ( +

+ 其它 + + + {this.state.polls_status === undefined || this.state.polls_status === 1 ? + this.Deleteentrys(arrid, indext, true)}> + : ""} +

) : (

+ 选项 + + + {this.state.polls_status === undefined || this.state.polls_status === 1 ? + this.Deleteentrys(arrid, indext, false)}> + : ""} +

)} +
+ ) + })} + +
+ {itemo.question.question_type === 1 ? ( +
+
+ {this.state.polls_status === undefined || this.state.polls_status === 1 ? + this.Ewoption(itemo.question.id, itemo)}>新增选项 + + : ""} + {this.state.polls_status === undefined || this.state.polls_status === 1 ? + + (this.state.newoption === false ? + this.Addanotheroption(itemo.question.id)}>新增其他选项 + : "") + : ""} + + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+
+ + + ) + + + : itemo.question.question_type === 2 ? ( + //////////////////////////////////////////// 可选 +
+
+
+ 可选 +
+ {/*可选最小*/} + + + ~ + {/*可选最大*/} + + + (学生答题时,系统对其选择的选项个数进行限制,--表示不限制) +
+ +
+
+
+ ) + + : (
) + + } +
+
+ {itemo.question.question_type === 2 ? + ( + this.state.polls_status === undefined || this.state.polls_status === 1 ? +
+ +
this.Ewoption(itemo.question.id, itemo)}>新增选项 + + { + this.state.newoption === false ? this.Addanotheroption(itemo.question.id)}>新增其他选项 : "" + } + +
+ + + + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+ + + : +
+ + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+ ) + + : itemo.question.question_type === 3 ? +
+ + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+ : + ""} + + +
+
+ + + return ( +
+ {resultDomtwo} +
+ ) + })} +
+
:"") + : +
+ {resultDom} + {this.state.Newdisplay === false? + +
+ {this.state.adddom === undefined ? "" :this.state.adddom===undefined?"": this.state.adddom.length===0?"":item.question.id === this.state.adddom[0].question.id&&this.state.adddom.map((itemo, indexo) => { + let arrid = itemo.question.id; + let resultDomtwo; + resultDomtwo = +
+ {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"} + this.OnCheckAllChange(e, indexo)} + className="lineh-40" + style={{"marginLeft": "20px"}}>必答 + + + + + {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { + return ( +
+ {itemt.answer_text === undefined ? ( +
) : itemt.answer_text === "其他" ? ( +

+ 其它 + + + {this.state.polls_status === undefined || this.state.polls_status === 1 ? + this.Deleteentrys(arrid, indext, true)}> + : ""} +

) : (

+ 选项 + + + {this.state.polls_status === undefined || this.state.polls_status === 1 ? + this.Deleteentrys(arrid, indext, false)}> + : ""} +

)} +
+ ) + })} + +
+ {itemo.question.question_type === 1 ? ( +
+
+ {this.state.polls_status === undefined || this.state.polls_status === 1 ? + this.Ewoption(itemo.question.id, itemo)}>新增选项 + + : ""} + {this.state.polls_status === undefined || this.state.polls_status === 1 ? + + (this.state.newoption === false ? + this.Addanotheroption(itemo.question.id)}>新增其他选项 + : "") + : ""} + + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+
+ + + ) + + + : itemo.question.question_type === 2 ? ( + //////////////////////////////////////////// 可选 +
+
+
+ 可选 +
+ {/*可选最小*/} + + + ~ + {/*可选最大*/} + + + (学生答题时,系统对其选择的选项个数进行限制,--表示不限制) +
+ +
+
+
+ ) + + : (
) + + } +
+
+ {itemo.question.question_type === 2 ? + ( + this.state.polls_status === undefined || this.state.polls_status === 1 ? +
+ +
this.Ewoption(itemo.question.id, itemo)}>新增选项 + + { + this.state.newoption === false ? this.Addanotheroption(itemo.question.id)}>新增其他选项 : "" + } + +
+ + + + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+ + + : +
+ + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+ ) + + : itemo.question.question_type === 3 ? +
+ + this.Deleteadddom(indexo,true)}>取消 + this.Deleteadddomthree(indexo, itemo,true)}>保存 + this.Deleteadddomtwo(indexo, itemo,true)}>保存并继续 + +
+ : + ""} + + +
+
+ + + return ( +
+ {resultDomtwo} +
+ ) + })} +
:""} +
+ } +
+ + ) + })} + + + + {/*新建单选多选2*/} +
+ { + this.state.Newdisplay === true? +
+ {this.state.adddom === undefined ? "" : this.state.adddom.map((itemo, indexo) => { + // console.log('打印this.state.adddom') + // console.log(this.state.adddom); + let arrid = itemo.question.id; + let resultDomtwo; + resultDomtwo = +
+ {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"} + this.OnCheckAllChange(e, indexo)} + className="lineh-40" + style={{"marginLeft": "20px"}}>必答 + + + + + {itemo.question.answers === undefined ? "" : itemo.question.answers.map((itemt, indext) => { + return ( +
+ {itemt.answer_text === undefined ? ( +
) : itemt.answer_text === "其他" ? ( +

+ 其它 + + + {polls_status === undefined || polls_status === 1 ? + this.Deleteentrys(arrid, indext, true)}> + : ""} +

) : (

+ 选项 + + + {polls_status === undefined || polls_status === 1 ? + this.Deleteentrys(arrid, indext, false)}> + : ""} +

)} +
+ ) + })} + +
+ {itemo.question.question_type === 1 ? ( +
+
+ {polls_status === undefined || polls_status === 1 ? + this.Ewoption(itemo.question.id, itemo)}>新增选项 + + : ""} + {polls_status === undefined || polls_status === 1 ? + + (newoption === false ? + this.Addanotheroption(itemo.question.id)}>新增其他选项 + : "") + : ""} + + this.Deleteadddom(indexo)}>取消 + this.Deleteadddomthree(indexo, itemo)}>保存 + this.Deleteadddomtwo(indexo, itemo)}>保存并继续 + +
+
+ + + ) + + + : itemo.question.question_type === 2 ? ( + //////////////////////////////////////////// 可选 +
+
+
+ 可选 +
+ {/*可选最小*/} + + + ~ + {/*可选最大*/} + + + (学生答题时,系统对其选择的选项个数进行限制,--表示不限制) +
+ +
+
+
+ ) + + : (
) + + } +
+
+ {itemo.question.question_type === 2 ? + ( + polls_status === undefined || polls_status === 1 ? +
+ +
this.Ewoption(itemo.question.id, itemo)}>新增选项 + + { + newoption === false ? this.Addanotheroption(itemo.question.id)}>新增其他选项 : "" + } + +
+ + + + this.Deleteadddom(indexo)}>取消 + this.Deleteadddomthree(indexo, itemo)}>保存 + this.Deleteadddomtwo(indexo, itemo)}>保存并继续 + +
+ + + : +
+ + this.Deleteadddom(indexo)}>取消 + this.Deleteadddomthree(indexo, itemo)}>保存 + this.Deleteadddomtwo(indexo, itemo)}>保存并继续 + +
+ ) + + : itemo.question.question_type === 3 ? +
+ + this.Deleteadddom(indexo)}>取消 + this.Deleteadddomthree(indexo, itemo)}>保存 + this.Deleteadddomtwo(indexo, itemo)}>保存并继续 + +
+ : + ""} + + +
+
+ + + return ( +
+ {resultDomtwo} +
+ ) + })} +
+ : + "" + } + + + + +
+
+ + {/*
*/} +
+
+
+ ) + } + +} + +// RouteHOC() +export default PollNewQuestbank +{/*
*/} +{/* {*/} +{/* this.props.match.params.news === "new" ?*/} +{/* this.state.Newedit === false ?*/} +{/*
*/} +{/*
*/} + +{/*
*/} +{/* this.addmysingles()}>单选题*/} +{/* this.addmydoubles()}>多选题*/} +{/* this.addmymainsint()}>主观题*/} +{/*
*/} +{/*
*/} +{/* : ""*/} +{/* :*/} +{/*
*/} +{/*
*/} +{/*
*/} +{/* this.addmysingles()}>单选题*/} +{/* this.addmydoubles()}>多选题*/} +{/* this.addmymainsint()}>主观题*/} +{/*
*/} +{/*
*/} +{/* }*/} +{/*
*/} +{/*{*/} +{/* this.props.match.params.news === "new" ?*/} +{/* (this.state.Newedit === false ?*/} +{/* */} +{/*
  • */} +{/* this.props.history.goBack()}>取消*/} +{/* this.submitQuestionnaire(this.props.match.params.news)}>提交*/} +{/*
  • */} + + +{/*
    */} + +{/* : "")*/} +{/* :*/} +{/* */} +{/*}*/} \ No newline at end of file diff --git a/public/react/src/modules/courses/questionbank/Generaljobanswer.js b/public/react/src/modules/courses/questionbank/Generaljobanswer.js index 3bfc6cd36..d8d86ffa5 100644 --- a/public/react/src/modules/courses/questionbank/Generaljobanswer.js +++ b/public/react/src/modules/courses/questionbank/Generaljobanswer.js @@ -55,18 +55,19 @@ class Generaljobanswer extends Component { render() { - + let{datas}=this.props return (
    -
    +
    + {datas.attachments === undefined ? "" : datas.attachments.map((item, key) => { + return ( + + ) + })} + -
    diff --git a/public/react/src/modules/courses/questionbank/Generaljobbankdetails.js b/public/react/src/modules/courses/questionbank/Generaljobbankdetails.js index 29453a7b5..04fde589d 100644 --- a/public/react/src/modules/courses/questionbank/Generaljobbankdetails.js +++ b/public/react/src/modules/courses/questionbank/Generaljobbankdetails.js @@ -43,7 +43,7 @@ class Generaljobbankdetails extends Component { console.log(e); console.log("44"); } - + this.getonedata(); } @@ -58,17 +58,19 @@ class Generaljobbankdetails extends Component { this.setState({ tab: type[1], }); - - console.log("Generaljobbankdetails"); console.log(this.props); + this.getonedata(); + } + + getonedata=()=>{ if( this.props.match.params.workid){ this.setState({ workid: this.props.match.params.workid, }) } this.getdata(this.props.match.params.workid); - } + }; //获取数据的地方 getdata=(workid)=>{ var workids= workid; @@ -86,7 +88,7 @@ class Generaljobbankdetails extends Component { if(response){ if(response.data){ this.setState({ - datas:response.data.informs, + datas:response.data, }) }else { this.setState({ @@ -118,7 +120,7 @@ class Generaljobbankdetails extends Component { ///////////////教师截止 render() { - let {tab} = this.state; + let {tab,datas} = this.state; const isAdmin = this.props.isAdmin(); // console.log(119) @@ -141,10 +143,10 @@ class Generaljobbankdetails extends Component {

    - MySQL数据库编程开发实训(基础篇) + {datas&&datas.name}

    @@ -160,8 +162,8 @@ class Generaljobbankdetails extends Component {
    - {parseInt(tab) === 0 ? :""} - {parseInt(tab) === 1 ? :""} + {parseInt(tab) === 0 ? :""} + {parseInt(tab) === 1 ? :""}
    diff --git a/public/react/src/modules/courses/questionbank/Generaljobdetails.js b/public/react/src/modules/courses/questionbank/Generaljobdetails.js index 9de444123..64413b368 100644 --- a/public/react/src/modules/courses/questionbank/Generaljobdetails.js +++ b/public/react/src/modules/courses/questionbank/Generaljobdetails.js @@ -13,14 +13,13 @@ import { import GroupPackage from '../groupjobbank/GroupPackage' import './questionbank.css'; - +//内容详情 class Generaljobdetails extends Component { constructor(props) { super(props); this.state = { - } } @@ -56,18 +55,18 @@ class Generaljobdetails extends Component { render() { - + let{datas}=this.props; return (
    -
    +
    + {datas.attachments === undefined ? "" : datas.attachments.map((item, key) => { + return ( + + ) + })} -
    diff --git a/public/react/src/modules/moop_cases/CaseNew.js b/public/react/src/modules/moop_cases/CaseNew.js index 7d0cd735c..5e3c279bd 100644 --- a/public/react/src/modules/moop_cases/CaseNew.js +++ b/public/react/src/modules/moop_cases/CaseNew.js @@ -1,452 +1,456 @@ -import React,{ Component } from "react"; -import './css/moopCases.css' -import '../courses/css/Courses.css' -import { Form , Input , Upload , Button , Icon , message , Tooltip } from "antd"; - -import { getImageUrl , setImagesUrl , MarkdownToHtml , ActionBtn , appendFileSizeToUploadFile , appendFileSizeToUploadFileAll , getUrl , getUploadActionUrl } from 'educoder'; - -import Tags from './CaseTags' - -import axios from 'axios'; -import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor'; -import _ from 'lodash' -const { Dragger } = Upload; -function beforeUpload(file) { - const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'; - if (!isJpgOrPng) { - message.error('You can only upload JPG/PNG file!'); - } - const isLt2M = file.size / 1024 / 1024 < 2; - if (!isLt2M) { - message.error('Image must smaller than 2MB!'); - } - return isJpgOrPng && isLt2M; -} -function getBase64(img, callback) { - const reader = new FileReader(); - reader.addEventListener('load', () => callback(reader.result)); - reader.readAsDataURL(img); -} - const $ = window.$; -class CaseNew extends Component{ - constructor(props){ - super(props); - this.DescMdRef = React.createRef(); - - this.state={ - casesTags:[], - contentFileList:[], - filesID:[], - imageUrl:undefined, - loading: false, - checkTag:false, - checkFile:false, - coverID:undefined - } - } - - // 上传附件-删除确认框 - onAttachmentRemove = (file, stateName) => { - this.props.confirm({ - content: '是否确认删除?', - onOk: () => { - this.deleteAttachment(file, stateName) - }, - onCancel() { - console.log('Cancel'); - }, - }); - return false; - } - - // 上传附件-确认删除 - 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); - console.log("newFileList"); - console.log(newFileList.map(item =>{ return( item.id )})); - return { - [stateName]: newFileList, - filesID:newFileList.map(item =>{ return( item.id )}) - }; - }); - } - } - }) - .catch(function (error) { - console.log(error); - }); - } - // 上传附件-change - handleContentUploadChange = (info) => { - if (info.file.status === 'done' || info.file.status === 'uploading') { - let contentFileList = info.fileList; - this.setState({ contentFileList: appendFileSizeToUploadFileAll(contentFileList)}); - let list = appendFileSizeToUploadFileAll(contentFileList); - let arr = list.map(item=>{ - return ( item.response && item.response.id ) - }) - this.setState({ - filesID:arr, - checkFile:arr.length > 0 ? false : true - }) - } - } - - // 上传封面图-change - handleChange = (info) => { - if (info.file.status === 'uploading') { - this.setState({ loading: true }); - return; - } - if (info.file.status === 'done') { - // Get this url from response in real world. - getBase64(info.file.originFileObj, imageUrl => - this.setState({ - imageUrl, - loading: false - }), - ); - console.log(info.file); - this.setState({ - coverID:info.file.response && info.file.response.id - }) - } - }; - - // 编辑时加载数据 - componentDidMount=()=>{ - if(this.props.match.params.caseID){ - this.InitEditData(); - } - } - - componentDidUpdate=(prevState)=>{ - if(this.props.CaseDetail && prevState.CaseDetail != this.props.CaseDetail){ - this.props.form.setFieldsValue({ - caseTitle:this.props.CaseDetail.title, - userName:this.props.CaseDetail.author_name, - userUnit:this.props.CaseDetail.author_school_name, - }) - this.setState({ - contentFileList:this.props.attachments.map(item => { - return { - id: item.id, - uid: item.id, - name: appendFileSizeToUploadFile(item), - url: item.url, - filesize: item.filesize, - status: 'done' - } - }), - filesID:this.props.attachments.map(item => { - return ( item.id ) - }), - coverID:this.props.cover && this.props.cover.id, - imageUrl:this.props.CaseDetail.cover && setImagesUrl(this.props.CaseDetail.cover.url), - casesTags:this.props.tags.map(item=>{ - return (item.id); - }) - }) - console.log(this.props.attachments.map(item => { - return ( item.id ) - })) - } - } - - InitEditData=()=>{ - let caseID = this.props.match.params.caseID; - this.props.getDetail(caseID); - } - - // 申请提交和保存 - handleSubmit = (type) => { - let caseID = this.props.match.params.caseID; - console.log(type); - this.props.form.validateFieldsAndScroll((err, values) => { - let { casesTags , filesID } = this.state; - if(casesTags.length == 0){ - $("html").animate({ scrollTop: $("#tagFormItem").offset().top - 100 }); - this.setState({ - checkTag:true - }) - return; - } - if(filesID.length == 0){ - $("html").animate({ scrollTop: $("#fileFormItem").offset().top - 100 }); - this.setState({ - checkFile:true - }) - return; - } - - const mdContnet = this.DescMdRef.current.getValue().trim(); - console.log(mdContnet) - values.description = mdContnet; - - console.log(values); - let url = caseID ? `/libraries/${caseID}.json`: `/libraries.json`; - if(caseID){ - axios.put((url),{ - title:values.caseTitle, - author_name:values.userName, - author_school_name:values.userUnit, - content:values.description, - attachment_ids:this.state.contentFileList.map(item=>{ - return (item.response ? item.response.id : item.id ) - }), - tag_ids:this.state.casesTags, - cover_id:this.state.coverID, - publish:type == 'save' ? false : true - }).then((result)=>{ - if(result){ - this.props.showNotification(type == 'save' ? `案例保存成功!`: `提交成功!`); - this.props.history.push(type == 'save' ? `/moop_cases/${result.data.id}` : `/moop_cases/${result.data.id}/publish_success`); - } - }).catch((error)=>{ - console.log(error); - }) - }else{ - axios.post((url),{ - title:values.caseTitle, - author_name:values.userName, - author_school_name:values.userUnit, - content:values.description, - attachment_ids:this.state.filesID, - tag_ids:this.state.casesTags, - cover_id:this.state.coverID, - publish:type == 'save' ? false : true - }).then((result)=>{ - if(result){ - this.props.showNotification(type == 'save' ? `案例保存成功!`: `提交成功!`); - this.props.history.push(type == 'save' ? `/moop_cases/${result.data.id}` : `/moop_cases/${result.data.id}/publish_success`); - } - }).catch((error)=>{ - console.log(error); - }) - } - - }) - } - - // 选择标签 - changeType=(type)=>{ - let tags = []; - if(this.state.casesTags.indexOf(type) > -1){ - tags = this.state.casesTags.filter(item => item != type); - }else{ - tags = this.state.casesTags.concat(type); - } - const tagUniqed = _.uniq(tags); - this.setState({ - casesTags: tagUniqed, - checkTag:tags.length > 0 ? false : true - }) - } - - render(){ - let { caseID } = this.props.match.params; - let { CaseDetail } = this.props; - let { casesTags , contentFileList , imageUrl , checkTag , checkFile } = this.state; - const {getFieldDecorator} = this.props.form; - - - // 上传附件点击事件 - const uploadProps = { - width: 600, - multiple: true, - fileList:contentFileList, - action: `${getUploadActionUrl()}`, - onChange: this.handleContentUploadChange, - onRemove: (file) => this.onAttachmentRemove(file, 'contentFileList'), - beforeUpload: (file) => { - const isLt150M = file.size / 1024 / 1024 < 150; - if (!isLt150M) { - //message.error('文件大小必须小于150MB!'); - this.props.define({ - title:'提示', - content:"该文件无法上传。超过文件大小限制(150MB),建议上传到百度云等其它共享工具里,然后再txt文档里给出链接以及共享密码并上传" - }) - return isLt150M; - } - } - }; - // 上传封面图-html - const uploadButton = ( -
    - -
    - ); - // 上传封面图点击事件 - const uploadCover = { - listType:"picture-card", - className:"avatar-uploader", - showUploadList:false, - action:`${getUploadActionUrl()}`, - onChange:this.handleChange, - } - console.log('111'); - console.log(!caseID || (CaseDetail && CaseDetail.status == "pending")); - return( -
    - -

    - 教学案例 > { caseID ? "编辑" : "新建" } -

    -

    上传教学案例

    -
    -
    - - {getFieldDecorator('caseTitle', { - rules: [{required: true, message: "案例标题不能为空"}], - })( - - )} - 简明扼要介绍文档/视频所包含的主要的内容 - -
    - - {getFieldDecorator('userName', { - rules: [{required: true, message: "请输入作者姓名"}], - })( - - )} - - - {getFieldDecorator('userUnit', { - rules: [{required: true, message: "请输入作者单位名称"}], - })( - - )} - -
    -
    - 标签 -
      -
    • -1 ? "active" :"" } onClick={()=>this.changeType(1)}>获奖案例
    • -
    • -1 ? "active" :"" } onClick={()=>this.changeType(2)}>入库案例
    • -
    - { - checkTag &&
    请选择标签
    - } -
    - - {getFieldDecorator('description', { - rules: [{ - required: true, message: '请输入描述内容' - }], - })( - - )} - -
    - -

    上传附件

    -

    从我的电脑选择要上传的文档:按住CTRL可以上传多份文档。单个文件最大限制:150MB

    -
    - { - checkFile == true &&
    请先上传附件
    - } -
    -

    - 封面图(上传尺寸:120*90 px) -

    -
    - - { imageUrl ? - - avatar - - : - - {uploadButton} - - } - -
    -
    -
    -
  • 审核说明
  • -
      -
    • 平台管理员将对每天新上传的文档进行审核,审核通过的文档将公开显示,否则将私有化或移除
    • -
    -
    -
    -
  • 温馨提示
  • -
      -
    • 1.请勿上传已设置加密口令的文档资源;
    • -
    • 2.可以上传符合教学案例标准的文档资料,如 - 案例入库标准、 - 案例使用说明书以及其他资料等,上传支持的文件最大容量:100MB;
    • -
    • 3.请确保上传内容无侵权或违反国家关于互联网政策的不良行为;
    • -
    • 4.请使用Chrome,Firefox,Safari,IE11(及以上版本)浏览器;
    • -
    -
    - -
    - { - (!caseID || (CaseDetail && CaseDetail.status == "pending" || CaseDetail && CaseDetail.status == "refused")) ? : "" - } - this.handleSubmit("save")}>保存 -
    -
    - -
    - ) - } -} -const WrappedCoursesNewApp = Form.create({name: 'CaseNew'})(CaseNew); +import React,{ Component } from "react"; +import './css/moopCases.css' +import '../courses/css/Courses.css' +import { Form , Input , Upload , Button , Icon , message , Tooltip } from "antd"; + +import { getImageUrl , setImagesUrl , MarkdownToHtml , ActionBtn , appendFileSizeToUploadFile , appendFileSizeToUploadFileAll , getUrl , getUploadActionUrl } from 'educoder'; + +import Tags from './CaseTags' + +import axios from 'axios'; +import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor'; +import _ from 'lodash' +const { Dragger } = Upload; +function beforeUpload(file) { + const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'; + if (!isJpgOrPng) { + message.error('You can only upload JPG/PNG file!'); + } + const isLt2M = file.size / 1024 / 1024 < 2; + if (!isLt2M) { + message.error('Image must smaller than 2MB!'); + } + return isJpgOrPng && isLt2M; +} +function getBase64(img, callback) { + const reader = new FileReader(); + reader.addEventListener('load', () => callback(reader.result)); + reader.readAsDataURL(img); +} + const $ = window.$; +class CaseNew extends Component{ + constructor(props){ + super(props); + this.DescMdRef = React.createRef(); + + this.state={ + casesTags:[], + contentFileList:[], + filesID:[], + imageUrl:undefined, + loading: false, + checkTag:false, + checkFile:false, + coverID:undefined + } + } + + // 上传附件-删除确认框 + onAttachmentRemove = (file, stateName) => { + this.props.confirm({ + content: '是否确认删除?', + onOk: () => { + this.deleteAttachment(file, stateName) + }, + onCancel() { + console.log('Cancel'); + }, + }); + return false; + } + + // 上传附件-确认删除 + 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); + console.log("newFileList"); + console.log(newFileList.map(item =>{ return( item.id )})); + return { + [stateName]: newFileList, + filesID:newFileList.map(item =>{ return( item.id )}) + }; + }); + } + } + }) + .catch(function (error) { + console.log(error); + }); + } + // 上传附件-change + handleContentUploadChange = (info) => { + if (info.file.status === 'done' || info.file.status === 'uploading') { + let contentFileList = info.fileList; + this.setState({ contentFileList: appendFileSizeToUploadFileAll(contentFileList)}); + let list = appendFileSizeToUploadFileAll(contentFileList); + let arr = list.map(item=>{ + return ( item.response && item.response.id ) + }) + this.setState({ + filesID:arr, + checkFile:arr.length > 0 ? false : true + }) + } + } + + // 上传封面图-change + handleChange = (info) => { + if (info.file.status === 'uploading') { + this.setState({ loading: true }); + return; + } + if (info.file.status === 'done') { + // Get this url from response in real world. + getBase64(info.file.originFileObj, imageUrl => + this.setState({ + imageUrl, + loading: false + }), + ); + console.log(info.file); + this.setState({ + coverID:info.file.response && info.file.response.id + }) + } + }; + + // 编辑时加载数据 + componentDidMount=()=>{ + if(this.props.match.params.caseID){ + this.InitEditData(); + } + } + + componentDidUpdate=(prevState)=>{ + if(this.props.CaseDetail && prevState.CaseDetail != this.props.CaseDetail){ + this.props.form.setFieldsValue({ + caseTitle:this.props.CaseDetail.title, + userName:this.props.CaseDetail.author_name, + userUnit:this.props.CaseDetail.author_school_name, + }) + this.setState({ + contentFileList:this.props.attachments.map(item => { + return { + id: item.id, + uid: item.id, + name: appendFileSizeToUploadFile(item), + url: item.url, + filesize: item.filesize, + status: 'done' + } + }), + filesID:this.props.attachments.map(item => { + return ( item.id ) + }), + coverID:this.props.cover && this.props.cover.id, + imageUrl:this.props.CaseDetail.cover && setImagesUrl(this.props.CaseDetail.cover.url), + casesTags:this.props.tags.map(item=>{ + return (item.id); + }) + }) + console.log(this.props.attachments.map(item => { + return ( item.id ) + })) + } + } + + InitEditData=()=>{ + let caseID = this.props.match.params.caseID; + this.props.getDetail(caseID); + } + + // 申请提交和保存 + handleSubmit = (type) => { + let caseID = this.props.match.params.caseID; + console.log(type); + this.props.form.validateFieldsAndScroll((err, values) => { + let { casesTags , filesID } = this.state; + if(casesTags.length == 0){ + $("html").animate({ scrollTop: $("#tagFormItem").offset().top - 100 }); + this.setState({ + checkTag:true + }) + return; + } + if(filesID.length == 0){ + $("html").animate({ scrollTop: $("#fileFormItem").offset().top - 100 }); + this.setState({ + checkFile:true + }) + return; + } + + const mdContnet = this.DescMdRef.current.getValue().trim(); + console.log(mdContnet) + values.description = mdContnet; + + console.log(values); + let url = caseID ? `/libraries/${caseID}.json`: `/libraries.json`; + if(caseID){ + axios.put((url),{ + title:values.caseTitle, + author_name:values.userName, + author_school_name:values.userUnit, + content:values.description, + attachment_ids:this.state.contentFileList.map(item=>{ + return (item.response ? item.response.id : item.id ) + }), + tag_ids:this.state.casesTags, + cover_id:this.state.coverID, + publish:type == 'save' ? false : true + }).then((result)=>{ + if(result){ + this.props.showNotification(type == 'save' ? `案例保存成功!`: `提交成功!`); + this.props.history.push(type == 'save' ? `/moop_cases/${result.data.id}` : `/moop_cases/${result.data.id}/publish_success`); + } + }).catch((error)=>{ + console.log(error); + }) + }else{ + axios.post((url),{ + title:values.caseTitle, + author_name:values.userName, + author_school_name:values.userUnit, + content:values.description, + attachment_ids:this.state.filesID, + tag_ids:this.state.casesTags, + cover_id:this.state.coverID, + publish:type == 'save' ? false : true + }).then((result)=>{ + if(result){ + this.props.showNotification(type == 'save' ? `案例保存成功!`: `提交成功!`); + this.props.history.push(type == 'save' ? `/moop_cases/${result.data.id}` : `/moop_cases/${result.data.id}/publish_success`); + } + }).catch((error)=>{ + console.log(error); + }) + } + + }) + } + + // 选择标签 + changeType=(type)=>{ + // console.log(this.state.casesTags); + // debugger + let tags = []; + + if(this.state.casesTags.indexOf(type) > -1){ + tags = this.state.casesTags.filter(item => item != type); + }else{ + tags = this.state.casesTags.concat(type); + } + const tagUniqed = _.uniq(tags); + this.setState({ + casesTags: tagUniqed, + checkTag:tags.length > 0 ? false : true + }) + } + + render(){ + let { caseID } = this.props.match.params; + let { CaseDetail } = this.props; + let { casesTags , contentFileList , imageUrl , checkTag , checkFile } = this.state; + const {getFieldDecorator} = this.props.form; + + + // 上传附件点击事件 + const uploadProps = { + width: 600, + multiple: true, + fileList:contentFileList, + action: `${getUploadActionUrl()}`, + onChange: this.handleContentUploadChange, + onRemove: (file) => this.onAttachmentRemove(file, 'contentFileList'), + beforeUpload: (file) => { + const isLt150M = file.size / 1024 / 1024 < 150; + if (!isLt150M) { + //message.error('文件大小必须小于150MB!'); + this.props.define({ + title:'提示', + content:"该文件无法上传。超过文件大小限制(150MB),建议上传到百度云等其它共享工具里,然后再txt文档里给出链接以及共享密码并上传" + }) + return isLt150M; + } + } + }; + // 上传封面图-html + const uploadButton = ( +
    + +
    + ); + // 上传封面图点击事件 + const uploadCover = { + listType:"picture-card", + className:"avatar-uploader", + showUploadList:false, + action:`${getUploadActionUrl()}`, + onChange:this.handleChange, + } + console.log('111'); + console.log(!caseID || (CaseDetail && CaseDetail.status == "pending")); + return( +
    + +

    + 教学案例 > { caseID ? "编辑" : "新建" } +

    +

    上传教学案例

    +
    +
    + + {getFieldDecorator('caseTitle', { + rules: [{required: true, message: "案例标题不能为空"}], + })( + + )} + 简明扼要介绍文档/视频所包含的主要的内容 + +
    + + {getFieldDecorator('userName', { + rules: [{required: true, message: "请输入作者姓名"}], + })( + + )} + + + {getFieldDecorator('userUnit', { + rules: [{required: true, message: "请输入作者单位名称"}], + })( + + )} + +
    +
    + 标签 +
      +
    • -1 ? "active" :"" } onClick={()=>this.changeType(1)}>获奖案例
    • +
    • -1 ? "active" :"" } onClick={()=>this.changeType(2)}>入库案例
    • + {/*
    • -1 ? "active" : ""} onclick={() => this.changeType(3)}>企业案例
    • */} +
    + { + checkTag &&
    请选择标签
    + } +
    + + {getFieldDecorator('description', { + rules: [{ + required: true, message: '请输入描述内容' + }], + })( + + )} + +
    + +

    上传附件

    +

    从我的电脑选择要上传的文档:按住CTRL可以上传多份文档。单个文件最大限制:150MB

    +
    + { + checkFile == true &&
    请先上传附件
    + } +
    +

    + 封面图(上传尺寸:120*90 px) +

    +
    + + { imageUrl ? + + avatar + + : + + {uploadButton} + + } + +
    +
    +
    +
  • 审核说明
  • +
      +
    • 平台管理员将对每天新上传的文档进行审核,审核通过的文档将公开显示,否则将私有化或移除
    • +
    +
    +
    +
  • 温馨提示
  • +
      +
    • 1.请勿上传已设置加密口令的文档资源;
    • +
    • 2.可以上传符合教学案例标准的文档资料,如 + 案例入库标准、 + 案例使用说明书以及其他资料等,上传支持的文件最大容量:100MB;
    • +
    • 3.请确保上传内容无侵权或违反国家关于互联网政策的不良行为;
    • +
    • 4.请使用Chrome,Firefox,Safari,IE11(及以上版本)浏览器;
    • +
    +
    + +
    + { + (!caseID || (CaseDetail && CaseDetail.status == "pending" || CaseDetail && CaseDetail.status == "refused")) ? : "" + } + this.handleSubmit("save")}>保存 +
    +
    + +
    + ) + } +} +const WrappedCoursesNewApp = Form.create({name: 'CaseNew'})(CaseNew); export default WrappedCoursesNewApp; \ No newline at end of file diff --git a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js index a011dc1b2..e7e8a1d75 100644 --- a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js +++ b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js @@ -1384,20 +1384,23 @@ export default class TPMsettings extends Component { } onAttachmentRemove = (file) => { - confirm({ - title: '确定要删除这个附件吗?', - okText: '确定', - cancelText: '取消', - // content: 'Some descriptions', - onOk: () => { - console.log("665") - this.deleteAttachment(file) - }, - onCancel() { - console.log('Cancel'); - }, - }); - return false; + if(file.response!=undefined){ + confirm({ + title: '确定要删除这个附件吗?', + okText: '确定', + cancelText: '取消', + // content: 'Some descriptions', + onOk: () => { + console.log("665") + this.deleteAttachment(file) + }, + onCancel() { + console.log('Cancel'); + }, + }); + return false; + } + } deleteAttachment = (file) => { diff --git a/public/react/src/modules/tpm/newshixuns/Newshixuns.js b/public/react/src/modules/tpm/newshixuns/Newshixuns.js index fbbc807b5..8d4191b44 100644 --- a/public/react/src/modules/tpm/newshixuns/Newshixuns.js +++ b/public/react/src/modules/tpm/newshixuns/Newshixuns.js @@ -772,20 +772,23 @@ class Newshixuns extends Component { } onAttachmentRemove = (file) => { - confirm({ - title: '确定要删除这个附件吗?', - okText: '确定', - cancelText: '取消', - // content: 'Some descriptions', - onOk: () => { - console.log("665") - this.deleteAttachment(file) - }, - onCancel() { - console.log('Cancel'); - }, - }); - return false; + if(file.response!=undefined){ + 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); diff --git a/public/react/src/modules/user/usersInfo/InfosTopics.js b/public/react/src/modules/user/usersInfo/InfosTopics.js index cf2c1eaa0..62ef259ad 100644 --- a/public/react/src/modules/user/usersInfo/InfosTopics.js +++ b/public/react/src/modules/user/usersInfo/InfosTopics.js @@ -457,7 +457,7 @@ class InfosTopics extends Component{