From eada0a6f795027cd8ae38e2db440948f404fb9ff Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 09:21:01 +0800 Subject: [PATCH 01/21] update edit page --- public/react/src/constants/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/react/src/constants/index.js b/public/react/src/constants/index.js index 3e7aceab0..c0e6074fc 100644 --- a/public/react/src/constants/index.js +++ b/public/react/src/constants/index.js @@ -3,8 +3,8 @@ * @Author: tangjiang * @Github: * @Date: 2019-11-20 23:10:48 - * @LastEditors: tangjiang - * @LastEditTime: 2019-12-06 15:53:27 + * @LastEditors : tangjiang + * @LastEditTime : 2019-12-30 09:19:52 */ const CONST = { jcLabel: { @@ -12,9 +12,10 @@ const CONST = { language: '编程语言', description: '描述', difficult: '难易度', - category: '分类', + category: '课程', openOrNot: '公开程序', - timeLimit: '时间限制' + timeLimit: '时间限制', + // knowledge: '知识点' }, fontSetting: { title: '代码格式', From bbc079b7036e61483a1c3f5c3018f7efd869c515 Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 11:09:01 +0800 Subject: [PATCH 02/21] add course question --- .../newOrEditTask/leftpane/editorTab/index.js | 92 +++++++++++++++++-- .../modules/developer/split_pane_resizer.scss | 4 + public/react/src/redux/actions/actionTypes.js | 2 + public/react/src/redux/actions/index.js | 3 + public/react/src/redux/actions/ojForm.js | 23 ++++- .../react/src/redux/reducers/ojFormReducer.js | 8 +- public/react/src/services/ojService.js | 8 +- 7 files changed, 127 insertions(+), 13 deletions(-) diff --git a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js index d4fc12b9c..8172a7778 100644 --- a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js +++ b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js @@ -4,12 +4,12 @@ * @Github: * @Date: 2019-11-20 10:35:40 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-27 14:30:55 + * @LastEditTime : 2019-12-30 11:05:14 */ import './index.scss'; // import 'katex/dist/katex.css'; import React from 'react'; -import { Form, Input, Select, InputNumber, Button } from 'antd'; +import { Form, Input, Select, InputNumber, Button, Cascader } from 'antd'; import { connect } from 'react-redux'; import AddTestDemo from './AddTestDemo'; // import QuillEditor from '../../../quillEditor'; @@ -77,6 +77,10 @@ class EditTab extends React.Component { }, () => { this.state.scrollEl.addEventListener('scroll', this.handleScroll, false); }); + // 获取题库 + this.props.getQuestion({ + source: 'question' + }); } componentWillUnmount () { @@ -127,7 +131,8 @@ class EditTab extends React.Component { } // 改变分类 handleChangeCategory = (value) => { - this.props.validateOjCategory(value); + console.log(value); + // this.props.validateOjCategory(value); } // 改变公开程序 handleChangeOpenOrNot = (value) => { @@ -146,7 +151,8 @@ class EditTab extends React.Component { addTestCase, // 添加测试用例 deleteTestCase, // 删除测试用例 testCasesValidate, - openTestCodeIndex = [] + openTestCodeIndex = [], + courseQuestions } = this.props; // 表单label const myLabel = (name, subTitle) => { @@ -244,6 +250,59 @@ class EditTab extends React.Component { ['image', 'formula'], // 数学公式、图片、视频 ['clean'], // 清除格式 ]; + + const renderCourseQuestion = (arrs) => { + const tempArr = []; + function loop (arrs, tempArr) { + arrs.forEach(item => { + const obj = {}; + obj.value = item.id; + obj.label = item.name; + // 当item下还有子元素时,递归调用 + if (item.sub_disciplines || item.tag_disciplines) { + arrs = item.sub_disciplines || item.tag_disciplines; + obj.children = []; + loop(arrs, obj.children); + } + tempArr.push(obj); + }); + } + loop(arrs, tempArr); + // arrs.forEach(item => { + // const obj = Object.create(null); + // obj.value = item.id; + // obj.label = item.name; + // if (item.sub_disciplines) { + // obj.children = []; + // item.sub_disciplines.forEach(sub => { + // const subObj = Object.create(null); + // subObj.value = sub.id; + // subObj.label = sub.name; + + // if (sub.tag_disciplines) { + // subObj.children = []; + // sub.tag_disciplines.forEach(tag => { + // const tabObj = Object.create(null); + // tabObj.value = tag.id; + // tabObj.label = tag.name; + // subObj.children.push(tabObj); + // }); + // } + // obj.children.push(subObj); + // }) + // } + // tempArr.push(obj); + // }); + console.log(tempArr); + return ( + + ) + } return (
@@ -262,14 +321,24 @@ class EditTab extends React.Component { {myLabel(jcLabel['category'], '合理的分类有利于快速检索')}} + label={{myLabel(jcLabel['category'], '合理的课程分类有利于快速检索')}} validateStatus={ojFormValidate.category.validateStatus} help={ojFormValidate.category.errMsg} colon={ false } > - {getOptions('category')} - + */} + {/* */} + { renderCourseQuestion(courseQuestions)} + + + + { testCases, openTestCodeIndex, testCasesValidate, - ojFormValidate} = ojFormReducer; + ojFormValidate, + courseQuestions + } = ojFormReducer; return { ojForm, testCases, testCasesValidate, ojFormValidate, position, - openTestCodeIndex + openTestCodeIndex, + courseQuestions }; }; @@ -390,6 +462,8 @@ const mapDispatchToProps = (dispatch) => ({ addTestCase: (value) => dispatch(actions.addTestCase(value)), // 删除测试用例 deleteTestCase: (value) => dispatch(actions.deleteTestCase(value)), + // 获取题库 + getQuestion: (params) => dispatch(actions.getQuestion(params)) }); export default connect( diff --git a/public/react/src/modules/developer/split_pane_resizer.scss b/public/react/src/modules/developer/split_pane_resizer.scss index 8fc8b525f..26fc21479 100644 --- a/public/react/src/modules/developer/split_pane_resizer.scss +++ b/public/react/src/modules/developer/split_pane_resizer.scss @@ -23,6 +23,8 @@ } .header_title{ + font-size: 16px; + font-weight: bold; text-align: center; } @@ -82,6 +84,8 @@ bottom: 0; top: 0; text-align: center; + font-size: 16px; + font-weight: bold; } } } diff --git a/public/react/src/redux/actions/actionTypes.js b/public/react/src/redux/actions/actionTypes.js index 73e3ea0b2..e3ae7044b 100644 --- a/public/react/src/redux/actions/actionTypes.js +++ b/public/react/src/redux/actions/actionTypes.js @@ -32,6 +32,8 @@ const types = { TEST_CASE_INPUT_CHANGE: 'TEST_CASE_INPUT_CHANGE', // 测试用例输入值改变时 TEST_CASE_OUTPUT_CHANGE: 'TEST_CASE_OUTPUT_CHANGE', // 测试用例输出值改变时 DEBUGGER_CODE: 'DEBUGGER_CODE', // 调试代码 + GET_COURSE_QUESTION: 'GET_COURSE_QUESTION', // 获取编辑题 + // study SAVE_USER_PROGRAM_ID: 'SAVE_USER_PROGRAM_ID',// 保存用户编程题id值 USER_PROGRAM_DETAIL: 'USER_PROGRAM_DETAIL', // 用户编程题详情 SHOW_OR_HIDE_CONTROL: 'SHOW_OR_HIDE_CONTROL', // 显示或隐藏控制台 diff --git a/public/react/src/redux/actions/index.js b/public/react/src/redux/actions/index.js index 988a0a469..263e367df 100644 --- a/public/react/src/redux/actions/index.js +++ b/public/react/src/redux/actions/index.js @@ -32,6 +32,7 @@ import { updateTestAndValidate, updateOpenTestCaseIndex, handleClickCancelPublish, + getQuestion } from './ojForm'; import { @@ -110,6 +111,8 @@ export default { validateOjCategory, validateOpenOrNot, handleClickCancelPublish, + getQuestion, + // addTestCase, deleteTestCase, testCaseInputChange, diff --git a/public/react/src/redux/actions/ojForm.js b/public/react/src/redux/actions/ojForm.js index 118295802..401c4f203 100644 --- a/public/react/src/redux/actions/ojForm.js +++ b/public/react/src/redux/actions/ojForm.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 16:35:46 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-27 22:19:15 + * @LastEditTime : 2019-12-30 09:56:39 */ import types from './actionTypes'; import CONST from '../../constants'; @@ -12,7 +12,8 @@ import { fetchPostOjForm, fetchGetOjById, publishTask, - cancelPublicTask + cancelPublicTask, + fetchQuestion } from '../../services/ojService'; import { Base64 } from 'js-base64'; import { notification } from 'antd'; @@ -644,3 +645,21 @@ export const updateOpenTestCaseIndex = (value) => { payload: value } } + +// 获取课程题库 +export const getQuestion = (params) => { + // return { + // type: types.GET_COURSE_QUESTION, + // } + return (dispatch) => { + fetchQuestion(params).then(res => { + const { data = {} } = res; + const { disciplines = [] } = data; + console.log('获取课程题库成功: ', res); + dispatch({ + type: types.GET_COURSE_QUESTION, + payload: disciplines + }) + }) + } +} diff --git a/public/react/src/redux/reducers/ojFormReducer.js b/public/react/src/redux/reducers/ojFormReducer.js index 952919aca..5beba6653 100644 --- a/public/react/src/redux/reducers/ojFormReducer.js +++ b/public/react/src/redux/reducers/ojFormReducer.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 16:40:32 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-27 20:00:26 + * @LastEditTime : 2019-12-30 09:55:37 */ import { Base64 } from 'js-base64'; import types from '../actions/actionTypes'; @@ -67,6 +67,7 @@ const init = { testCodeStatus: 'default', // 调试代码状态 default(默认值) | loading(加载中) | loaded(加载完成) | userCase(用户自定义测试用例) | finish(测试完成) openTestCodeIndex: [0], // 展开的测试用例: 数组, 当出错时,展开所有出错的测试用例, 默认展开第一个 isPublish: 0, // 是否是发布状态: 0 未发布 1 已发布 + courseQuestions: [], // 课程题库 } const tcValidateObj = { @@ -306,6 +307,11 @@ const ojFormReducer = (state = initialState, action) => { ...state, openTestCodeIndex: tempArr } + case types.GET_COURSE_QUESTION: + return { + ...state, + courseQuestions: action.payload + } default: return state; } diff --git a/public/react/src/services/ojService.js b/public/react/src/services/ojService.js index 04fde2224..59151e687 100644 --- a/public/react/src/services/ojService.js +++ b/public/react/src/services/ojService.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 10:55:38 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-27 11:06:27 + * @LastEditTime : 2019-12-30 09:44:56 */ import axios from 'axios'; @@ -142,4 +142,10 @@ export async function fetchUploadImageUrl (id) { export async function fetchAddNotes (identifier, params) { const url = `/myproblems/${identifier}/add_notes.json`; return axios.post(url, params); +} + +// 获取课程体系 +export async function fetchQuestion (params) { + const url = `/disciplines.json`; + return axios.get(url, { params }); } \ No newline at end of file From 1075b49f6acc0a27accc16bbeae3fd1e9b60ab58 Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 14:23:40 +0800 Subject: [PATCH 03/21] add selector --- .../developer/components/knowledge/index.js | 47 +++++++++++++++++++ .../developer/components/knowledge/index.scss | 0 2 files changed, 47 insertions(+) create mode 100644 public/react/src/modules/developer/components/knowledge/index.js create mode 100644 public/react/src/modules/developer/components/knowledge/index.scss diff --git a/public/react/src/modules/developer/components/knowledge/index.js b/public/react/src/modules/developer/components/knowledge/index.js new file mode 100644 index 000000000..b4328376d --- /dev/null +++ b/public/react/src/modules/developer/components/knowledge/index.js @@ -0,0 +1,47 @@ +/* + * @Description: 知识点 + * @Author: tangjiang + * @Github: + * @Date: 2019-12-30 13:51:19 + * @LastEditors : tangjiang + * @LastEditTime : 2019-12-30 14:20:50 + */ +import './index.scss'; +import React, { useState } from 'react'; +import { Select } from 'antd'; + +function KnowLedge (props) { + + const { + options = [], // 下拉选项 + values = [], // 已选择的下拉项 + } = props; + + // 显示的下拉项 + const [selectOptions, setSelectOptions] = useState(options); + // 已选择的下拉项 + const [selectValue, setSelectValue] = useState(values); + + // 渲染下拉选项 + // 渲染下拉列表 + const renderSelect = (options, values) => { + return ( + + ) + } + + return ( +
+ { renderSelect(selectOptions, selectValue) } +
+ +
+
+ ); +} + +export default KnowLedge; diff --git a/public/react/src/modules/developer/components/knowledge/index.scss b/public/react/src/modules/developer/components/knowledge/index.scss new file mode 100644 index 000000000..e69de29bb From 9a97db2893bfbc6c35c7cc9d0660ba0f023af0fe Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 14:31:13 +0800 Subject: [PATCH 04/21] add selector --- .../modules/developer/components/knowledge/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/developer/components/knowledge/index.js b/public/react/src/modules/developer/components/knowledge/index.js index b4328376d..81e9f770a 100644 --- a/public/react/src/modules/developer/components/knowledge/index.js +++ b/public/react/src/modules/developer/components/knowledge/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-12-30 13:51:19 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 14:20:50 + * @LastEditTime : 2019-12-30 14:28:17 */ import './index.scss'; import React, { useState } from 'react'; @@ -23,13 +23,22 @@ function KnowLedge (props) { const [selectValue, setSelectValue] = useState(values); // 渲染下拉选项 + const renderOptions = () => { + + } + const handleSelectChange = (value) => { + console.log(value); + } + // 渲染下拉列表 const renderSelect = (options, values) => { return ( ) } From 8ac904a82d24f640b7f39e211556ad3fd5f7b785 Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 16:58:10 +0800 Subject: [PATCH 05/21] add selector --- public/react/src/constants/index.js | 4 +- .../developer/components/knowledge/index.js | 14 +++++-- .../newOrEditTask/leftpane/editorTab/index.js | 41 ++++++++++++++----- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/public/react/src/constants/index.js b/public/react/src/constants/index.js index c0e6074fc..623cff362 100644 --- a/public/react/src/constants/index.js +++ b/public/react/src/constants/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 23:10:48 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 09:19:52 + * @LastEditTime : 2019-12-30 14:44:45 */ const CONST = { jcLabel: { @@ -15,7 +15,7 @@ const CONST = { category: '课程', openOrNot: '公开程序', timeLimit: '时间限制', - // knowledge: '知识点' + knowledge: '知识点' }, fontSetting: { title: '代码格式', diff --git a/public/react/src/modules/developer/components/knowledge/index.js b/public/react/src/modules/developer/components/knowledge/index.js index 81e9f770a..63d99b762 100644 --- a/public/react/src/modules/developer/components/knowledge/index.js +++ b/public/react/src/modules/developer/components/knowledge/index.js @@ -4,12 +4,14 @@ * @Github: * @Date: 2019-12-30 13:51:19 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 14:28:17 + * @LastEditTime : 2019-12-30 16:54:30 */ import './index.scss'; import React, { useState } from 'react'; import { Select } from 'antd'; +const { Option } = Select; + function KnowLedge (props) { const { @@ -23,8 +25,11 @@ function KnowLedge (props) { const [selectValue, setSelectValue] = useState(values); // 渲染下拉选项 - const renderOptions = () => { - + const renderOptions = (options = []) => { + console.log('下拉选择: ', options); + return options.map((opt, i) => ( + + )); } const handleSelectChange = (value) => { console.log(value); @@ -34,9 +39,12 @@ function KnowLedge (props) { const renderSelect = (options, values) => { return ( diff --git a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js index 8172a7778..4672a3be7 100644 --- a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js +++ b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 10:35:40 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 11:05:14 + * @LastEditTime : 2019-12-30 16:42:36 */ import './index.scss'; // import 'katex/dist/katex.css'; @@ -18,6 +18,7 @@ import CONST from '../../../../../constants'; import { toStore } from 'educoder'; // 保存和读取store值 // import Wrapper from '../../../../../common/reactQuill'; import QuillForEditor from '../../../../../common/quillForEditor'; +import KnowLedge from '../../../components/knowledge'; const scrollIntoView = require('scroll-into-view'); const {jcLabel} = CONST; const FormItem = Form.Item; @@ -59,7 +60,8 @@ class EditTab extends React.Component { scrollHeight: 0, // 滚动元素的高度 top: 500, bottom: 20, - offsetTop: 0 + offsetTop: 0, + knowledges: ['HTML', 'CSS', 'JS', 'REACT'] } } @@ -131,8 +133,21 @@ class EditTab extends React.Component { } // 改变分类 handleChangeCategory = (value) => { - console.log(value); - // this.props.validateOjCategory(value); + // 课程下拉值变化时, 同步更新知识点 + const { courseQuestions } = this.props; + courseQuestions.forEach(item => { + if (value[0] && item.id === value[0]) { + item.sub_disciplines && item.sub_disciplines.forEach(c => { + if (value[1] && c.id === value[1]) { + // tempArr = c.tag_disciplines || []; + console.log('+++++', c.tag_disciplines); + this.setState({ + knowledges: c.tag_disciplines || [] + }); + } + }); + } + }); } // 改变公开程序 handleChangeOpenOrNot = (value) => { @@ -154,6 +169,7 @@ class EditTab extends React.Component { openTestCodeIndex = [], courseQuestions } = this.props; + const {knowledges} = this.state; // 表单label const myLabel = (name, subTitle) => { if (subTitle) { @@ -259,8 +275,8 @@ class EditTab extends React.Component { obj.value = item.id; obj.label = item.name; // 当item下还有子元素时,递归调用 - if (item.sub_disciplines || item.tag_disciplines) { - arrs = item.sub_disciplines || item.tag_disciplines; + if (item.sub_disciplines) { + arrs = item.sub_disciplines; obj.children = []; loop(arrs, obj.children); } @@ -297,7 +313,6 @@ class EditTab extends React.Component { return ( @@ -337,10 +352,16 @@ class EditTab extends React.Component { { renderCourseQuestion(courseQuestions)}
- - + {myLabel(jcLabel['knowledge'])}} + > + - + {myLabel(jcLabel['timeLimit'], '程序允许时间限制时长,单位:秒')}} From f7f4c413719265b125a0bd78f678384f1a954dcd Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 18:28:27 +0800 Subject: [PATCH 06/21] add selector --- .../src/modules/developer/components/knowledge/index.js | 9 +++------ .../modules/developer/components/knowledge/index.scss | 5 +++++ .../developer/newOrEditTask/leftpane/editorTab/index.js | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/public/react/src/modules/developer/components/knowledge/index.js b/public/react/src/modules/developer/components/knowledge/index.js index 63d99b762..17cf11624 100644 --- a/public/react/src/modules/developer/components/knowledge/index.js +++ b/public/react/src/modules/developer/components/knowledge/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-12-30 13:51:19 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 16:54:30 + * @LastEditTime : 2019-12-30 18:02:20 */ import './index.scss'; import React, { useState } from 'react'; @@ -33,6 +33,8 @@ function KnowLedge (props) { } const handleSelectChange = (value) => { console.log(value); + const _result = selectOptions.filter(item => item !== value); + setSelectOptions(_result); } // 渲染下拉列表 @@ -43,8 +45,6 @@ function KnowLedge (props) { placeholder="请选择" style={{ width: '100%' }} onChange={handleSelectChange} - autoClearSearchValue={true} - maxTagCount={0} > {renderOptions(options)} @@ -54,9 +54,6 @@ function KnowLedge (props) { return (
{ renderSelect(selectOptions, selectValue) } -
- -
); } diff --git a/public/react/src/modules/developer/components/knowledge/index.scss b/public/react/src/modules/developer/components/knowledge/index.scss index e69de29bb..a38f42c70 100644 --- a/public/react/src/modules/developer/components/knowledge/index.scss +++ b/public/react/src/modules/developer/components/knowledge/index.scss @@ -0,0 +1,5 @@ +.knowledge-select-area{ + .ant-select-selection__rendered{ + margin-bottom: 0 !important; + } +} diff --git a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js index 4672a3be7..4c5d89dce 100644 --- a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js +++ b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 10:35:40 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 16:42:36 + * @LastEditTime : 2019-12-30 17:53:18 */ import './index.scss'; // import 'katex/dist/katex.css'; From f7fc049d7e51d7523a3cd114fb255db28227eaeb Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 19:30:56 +0800 Subject: [PATCH 07/21] add --- public/react/src/AppConfig.js | 13 +++++++------ .../modules/developer/components/knowledge/index.js | 12 ++++++++---- .../developer/components/knowledge/index.scss | 4 ++++ .../newOrEditTask/leftpane/editorTab/index.js | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index 859b5f579..4e91938c8 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -63,11 +63,11 @@ export function initAxiosInterceptors(props) { const requestMap = {}; window.railsgettimes = function(proxy) { - $.ajax({url:`${proxy}/api/main/first_stamp.json`,async:false,success:function(data,status){ - if(data.status===0){ - return data.message; - } - }}); + // $.ajax({url:`${proxy}/api/main/first_stamp.json`,async:false,success:function(data,status){ + // if(data.status===0){ + // return data.message; + // } + // }}); } window.setfalseInRequestMap = function(keyName) { @@ -101,8 +101,9 @@ export function initAxiosInterceptors(props) { } } if(`${config[0]}`!=`true`){ + let timestamp = Date.parse(new Date())/1000; if (window.location.port === "3007") { - let timestamp=railsgettimes(proxy); + // let timestamp=railsgettimes(proxy); console.log(timestamp) let newopens=md5(opens+timestamp) config.url = `${proxy}${url}`; diff --git a/public/react/src/modules/developer/components/knowledge/index.js b/public/react/src/modules/developer/components/knowledge/index.js index 17cf11624..5677d3630 100644 --- a/public/react/src/modules/developer/components/knowledge/index.js +++ b/public/react/src/modules/developer/components/knowledge/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-12-30 13:51:19 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 18:02:20 + * @LastEditTime : 2019-12-30 19:21:56 */ import './index.scss'; import React, { useState } from 'react'; @@ -23,6 +23,8 @@ function KnowLedge (props) { const [selectOptions, setSelectOptions] = useState(options); // 已选择的下拉项 const [selectValue, setSelectValue] = useState(values); + // + const [value] = useState([]); // 渲染下拉选项 const renderOptions = (options = []) => { @@ -32,8 +34,9 @@ function KnowLedge (props) { )); } const handleSelectChange = (value) => { - console.log(value); - const _result = selectOptions.filter(item => item !== value); + console.log('过滤结果Start=====》》》》》', selectOptions, value); + const _result = selectOptions.filter(item => item !== value.join('')); + console.log('过滤结果=====》》》》》', _result, selectOptions); setSelectOptions(_result); } @@ -41,7 +44,8 @@ function KnowLedge (props) { const renderSelect = (options, values) => { return ( { if (value[1] && c.id === value[1]) { - // tempArr = c.tag_disciplines || []; - console.log('+++++', c.tag_disciplines); this.setState({ - knowledges: c.tag_disciplines || [] + knowledges: [...c.tag_disciplines] + }); + } else { + this.setState({ + knowledges: [] }); } }); + } else { + this.setState({ + knowledges: [] + }); } }); } From a2e80d190ca8c310ff12aae3af942309592f542a Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Mon, 30 Dec 2019 20:47:08 +0800 Subject: [PATCH 11/21] add --- .../developer/components/knowledge/index.js | 33 +++++++++++++------ .../newOrEditTask/leftpane/editorTab/index.js | 11 +++---- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/public/react/src/modules/developer/components/knowledge/index.js b/public/react/src/modules/developer/components/knowledge/index.js index 36060e8e8..5d21b1420 100644 --- a/public/react/src/modules/developer/components/knowledge/index.js +++ b/public/react/src/modules/developer/components/knowledge/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-12-30 13:51:19 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-30 20:08:09 + * @LastEditTime : 2019-12-30 20:44:38 */ import './index.scss'; import React, { useState, useEffect } from 'react'; @@ -32,26 +32,35 @@ function KnowLedge (props) { // 渲染下拉选项 const renderOptions = (options = []) => { - console.log('下拉选择: ', options); return options.map((opt, i) => ( )); } + // 过滤下拉列表项 const handleSelectChange = (value) => { - console.log('过滤结果Start=====》》》》》', selectOptions, value); + value = +value.join(''); + const tempArr = [...selectValue]; const _result = selectOptions.filter(item => { - if (item === value) { - + if (item.id === value && tempArr.findIndex(t => t.id === value) === -1) { + tempArr.push(item); } - return item !== value; + return item.id !== value; }); - console.log('过滤结果=====》》》》》', _result, selectOptions); + console.log(tempArr) + setSelectValue(tempArr); setSelectOptions(_result); } + // 渲染下拉结果 + const renderResult = (arrs) => { + return arrs.map(item => ( +
+ +
+ )); + } // 渲染下拉列表 - const renderSelect = (options, values) => { - console.log('==========>>>>>>>>', options); + const renderSelect = (options) => { return ( { getUserInfoForNew, handleCancelPublish, validateOjForm, + getQuestion // updateTestAndValidate, } = props; @@ -53,6 +54,10 @@ const NewOrEditTask = (props) => { useEffect(() => { // 获取用户信息 getUserInfoForNew(); + // 获取课程列表 + getQuestion({ + source: 'question' + }); // console.log('获取路由参数: ====', props.match.params); const id = props.match.params.id; // 保存OJForm的id号,指明是编辑还是新增 @@ -273,7 +278,8 @@ const mapDispatchToProps = (dispatch) => ({ startProgramQuestion: (id, props) => dispatch(actions.startProgramQuestion(id, props)), // 新建时获取信息 getUserInfoForNew: () => dispatch(actions.getUserInfoForNew()), - validateOjForm: (props, type, cb) => dispatch(actions.validateOjForm(props, type, cb)) + validateOjForm: (props, type, cb) => dispatch(actions.validateOjForm(props, type, cb)), + getQuestion: (params) => dispatch(actions.getQuestion(params)) }); export default withRouter(connect( diff --git a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js index be692ef59..578f4a94e 100644 --- a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js +++ b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 10:35:40 * @LastEditors : tangjiang - * @LastEditTime : 2019-12-31 15:17:08 + * @LastEditTime : 2020-01-02 17:42:04 */ import './index.scss'; // import 'katex/dist/katex.css'; @@ -61,7 +61,8 @@ class EditTab extends React.Component { top: 500, bottom: 20, offsetTop: 0, - knowledges: [] + // knowledges: [], + // coursers: [] // 选中的课程 } } @@ -80,12 +81,16 @@ class EditTab extends React.Component { this.state.scrollEl.addEventListener('scroll', this.handleScroll, false); }); // 获取题库 - this.props.getQuestion({ - source: 'question' - }); + // this.props.getQuestion({ + // source: 'question' + // }); } - componentWillUnmount () { + // componentDidUpdate (nextProp) { + // console.log(nextProp); + // } + + componentWillUnmount (nextPro) { this.state.scrollEl.removeEventListener('scroll', this.handleScroll, false); } @@ -131,30 +136,25 @@ class EditTab extends React.Component { handleTimeLimitChange = (value) => { this.props.validateOjTimeLimit(value); } - // 改变分类 - handleChangeCategory = (value) => { + // 改变方向 + handleChangeSubDisciplineId = (value) => { // 课程下拉值变化时, 同步更新知识点 - const { courseQuestions } = this.props; - this.setState({ - knowledges: [] - }); + const { courseQuestions, saveKnowledge } = this.props; + saveKnowledge([]); // 获取当前分类下的知识点 courseQuestions.forEach(item => { if (value[0] && item.id === value[0]) { item.sub_disciplines && item.sub_disciplines.forEach(c => { if (value[1] && c.id === value[1]) { - this.setState({ - knowledges: [...c.tag_disciplines] - }); + saveKnowledge(...c.tag_disciplines) } else if (!value[1]) { - this.setState({ - knowledges: [] - }); + saveKnowledge([]); } }); } }); - this.props.validateOjCategory(value[1] || ''); + // this.props.validateOjCategory(value[1] || ''); + this.props.validateOjSubDisciplineId(value[1] || ''); } // 改变公开程序 handleChangeOpenOrNot = (value) => { @@ -174,9 +174,12 @@ class EditTab extends React.Component { deleteTestCase, // 删除测试用例 testCasesValidate, openTestCodeIndex = [], - courseQuestions + courseQuestions, + tag_discipline_id, + knowledges } = this.props; - const {knowledges} = this.state; + console.log('+++++++++', knowledges); + // const {knowledges} = this.state; // 表单label const myLabel = (name, subTitle, nostar) => { if (subTitle) { @@ -285,6 +288,7 @@ class EditTab extends React.Component { const renderCourseQuestion = (arrs) => { const tempArr = []; + const sub_id = this.props.ojForm.sub_discipline_id; function loop (arrs, tempArr) { arrs.forEach(item => { const obj = {}; @@ -300,37 +304,30 @@ class EditTab extends React.Component { }); } loop(arrs, tempArr); - // arrs.forEach(item => { - // const obj = Object.create(null); - // obj.value = item.id; - // obj.label = item.name; - // if (item.sub_disciplines) { - // obj.children = []; - // item.sub_disciplines.forEach(sub => { - // const subObj = Object.create(null); - // subObj.value = sub.id; - // subObj.label = sub.name; - - // if (sub.tag_disciplines) { - // subObj.children = []; - // sub.tag_disciplines.forEach(tag => { - // const tabObj = Object.create(null); - // tabObj.value = tag.id; - // tabObj.label = tag.name; - // subObj.children.push(tabObj); - // }); - // } - // obj.children.push(subObj); - // }) - // } - // tempArr.push(obj); - // }); - console.log(tempArr); + + // 获取选中的下拉值 + let choid_ids = []; + // let tempKnowledges = []; + tempArr.forEach(t => { + // debugger; + if (sub_id && t.children) { + t.children.forEach(c => { + if (c.value === sub_id) { + choid_ids = [t.value, c.value]; + // tempKnowledges = c.children || []; + } + }); + } + }); + + console.log(choid_ids); return ( ) } @@ -342,6 +339,8 @@ class EditTab extends React.Component { _result.push(v.id); }); console.log('下拉选择的值:===>>>', _result); + // 保存选择的知识点 + this.props.saveTagDisciplineId(_result); } return ( @@ -361,9 +360,9 @@ class EditTab extends React.Component { {myLabel(jcLabel['category'], '合理的课程分类有利于快速检索')}} - validateStatus={ojFormValidate.category.validateStatus} - help={ojFormValidate.category.errMsg} + label={{myLabel(jcLabel['sub_discipline_id'], '合理的课程分类有利于快速检索')}} + validateStatus={ojFormValidate.sub_discipline_id.validateStatus} + help={ojFormValidate.sub_discipline_id.errMsg} colon={ false } > {/* { if (value[1] && c.id === value[1]) { - saveKnowledge(...c.tag_disciplines) + saveKnowledge(c.tag_disciplines) + console.log(c.tag_disciplines); } else if (!value[1]) { saveKnowledge([]); } @@ -178,7 +179,7 @@ class EditTab extends React.Component { tag_discipline_id, knowledges } = this.props; - console.log('+++++++++', knowledges); + console.log('knowledge======>>>>>>', knowledges); // const {knowledges} = this.state; // 表单label const myLabel = (name, subTitle, nostar) => {