add course question

dev_new_shixunsrepository
tangjiang 5 years ago
parent 640f5acf3b
commit bbc079b703

@ -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) => {
@ -245,6 +251,59 @@ class EditTab extends React.Component {
['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 (
<Cascader
options={tempArr}
value={[1,1,1]}
expandTrigger="hover"
onChange={this.handleChangeCategory}
/>
)
}
return (
<div className={'editor_area'} id="textCase">
<Form className={'editor_form'}>
@ -262,14 +321,24 @@ class EditTab extends React.Component {
<FormItem
className={`input_area flex_50 flex_50_right`}
label={<span>{myLabel(jcLabel['category'], '合理的分类有利于快速检索')}</span>}
label={<span>{myLabel(jcLabel['category'], '合理的课程分类有利于快速检索')}</span>}
validateStatus={ojFormValidate.category.validateStatus}
help={ojFormValidate.category.errMsg}
colon={ false }
>
<Select onChange={this.handleChangeCategory} value={`${ojForm.category}`}>
{/* <Select onChange={this.handleChangeCategory} value={`${ojForm.category}`}>
{getOptions('category')}
</Select>
</Select> */}
{/* <Cascader
options={courseQuestions}
expandTrigger="hover"
onChange={this.handleChangeCategory}
/> */}
{ renderCourseQuestion(courseQuestions)}
</FormItem>
<FormItem>
</FormItem>
<FormItem
@ -366,14 +435,17 @@ const mapStateToProps = (state) => {
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(

@ -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;
}
}
}

@ -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', // 显示或隐藏控制台

@ -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,

@ -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
})
})
}
}

@ -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;
}

@ -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';
@ -143,3 +143,9 @@ 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 });
}
Loading…
Cancel
Save