add course question

dev_new_shixunsrepository
tangjiang 5 years ago
parent 640f5acf3b
commit bbc079b703

@ -4,12 +4,12 @@
* @Github: * @Github:
* @Date: 2019-11-20 10:35:40 * @Date: 2019-11-20 10:35:40
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2019-12-27 14:30:55 * @LastEditTime : 2019-12-30 11:05:14
*/ */
import './index.scss'; import './index.scss';
// import 'katex/dist/katex.css'; // import 'katex/dist/katex.css';
import React from 'react'; 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 { connect } from 'react-redux';
import AddTestDemo from './AddTestDemo'; import AddTestDemo from './AddTestDemo';
// import QuillEditor from '../../../quillEditor'; // import QuillEditor from '../../../quillEditor';
@ -77,6 +77,10 @@ class EditTab extends React.Component {
}, () => { }, () => {
this.state.scrollEl.addEventListener('scroll', this.handleScroll, false); this.state.scrollEl.addEventListener('scroll', this.handleScroll, false);
}); });
// 获取题库
this.props.getQuestion({
source: 'question'
});
} }
componentWillUnmount () { componentWillUnmount () {
@ -127,7 +131,8 @@ class EditTab extends React.Component {
} }
// 改变分类 // 改变分类
handleChangeCategory = (value) => { handleChangeCategory = (value) => {
this.props.validateOjCategory(value); console.log(value);
// this.props.validateOjCategory(value);
} }
// 改变公开程序 // 改变公开程序
handleChangeOpenOrNot = (value) => { handleChangeOpenOrNot = (value) => {
@ -146,7 +151,8 @@ class EditTab extends React.Component {
addTestCase, // 添加测试用例 addTestCase, // 添加测试用例
deleteTestCase, // 删除测试用例 deleteTestCase, // 删除测试用例
testCasesValidate, testCasesValidate,
openTestCodeIndex = [] openTestCodeIndex = [],
courseQuestions
} = this.props; } = this.props;
// 表单label // 表单label
const myLabel = (name, subTitle) => { const myLabel = (name, subTitle) => {
@ -244,6 +250,59 @@ class EditTab extends React.Component {
['image', 'formula'], // 数学公式、图片、视频 ['image', 'formula'], // 数学公式、图片、视频
['clean'], // 清除格式 ['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 ( return (
<div className={'editor_area'} id="textCase"> <div className={'editor_area'} id="textCase">
@ -262,14 +321,24 @@ class EditTab extends React.Component {
<FormItem <FormItem
className={`input_area flex_50 flex_50_right`} className={`input_area flex_50 flex_50_right`}
label={<span>{myLabel(jcLabel['category'], '合理的分类有利于快速检索')}</span>} label={<span>{myLabel(jcLabel['category'], '合理的课程分类有利于快速检索')}</span>}
validateStatus={ojFormValidate.category.validateStatus} validateStatus={ojFormValidate.category.validateStatus}
help={ojFormValidate.category.errMsg} help={ojFormValidate.category.errMsg}
colon={ false } colon={ false }
> >
<Select onChange={this.handleChangeCategory} value={`${ojForm.category}`}> {/* <Select onChange={this.handleChangeCategory} value={`${ojForm.category}`}>
{getOptions('category')} {getOptions('category')}
</Select> </Select> */}
{/* <Cascader
options={courseQuestions}
expandTrigger="hover"
onChange={this.handleChangeCategory}
/> */}
{ renderCourseQuestion(courseQuestions)}
</FormItem>
<FormItem>
</FormItem> </FormItem>
<FormItem <FormItem
@ -366,14 +435,17 @@ const mapStateToProps = (state) => {
testCases, testCases,
openTestCodeIndex, openTestCodeIndex,
testCasesValidate, testCasesValidate,
ojFormValidate} = ojFormReducer; ojFormValidate,
courseQuestions
} = ojFormReducer;
return { return {
ojForm, ojForm,
testCases, testCases,
testCasesValidate, testCasesValidate,
ojFormValidate, ojFormValidate,
position, position,
openTestCodeIndex openTestCodeIndex,
courseQuestions
}; };
}; };
@ -390,6 +462,8 @@ const mapDispatchToProps = (dispatch) => ({
addTestCase: (value) => dispatch(actions.addTestCase(value)), addTestCase: (value) => dispatch(actions.addTestCase(value)),
// 删除测试用例 // 删除测试用例
deleteTestCase: (value) => dispatch(actions.deleteTestCase(value)), deleteTestCase: (value) => dispatch(actions.deleteTestCase(value)),
// 获取题库
getQuestion: (params) => dispatch(actions.getQuestion(params))
}); });
export default connect( export default connect(

@ -23,6 +23,8 @@
} }
.header_title{ .header_title{
font-size: 16px;
font-weight: bold;
text-align: center; text-align: center;
} }
@ -82,6 +84,8 @@
bottom: 0; bottom: 0;
top: 0; top: 0;
text-align: center; 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_INPUT_CHANGE: 'TEST_CASE_INPUT_CHANGE', // 测试用例输入值改变时
TEST_CASE_OUTPUT_CHANGE: 'TEST_CASE_OUTPUT_CHANGE', // 测试用例输出值改变时 TEST_CASE_OUTPUT_CHANGE: 'TEST_CASE_OUTPUT_CHANGE', // 测试用例输出值改变时
DEBUGGER_CODE: 'DEBUGGER_CODE', // 调试代码 DEBUGGER_CODE: 'DEBUGGER_CODE', // 调试代码
GET_COURSE_QUESTION: 'GET_COURSE_QUESTION', // 获取编辑题
// study
SAVE_USER_PROGRAM_ID: 'SAVE_USER_PROGRAM_ID',// 保存用户编程题id值 SAVE_USER_PROGRAM_ID: 'SAVE_USER_PROGRAM_ID',// 保存用户编程题id值
USER_PROGRAM_DETAIL: 'USER_PROGRAM_DETAIL', // 用户编程题详情 USER_PROGRAM_DETAIL: 'USER_PROGRAM_DETAIL', // 用户编程题详情
SHOW_OR_HIDE_CONTROL: 'SHOW_OR_HIDE_CONTROL', // 显示或隐藏控制台 SHOW_OR_HIDE_CONTROL: 'SHOW_OR_HIDE_CONTROL', // 显示或隐藏控制台

@ -32,6 +32,7 @@ import {
updateTestAndValidate, updateTestAndValidate,
updateOpenTestCaseIndex, updateOpenTestCaseIndex,
handleClickCancelPublish, handleClickCancelPublish,
getQuestion
} from './ojForm'; } from './ojForm';
import { import {
@ -110,6 +111,8 @@ export default {
validateOjCategory, validateOjCategory,
validateOpenOrNot, validateOpenOrNot,
handleClickCancelPublish, handleClickCancelPublish,
getQuestion,
//
addTestCase, addTestCase,
deleteTestCase, deleteTestCase,
testCaseInputChange, testCaseInputChange,

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-20 16:35:46 * @Date: 2019-11-20 16:35:46
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2019-12-27 22:19:15 * @LastEditTime : 2019-12-30 09:56:39
*/ */
import types from './actionTypes'; import types from './actionTypes';
import CONST from '../../constants'; import CONST from '../../constants';
@ -12,7 +12,8 @@ import {
fetchPostOjForm, fetchPostOjForm,
fetchGetOjById, fetchGetOjById,
publishTask, publishTask,
cancelPublicTask cancelPublicTask,
fetchQuestion
} from '../../services/ojService'; } from '../../services/ojService';
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
import { notification } from 'antd'; import { notification } from 'antd';
@ -644,3 +645,21 @@ export const updateOpenTestCaseIndex = (value) => {
payload: 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: * @Github:
* @Date: 2019-11-20 16:40:32 * @Date: 2019-11-20 16:40:32
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2019-12-27 20:00:26 * @LastEditTime : 2019-12-30 09:55:37
*/ */
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
import types from '../actions/actionTypes'; import types from '../actions/actionTypes';
@ -67,6 +67,7 @@ const init = {
testCodeStatus: 'default', // 调试代码状态 default(默认值) | loading(加载中) | loaded(加载完成) | userCase(用户自定义测试用例) | finish(测试完成) testCodeStatus: 'default', // 调试代码状态 default(默认值) | loading(加载中) | loaded(加载完成) | userCase(用户自定义测试用例) | finish(测试完成)
openTestCodeIndex: [0], // 展开的测试用例: 数组, 当出错时,展开所有出错的测试用例, 默认展开第一个 openTestCodeIndex: [0], // 展开的测试用例: 数组, 当出错时,展开所有出错的测试用例, 默认展开第一个
isPublish: 0, // 是否是发布状态: 0 未发布 1 已发布 isPublish: 0, // 是否是发布状态: 0 未发布 1 已发布
courseQuestions: [], // 课程题库
} }
const tcValidateObj = { const tcValidateObj = {
@ -306,6 +307,11 @@ const ojFormReducer = (state = initialState, action) => {
...state, ...state,
openTestCodeIndex: tempArr openTestCodeIndex: tempArr
} }
case types.GET_COURSE_QUESTION:
return {
...state,
courseQuestions: action.payload
}
default: default:
return state; return state;
} }

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-20 10:55:38 * @Date: 2019-11-20 10:55:38
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2019-12-27 11:06:27 * @LastEditTime : 2019-12-30 09:44:56
*/ */
import axios from 'axios'; import axios from 'axios';
@ -142,4 +142,10 @@ export async function fetchUploadImageUrl (id) {
export async function fetchAddNotes (identifier, params) { export async function fetchAddNotes (identifier, params) {
const url = `/myproblems/${identifier}/add_notes.json`; const url = `/myproblems/${identifier}/add_notes.json`;
return axios.post(url, params); return axios.post(url, params);
}
// 获取课程体系
export async function fetchQuestion (params) {
const url = `/disciplines.json`;
return axios.get(url, { params });
} }
Loading…
Cancel
Save