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