dev_new_shixunsrepository
tangjiang 5 years ago
parent f5b2da094b
commit 71156118b9

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 23:10:48
* @LastEditors : tangjiang
* @LastEditTime : 2019-12-30 14:44:45
* @LastEditTime : 2020-01-02 14:57:02
*/
const CONST = {
jcLabel: {
@ -15,7 +15,8 @@ const CONST = {
category: '课程',
openOrNot: '公开程序',
timeLimit: '时间限制',
knowledge: '知识点'
knowledge: '知识点',
sub_discipline_id: '课程'
},
fontSetting: {
title: '代码格式',

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-12-30 13:51:19
* @LastEditors : tangjiang
* @LastEditTime : 2019-12-31 10:42:51
* @LastEditTime : 2020-01-02 17:00:10
*/
import './index.scss';
import React, { useState, useEffect } from 'react';
@ -88,6 +88,7 @@ function KnowLedge (props) {
}
// 渲染下拉列表
const renderSelect = (options) => {
// console.log('+++++', options);
return (
<Select
value={value}

@ -35,6 +35,7 @@ const NewOrEditTask = (props) => {
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(

@ -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 (
<Cascader
options={tempArr}
expandTrigger="hover"
onChange={this.handleChangeCategory}
value={choid_ids}
// onChange={this.handleChangeCategory}
onChange={this.handleChangeSubDisciplineId}
/>
)
}
@ -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 {
<FormItem
className={`input_area flex_50 flex_50_right`}
label={<span>{myLabel(jcLabel['category'], '合理的课程分类有利于快速检索')}</span>}
validateStatus={ojFormValidate.category.validateStatus}
help={ojFormValidate.category.errMsg}
label={<span>{myLabel(jcLabel['sub_discipline_id'], '合理的课程分类有利于快速检索')}</span>}
validateStatus={ojFormValidate.sub_discipline_id.validateStatus}
help={ojFormValidate.sub_discipline_id.errMsg}
colon={ false }
>
{/* <Select onChange={this.handleChangeCategory} value={`${ojForm.category}`}>
@ -384,6 +383,7 @@ class EditTab extends React.Component {
>
<KnowLedge
options={knowledges}
values={tag_discipline_id}
onChange={handleKnowledgeChange}
/>
</FormItem>
@ -480,7 +480,9 @@ const mapStateToProps = (state) => {
openTestCodeIndex,
testCasesValidate,
ojFormValidate,
courseQuestions
courseQuestions,
tag_discipline_id,
knowledges
} = ojFormReducer;
return {
ojForm,
@ -489,7 +491,9 @@ const mapStateToProps = (state) => {
ojFormValidate,
position,
openTestCodeIndex,
courseQuestions
courseQuestions,
tag_discipline_id,
knowledges
};
};
@ -502,12 +506,15 @@ const mapDispatchToProps = (dispatch) => ({
validateOjTimeLimit: (value) => dispatch(actions.validateOjTimeLimit(value)),
validateOjCategory: (value) => dispatch(actions.validateOjCategory(value)),
validateOpenOrNot: (value) => dispatch(actions.validateOpenOrNot(value)),
validateOjSubDisciplineId: (value) => dispatch(actions.validateOjSubDisciplineId(value)),
saveTagDisciplineId: (value) => dispatch(actions.saveTagDisciplineId(value)),
// 新增测试用例
addTestCase: (value) => dispatch(actions.addTestCase(value)),
// 删除测试用例
deleteTestCase: (value) => dispatch(actions.deleteTestCase(value)),
saveKnowledge: (value) => dispatch(actions.saveKnowledge(value))
// 获取题库
getQuestion: (params) => dispatch(actions.getQuestion(params))
// getQuestion: (params) => dispatch(actions.getQuestion(params))
});
export default connect(

@ -18,7 +18,9 @@ const types = {
VALIDATE_OJ_DIFFICULT: 'VALIDATE_OJ_DIFFICULT', // 难易度
VALIDATE_OJ_TIMELIMIT: 'VALIDATE_OJ_TIMELIMIT', // 时间限制
VALIDATE_OJ_CATEGORY: 'VALIDATE_OJ_CATEGORY', // 分类
VALIDATE_OJ_SUB_DISCIPLINE_ID: 'VALIDATE_OJ_SUB_DISCIPLINE_ID', // 方向
VALIDATE_OJ_OPENORNOT: 'VALIDATE_OJ_OPENORNOT', // 公开程序
SAVE_TAG_DISCIPLINE_ID: 'SAVE_TAG_DISCIPLINE_ID', // 保存知识点
SAVE_OJ_FORM: 'SAVE_OJ_FORM', // 保存表单
ADD_TEST_CASE: 'ADD_TEST_CASE', // 添加测试用例
DELETE_TEST_CASE: 'DELETE_TEST_CASE', // 删除测试用例
@ -33,6 +35,7 @@ const types = {
TEST_CASE_OUTPUT_CHANGE: 'TEST_CASE_OUTPUT_CHANGE', // 测试用例输出值改变时
DEBUGGER_CODE: 'DEBUGGER_CODE', // 调试代码
GET_COURSE_QUESTION: 'GET_COURSE_QUESTION', // 获取编辑题
CHANGE_KNOWLEDGES: 'CHANGE_KNOWLEDGES', // 保存所选择的知识点
// study
SAVE_USER_PROGRAM_ID: 'SAVE_USER_PROGRAM_ID',// 保存用户编程题id值
USER_PROGRAM_DETAIL: 'USER_PROGRAM_DETAIL', // 用户编程题详情

@ -25,6 +25,8 @@ import {
validateOjTimeLimit,
validateOjCategory,
validateOpenOrNot,
validateOjSubDisciplineId,
saveTagDisciplineId,
addTestCase,
deleteTestCase,
testCaseInputChange,
@ -32,7 +34,8 @@ import {
updateTestAndValidate,
updateOpenTestCaseIndex,
handleClickCancelPublish,
getQuestion
getQuestion,
saveKnowledge
} from './ojForm';
import {
@ -110,8 +113,11 @@ export default {
validateOjTimeLimit,
validateOjCategory,
validateOpenOrNot,
validateOjSubDisciplineId,
saveTagDisciplineId,
handleClickCancelPublish,
getQuestion,
saveKnowledge,
//
addTestCase,
deleteTestCase,

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 16:35:46
* @LastEditors : tangjiang
* @LastEditTime : 2019-12-31 10:55:48
* @LastEditTime : 2020-01-02 17:38:12
*/
import types from './actionTypes';
import CONST from '../../constants';
@ -46,6 +46,10 @@ const maps = {
label: jcLabel['category'],
type: types.VALIDATE_OJ_CATEGORY
},
sub_discipline_id: {
label: jcLabel['sub_discipline_id'],
type: types.VALIDATE_OJ_SUB_DISCIPLINE_ID
},
openOrNot: {
label: jcLabel['openOrNot'],
type: types.VALIDATE_OJ_OPENORNOT
@ -111,17 +115,19 @@ export const validateOjForm = (props, type, cb) => {
// 循环判断每个字段是否为空
let hasSuccess = true;
keys.forEach(key => {
const value = ojForm[key];
const validateResult = emptyValidate(key, value);
const errMsg = validateResult[key].errMsg;
if (errMsg) {
hasSuccess = false;
dispatch(
{
type: maps[key].type,
payload: payloadInfo(key, value, errMsg, validateResult[key])
}
)
if (!['category'].includes(key)) {
const value = ojForm[key];
const validateResult = emptyValidate(key, value);
const errMsg = validateResult[key].errMsg;
if (errMsg) {
hasSuccess = false;
dispatch(
{
type: maps[key].type,
payload: payloadInfo(key, value, errMsg, validateResult[key])
}
)
}
}
});
// 验证测试用例中的数组是否都有对应的值
@ -199,8 +205,8 @@ export const validateOjForm = (props, type, cb) => {
if (hasSuccess) {
// console.log('表单保存的数据为: ', getState());
const {ojFormReducer} = getState();
const {code, score, ojForm, testCases = []} = ojFormReducer;
const {category, description, difficult, language, name, openOrNot, timeLimit} = ojForm;
const {code, score, ojForm, testCases = [], tag_discipline_id = []} = ojFormReducer;
const {category, description, difficult, language, name, openOrNot, timeLimit, sub_discipline_id} = ojForm;
let paramsObj = {};
const hack = { // 编程题干
name,
@ -209,6 +215,8 @@ export const validateOjForm = (props, type, cb) => {
category,
'open_or_not': openOrNot,
'time_limit': timeLimit,
sub_discipline_id,
// tag_discipline_id,
score
};
@ -225,7 +233,8 @@ export const validateOjForm = (props, type, cb) => {
paramsObj['params'] = {
hack,
hack_sets: tempTc,
hack_codes
hack_codes,
tags: tag_discipline_id
}
paramsObj['submitType'] = 'add';
} else { // 存在时调用更新接口
@ -244,7 +253,8 @@ export const validateOjForm = (props, type, cb) => {
hack,
hack_sets,
hack_codes,
update_hack_sets
update_hack_sets,
tags: tag_discipline_id
}
paramsObj['submitType'] = 'update';
paramsObj['identifier'] = identifier;
@ -485,6 +495,15 @@ export const validateOjCategory = (value) => {
payload: payloadInfo('category', value, errMsg, validate)
}
};
// 验证方向
export const validateOjSubDisciplineId = (value) => {
const validate = emptyValidate('sub_discipline_id', value)['sub_discipline_id'];
const errMsg = validate.errMsg;
return {
type: types.VALIDATE_OJ_SUB_DISCIPLINE_ID,
payload: payloadInfo('sub_discipline_id', value, errMsg, validate)
}
};
// 验证公开程序
export const validateOpenOrNot = (value) => {
const validate = emptyValidate('openOrNot', value)['openOrNot'];
@ -494,6 +513,14 @@ export const validateOpenOrNot = (value) => {
payload: payloadInfo('openOrNot', value, errMsg, validate)
}
};
// 保存知识点
export const saveTagDisciplineId = (value) => {
// console.log('====????????????', value);
return {
type: types.SAVE_TAG_DISCIPLINE_ID,
payload: value
};
}
// 新增测试用例
export const addTestCase = (obj) => {
return {
@ -624,7 +651,6 @@ export const testCaseOutputChange = (value, index) => {
// // 调试代码时,更改对应的状态值
// export const changeTestCodeStatus = () => {
// 更新测试用命及验证
export const updateTestAndValidate = (obj) => {
return (dispatch) => {
@ -649,14 +675,10 @@ export const updateOpenTestCaseIndex = (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
@ -664,3 +686,11 @@ export const getQuestion = (params) => {
})
}
}
// 保存所选择的知识点
export const saveKnowledge = (values) => {
return {
type: types.CHANGE_KNOWLEDGES,
payload: values
}
}

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 16:40:32
* @LastEditors : tangjiang
* @LastEditTime : 2019-12-30 09:55:37
* @LastEditTime : 2020-01-02 17:36:40
*/
import { Base64 } from 'js-base64';
import types from '../actions/actionTypes';
@ -15,10 +15,12 @@ const init = {
language: '',
description: '',
difficult: '',
category: '',
sub_discipline_id: '', // 方向
// category: '',
// openOrNot: 1,
timeLimit: 3
},
tag_discipline_id: [], // 知识点
ojFormValidate: {
name: {
validateStatus: '',
@ -36,14 +38,18 @@ const init = {
validateStatus: '',
errMsg: ''
},
category: {
validateStatus: '',
errMsg: ''
},
// category: {
// validateStatus: '',
// errMsg: ''
// },
// openOrNot: {
// validateStatus: '',
// errMsg: ''
// },
sub_discipline_id: {
validateStatus: '',
errMsg: ''
},
timeLimit: {
validateStatus: '',
errMsg: ''
@ -68,6 +74,7 @@ const init = {
openTestCodeIndex: [0], // 展开的测试用例: 数组, 当出错时,展开所有出错的测试用例, 默认展开第一个
isPublish: 0, // 是否是发布状态: 0 未发布 1 已发布
courseQuestions: [], // 课程题库
knowledges: [], // 知识点下拉值
}
const tcValidateObj = {
@ -128,10 +135,17 @@ const ojFormReducer = (state = initialState, action) => {
return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_CATEGORY:
return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_SUB_DISCIPLINE_ID:
return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_OPENORNOT:
return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_TIMELIMIT:
return returnState(state, ojForm, ojFormValidate);
case types.SAVE_TAG_DISCIPLINE_ID:
return {
...state,
tag_discipline_id: action.payload
}
case types.ADD_TEST_CASE:
const { testCase, tcValidate } = action.payload;
const tcArrs = state.testCases.concat([testCase]);
@ -175,7 +189,8 @@ const ojFormReducer = (state = initialState, action) => {
* 6. 更改测试用例状态
* 7. 添加测试用例验证
*/
const { code = '', description, language, name, hack_sets = [], time_limit, difficult, category, status } = action.payload;
const { code = '', description, language, name, hack_sets = [], time_limit, difficult, category, status, sub_discipline_id, tag_discipline_id } = action.payload;
const { courseQuestions } = state;
let desc = null;
try {
desc = JSON.parse(description)
@ -189,7 +204,8 @@ const ojFormReducer = (state = initialState, action) => {
difficult,
category,
openOrNot: 1,
timeLimit: time_limit
timeLimit: time_limit,
sub_discipline_id
};
// state.code = code; // 保存代码块值
let curPosition = 0;
@ -209,6 +225,18 @@ const ojFormReducer = (state = initialState, action) => {
} else if (Array.isArray(code)) {
cbcode = Base64.decode(code[code.length - 1]);
}
// console.log('++++>>>>>>>>>>>>>', courseQuestions);
let temp_knowledges = [];
courseQuestions.forEach(c => {
if (sub_discipline_id && c.sub_disciplines) {
c.sub_disciplines.forEach(sub => {
if (+sub.id === sub_discipline_id) {
temp_knowledges = sub.tag_disciplines || [];
}
});
}
});
// state.position = curPosition; // 计算下一个测试用例的位置值
return {
...state,
@ -219,7 +247,9 @@ const ojFormReducer = (state = initialState, action) => {
testCasesValidate: curTcValidates,
testCodeStatus: hack_sets.length > 0 ? 'userCase' : 'default',
isPublish: status,
showCode: cbcode
showCode: cbcode,
tag_discipline_id,
knowledges: temp_knowledges
}
case types.CHANGE_PUBLISH_VALUE:
return {
@ -302,7 +332,7 @@ const ojFormReducer = (state = initialState, action) => {
if (tIndex === -1) {
tempArr.push(action.payload);
}
console.log(tempArr);
// console.log(tempArr);
return {
...state,
openTestCodeIndex: tempArr
@ -312,6 +342,12 @@ const ojFormReducer = (state = initialState, action) => {
...state,
courseQuestions: action.payload
}
case types.CHANGE_KNOWLEDGES: {
return {
...state,
knowledges: action.payload
}
}
default:
return state;
}

Loading…
Cancel
Save