dev_new_shixunsrepository
tangjiang 5 years ago
parent f5b2da094b
commit 71156118b9

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

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

@ -35,6 +35,7 @@ const NewOrEditTask = (props) => {
getUserInfoForNew, getUserInfoForNew,
handleCancelPublish, handleCancelPublish,
validateOjForm, validateOjForm,
getQuestion
// updateTestAndValidate, // updateTestAndValidate,
} = props; } = props;
@ -53,6 +54,10 @@ const NewOrEditTask = (props) => {
useEffect(() => { useEffect(() => {
// 获取用户信息 // 获取用户信息
getUserInfoForNew(); getUserInfoForNew();
// 获取课程列表
getQuestion({
source: 'question'
});
// console.log('获取路由参数: ====', props.match.params); // console.log('获取路由参数: ====', props.match.params);
const id = props.match.params.id; const id = props.match.params.id;
// 保存OJForm的id号指明是编辑还是新增 // 保存OJForm的id号指明是编辑还是新增
@ -273,7 +278,8 @@ const mapDispatchToProps = (dispatch) => ({
startProgramQuestion: (id, props) => dispatch(actions.startProgramQuestion(id, props)), startProgramQuestion: (id, props) => dispatch(actions.startProgramQuestion(id, props)),
// 新建时获取信息 // 新建时获取信息
getUserInfoForNew: () => dispatch(actions.getUserInfoForNew()), 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( export default withRouter(connect(

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-20 10:35:40 * @Date: 2019-11-20 10:35:40
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2019-12-31 15:17:08 * @LastEditTime : 2020-01-02 17:42:04
*/ */
import './index.scss'; import './index.scss';
// import 'katex/dist/katex.css'; // import 'katex/dist/katex.css';
@ -61,7 +61,8 @@ class EditTab extends React.Component {
top: 500, top: 500,
bottom: 20, bottom: 20,
offsetTop: 0, offsetTop: 0,
knowledges: [] // knowledges: [],
// coursers: [] // 选中的课程
} }
} }
@ -80,12 +81,16 @@ class EditTab extends React.Component {
this.state.scrollEl.addEventListener('scroll', this.handleScroll, false); this.state.scrollEl.addEventListener('scroll', this.handleScroll, false);
}); });
// 获取题库 // 获取题库
this.props.getQuestion({ // this.props.getQuestion({
source: 'question' // source: 'question'
}); // });
} }
componentWillUnmount () { // componentDidUpdate (nextProp) {
// console.log(nextProp);
// }
componentWillUnmount (nextPro) {
this.state.scrollEl.removeEventListener('scroll', this.handleScroll, false); this.state.scrollEl.removeEventListener('scroll', this.handleScroll, false);
} }
@ -131,30 +136,25 @@ class EditTab extends React.Component {
handleTimeLimitChange = (value) => { handleTimeLimitChange = (value) => {
this.props.validateOjTimeLimit(value); this.props.validateOjTimeLimit(value);
} }
// 改变分类 // 改变方向
handleChangeCategory = (value) => { handleChangeSubDisciplineId = (value) => {
// 课程下拉值变化时, 同步更新知识点 // 课程下拉值变化时, 同步更新知识点
const { courseQuestions } = this.props; const { courseQuestions, saveKnowledge } = this.props;
this.setState({ saveKnowledge([]);
knowledges: []
});
// 获取当前分类下的知识点 // 获取当前分类下的知识点
courseQuestions.forEach(item => { courseQuestions.forEach(item => {
if (value[0] && item.id === value[0]) { if (value[0] && item.id === value[0]) {
item.sub_disciplines && item.sub_disciplines.forEach(c => { item.sub_disciplines && item.sub_disciplines.forEach(c => {
if (value[1] && c.id === value[1]) { if (value[1] && c.id === value[1]) {
this.setState({ saveKnowledge(...c.tag_disciplines)
knowledges: [...c.tag_disciplines]
});
} else if (!value[1]) { } else if (!value[1]) {
this.setState({ saveKnowledge([]);
knowledges: []
});
} }
}); });
} }
}); });
this.props.validateOjCategory(value[1] || ''); // this.props.validateOjCategory(value[1] || '');
this.props.validateOjSubDisciplineId(value[1] || '');
} }
// 改变公开程序 // 改变公开程序
handleChangeOpenOrNot = (value) => { handleChangeOpenOrNot = (value) => {
@ -174,9 +174,12 @@ class EditTab extends React.Component {
deleteTestCase, // 删除测试用例 deleteTestCase, // 删除测试用例
testCasesValidate, testCasesValidate,
openTestCodeIndex = [], openTestCodeIndex = [],
courseQuestions courseQuestions,
tag_discipline_id,
knowledges
} = this.props; } = this.props;
const {knowledges} = this.state; console.log('+++++++++', knowledges);
// const {knowledges} = this.state;
// 表单label // 表单label
const myLabel = (name, subTitle, nostar) => { const myLabel = (name, subTitle, nostar) => {
if (subTitle) { if (subTitle) {
@ -285,6 +288,7 @@ class EditTab extends React.Component {
const renderCourseQuestion = (arrs) => { const renderCourseQuestion = (arrs) => {
const tempArr = []; const tempArr = [];
const sub_id = this.props.ojForm.sub_discipline_id;
function loop (arrs, tempArr) { function loop (arrs, tempArr) {
arrs.forEach(item => { arrs.forEach(item => {
const obj = {}; const obj = {};
@ -300,37 +304,30 @@ class EditTab extends React.Component {
}); });
} }
loop(arrs, tempArr); 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 = []; let choid_ids = [];
// sub.tag_disciplines.forEach(tag => { // let tempKnowledges = [];
// const tabObj = Object.create(null); tempArr.forEach(t => {
// tabObj.value = tag.id; // debugger;
// tabObj.label = tag.name; if (sub_id && t.children) {
// subObj.children.push(tabObj); t.children.forEach(c => {
// }); if (c.value === sub_id) {
// } choid_ids = [t.value, c.value];
// obj.children.push(subObj); // tempKnowledges = c.children || [];
// }) }
// } });
// tempArr.push(obj); }
// }); });
console.log(tempArr);
console.log(choid_ids);
return ( return (
<Cascader <Cascader
options={tempArr} options={tempArr}
expandTrigger="hover" 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); _result.push(v.id);
}); });
console.log('下拉选择的值:===>>>', _result); console.log('下拉选择的值:===>>>', _result);
// 保存选择的知识点
this.props.saveTagDisciplineId(_result);
} }
return ( return (
@ -361,9 +360,9 @@ 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['sub_discipline_id'], '合理的课程分类有利于快速检索')}</span>}
validateStatus={ojFormValidate.category.validateStatus} validateStatus={ojFormValidate.sub_discipline_id.validateStatus}
help={ojFormValidate.category.errMsg} help={ojFormValidate.sub_discipline_id.errMsg}
colon={ false } colon={ false }
> >
{/* <Select onChange={this.handleChangeCategory} value={`${ojForm.category}`}> {/* <Select onChange={this.handleChangeCategory} value={`${ojForm.category}`}>
@ -384,6 +383,7 @@ class EditTab extends React.Component {
> >
<KnowLedge <KnowLedge
options={knowledges} options={knowledges}
values={tag_discipline_id}
onChange={handleKnowledgeChange} onChange={handleKnowledgeChange}
/> />
</FormItem> </FormItem>
@ -480,7 +480,9 @@ const mapStateToProps = (state) => {
openTestCodeIndex, openTestCodeIndex,
testCasesValidate, testCasesValidate,
ojFormValidate, ojFormValidate,
courseQuestions courseQuestions,
tag_discipline_id,
knowledges
} = ojFormReducer; } = ojFormReducer;
return { return {
ojForm, ojForm,
@ -489,7 +491,9 @@ const mapStateToProps = (state) => {
ojFormValidate, ojFormValidate,
position, position,
openTestCodeIndex, openTestCodeIndex,
courseQuestions courseQuestions,
tag_discipline_id,
knowledges
}; };
}; };
@ -502,12 +506,15 @@ const mapDispatchToProps = (dispatch) => ({
validateOjTimeLimit: (value) => dispatch(actions.validateOjTimeLimit(value)), validateOjTimeLimit: (value) => dispatch(actions.validateOjTimeLimit(value)),
validateOjCategory: (value) => dispatch(actions.validateOjCategory(value)), validateOjCategory: (value) => dispatch(actions.validateOjCategory(value)),
validateOpenOrNot: (value) => dispatch(actions.validateOpenOrNot(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)), addTestCase: (value) => dispatch(actions.addTestCase(value)),
// 删除测试用例 // 删除测试用例
deleteTestCase: (value) => dispatch(actions.deleteTestCase(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( export default connect(

@ -18,7 +18,9 @@ const types = {
VALIDATE_OJ_DIFFICULT: 'VALIDATE_OJ_DIFFICULT', // 难易度 VALIDATE_OJ_DIFFICULT: 'VALIDATE_OJ_DIFFICULT', // 难易度
VALIDATE_OJ_TIMELIMIT: 'VALIDATE_OJ_TIMELIMIT', // 时间限制 VALIDATE_OJ_TIMELIMIT: 'VALIDATE_OJ_TIMELIMIT', // 时间限制
VALIDATE_OJ_CATEGORY: 'VALIDATE_OJ_CATEGORY', // 分类 VALIDATE_OJ_CATEGORY: 'VALIDATE_OJ_CATEGORY', // 分类
VALIDATE_OJ_SUB_DISCIPLINE_ID: 'VALIDATE_OJ_SUB_DISCIPLINE_ID', // 方向
VALIDATE_OJ_OPENORNOT: 'VALIDATE_OJ_OPENORNOT', // 公开程序 VALIDATE_OJ_OPENORNOT: 'VALIDATE_OJ_OPENORNOT', // 公开程序
SAVE_TAG_DISCIPLINE_ID: 'SAVE_TAG_DISCIPLINE_ID', // 保存知识点
SAVE_OJ_FORM: 'SAVE_OJ_FORM', // 保存表单 SAVE_OJ_FORM: 'SAVE_OJ_FORM', // 保存表单
ADD_TEST_CASE: 'ADD_TEST_CASE', // 添加测试用例 ADD_TEST_CASE: 'ADD_TEST_CASE', // 添加测试用例
DELETE_TEST_CASE: 'DELETE_TEST_CASE', // 删除测试用例 DELETE_TEST_CASE: 'DELETE_TEST_CASE', // 删除测试用例
@ -33,6 +35,7 @@ const types = {
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', // 获取编辑题 GET_COURSE_QUESTION: 'GET_COURSE_QUESTION', // 获取编辑题
CHANGE_KNOWLEDGES: 'CHANGE_KNOWLEDGES', // 保存所选择的知识点
// study // 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', // 用户编程题详情

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

@ -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-31 10:55:48 * @LastEditTime : 2020-01-02 17:38:12
*/ */
import types from './actionTypes'; import types from './actionTypes';
import CONST from '../../constants'; import CONST from '../../constants';
@ -46,6 +46,10 @@ const maps = {
label: jcLabel['category'], label: jcLabel['category'],
type: types.VALIDATE_OJ_CATEGORY type: types.VALIDATE_OJ_CATEGORY
}, },
sub_discipline_id: {
label: jcLabel['sub_discipline_id'],
type: types.VALIDATE_OJ_SUB_DISCIPLINE_ID
},
openOrNot: { openOrNot: {
label: jcLabel['openOrNot'], label: jcLabel['openOrNot'],
type: types.VALIDATE_OJ_OPENORNOT type: types.VALIDATE_OJ_OPENORNOT
@ -111,6 +115,7 @@ export const validateOjForm = (props, type, cb) => {
// 循环判断每个字段是否为空 // 循环判断每个字段是否为空
let hasSuccess = true; let hasSuccess = true;
keys.forEach(key => { keys.forEach(key => {
if (!['category'].includes(key)) {
const value = ojForm[key]; const value = ojForm[key];
const validateResult = emptyValidate(key, value); const validateResult = emptyValidate(key, value);
const errMsg = validateResult[key].errMsg; const errMsg = validateResult[key].errMsg;
@ -123,6 +128,7 @@ export const validateOjForm = (props, type, cb) => {
} }
) )
} }
}
}); });
// 验证测试用例中的数组是否都有对应的值 // 验证测试用例中的数组是否都有对应的值
const tcValidResult = []; const tcValidResult = [];
@ -199,8 +205,8 @@ export const validateOjForm = (props, type, cb) => {
if (hasSuccess) { if (hasSuccess) {
// console.log('表单保存的数据为: ', getState()); // console.log('表单保存的数据为: ', getState());
const {ojFormReducer} = getState(); const {ojFormReducer} = getState();
const {code, score, ojForm, testCases = []} = ojFormReducer; const {code, score, ojForm, testCases = [], tag_discipline_id = []} = ojFormReducer;
const {category, description, difficult, language, name, openOrNot, timeLimit} = ojForm; const {category, description, difficult, language, name, openOrNot, timeLimit, sub_discipline_id} = ojForm;
let paramsObj = {}; let paramsObj = {};
const hack = { // 编程题干 const hack = { // 编程题干
name, name,
@ -209,6 +215,8 @@ export const validateOjForm = (props, type, cb) => {
category, category,
'open_or_not': openOrNot, 'open_or_not': openOrNot,
'time_limit': timeLimit, 'time_limit': timeLimit,
sub_discipline_id,
// tag_discipline_id,
score score
}; };
@ -225,7 +233,8 @@ export const validateOjForm = (props, type, cb) => {
paramsObj['params'] = { paramsObj['params'] = {
hack, hack,
hack_sets: tempTc, hack_sets: tempTc,
hack_codes hack_codes,
tags: tag_discipline_id
} }
paramsObj['submitType'] = 'add'; paramsObj['submitType'] = 'add';
} else { // 存在时调用更新接口 } else { // 存在时调用更新接口
@ -244,7 +253,8 @@ export const validateOjForm = (props, type, cb) => {
hack, hack,
hack_sets, hack_sets,
hack_codes, hack_codes,
update_hack_sets update_hack_sets,
tags: tag_discipline_id
} }
paramsObj['submitType'] = 'update'; paramsObj['submitType'] = 'update';
paramsObj['identifier'] = identifier; paramsObj['identifier'] = identifier;
@ -485,6 +495,15 @@ export const validateOjCategory = (value) => {
payload: payloadInfo('category', value, errMsg, validate) 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) => { export const validateOpenOrNot = (value) => {
const validate = emptyValidate('openOrNot', value)['openOrNot']; const validate = emptyValidate('openOrNot', value)['openOrNot'];
@ -494,6 +513,14 @@ export const validateOpenOrNot = (value) => {
payload: payloadInfo('openOrNot', value, errMsg, validate) 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) => { export const addTestCase = (obj) => {
return { return {
@ -624,7 +651,6 @@ export const testCaseOutputChange = (value, index) => {
// // 调试代码时,更改对应的状态值 // // 调试代码时,更改对应的状态值
// export const changeTestCodeStatus = () => { // export const changeTestCodeStatus = () => {
// 更新测试用命及验证 // 更新测试用命及验证
export const updateTestAndValidate = (obj) => { export const updateTestAndValidate = (obj) => {
return (dispatch) => { return (dispatch) => {
@ -649,14 +675,10 @@ export const updateOpenTestCaseIndex = (value) => {
// 获取课程题库 // 获取课程题库
export const getQuestion = (params) => { export const getQuestion = (params) => {
// return {
// type: types.GET_COURSE_QUESTION,
// }
return (dispatch) => { return (dispatch) => {
fetchQuestion(params).then(res => { fetchQuestion(params).then(res => {
const { data = {} } = res; const { data = {} } = res;
const { disciplines = [] } = data; const { disciplines = [] } = data;
console.log('获取课程题库成功: ', res);
dispatch({ dispatch({
type: types.GET_COURSE_QUESTION, type: types.GET_COURSE_QUESTION,
payload: disciplines 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: * @Github:
* @Date: 2019-11-20 16:40:32 * @Date: 2019-11-20 16:40:32
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2019-12-30 09:55:37 * @LastEditTime : 2020-01-02 17:36:40
*/ */
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
import types from '../actions/actionTypes'; import types from '../actions/actionTypes';
@ -15,10 +15,12 @@ const init = {
language: '', language: '',
description: '', description: '',
difficult: '', difficult: '',
category: '', sub_discipline_id: '', // 方向
// category: '',
// openOrNot: 1, // openOrNot: 1,
timeLimit: 3 timeLimit: 3
}, },
tag_discipline_id: [], // 知识点
ojFormValidate: { ojFormValidate: {
name: { name: {
validateStatus: '', validateStatus: '',
@ -36,14 +38,18 @@ const init = {
validateStatus: '', validateStatus: '',
errMsg: '' errMsg: ''
}, },
category: { // category: {
validateStatus: '', // validateStatus: '',
errMsg: '' // errMsg: ''
}, // },
// openOrNot: { // openOrNot: {
// validateStatus: '', // validateStatus: '',
// errMsg: '' // errMsg: ''
// }, // },
sub_discipline_id: {
validateStatus: '',
errMsg: ''
},
timeLimit: { timeLimit: {
validateStatus: '', validateStatus: '',
errMsg: '' errMsg: ''
@ -68,6 +74,7 @@ const init = {
openTestCodeIndex: [0], // 展开的测试用例: 数组, 当出错时,展开所有出错的测试用例, 默认展开第一个 openTestCodeIndex: [0], // 展开的测试用例: 数组, 当出错时,展开所有出错的测试用例, 默认展开第一个
isPublish: 0, // 是否是发布状态: 0 未发布 1 已发布 isPublish: 0, // 是否是发布状态: 0 未发布 1 已发布
courseQuestions: [], // 课程题库 courseQuestions: [], // 课程题库
knowledges: [], // 知识点下拉值
} }
const tcValidateObj = { const tcValidateObj = {
@ -128,10 +135,17 @@ const ojFormReducer = (state = initialState, action) => {
return returnState(state, ojForm, ojFormValidate); return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_CATEGORY: case types.VALIDATE_OJ_CATEGORY:
return returnState(state, ojForm, ojFormValidate); return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_SUB_DISCIPLINE_ID:
return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_OPENORNOT: case types.VALIDATE_OJ_OPENORNOT:
return returnState(state, ojForm, ojFormValidate); return returnState(state, ojForm, ojFormValidate);
case types.VALIDATE_OJ_TIMELIMIT: case types.VALIDATE_OJ_TIMELIMIT:
return returnState(state, ojForm, ojFormValidate); return returnState(state, ojForm, ojFormValidate);
case types.SAVE_TAG_DISCIPLINE_ID:
return {
...state,
tag_discipline_id: action.payload
}
case types.ADD_TEST_CASE: case types.ADD_TEST_CASE:
const { testCase, tcValidate } = action.payload; const { testCase, tcValidate } = action.payload;
const tcArrs = state.testCases.concat([testCase]); const tcArrs = state.testCases.concat([testCase]);
@ -175,7 +189,8 @@ const ojFormReducer = (state = initialState, action) => {
* 6. 更改测试用例状态 * 6. 更改测试用例状态
* 7. 添加测试用例验证 * 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; let desc = null;
try { try {
desc = JSON.parse(description) desc = JSON.parse(description)
@ -189,7 +204,8 @@ const ojFormReducer = (state = initialState, action) => {
difficult, difficult,
category, category,
openOrNot: 1, openOrNot: 1,
timeLimit: time_limit timeLimit: time_limit,
sub_discipline_id
}; };
// state.code = code; // 保存代码块值 // state.code = code; // 保存代码块值
let curPosition = 0; let curPosition = 0;
@ -209,6 +225,18 @@ const ojFormReducer = (state = initialState, action) => {
} else if (Array.isArray(code)) { } else if (Array.isArray(code)) {
cbcode = Base64.decode(code[code.length - 1]); 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; // 计算下一个测试用例的位置值 // state.position = curPosition; // 计算下一个测试用例的位置值
return { return {
...state, ...state,
@ -219,7 +247,9 @@ const ojFormReducer = (state = initialState, action) => {
testCasesValidate: curTcValidates, testCasesValidate: curTcValidates,
testCodeStatus: hack_sets.length > 0 ? 'userCase' : 'default', testCodeStatus: hack_sets.length > 0 ? 'userCase' : 'default',
isPublish: status, isPublish: status,
showCode: cbcode showCode: cbcode,
tag_discipline_id,
knowledges: temp_knowledges
} }
case types.CHANGE_PUBLISH_VALUE: case types.CHANGE_PUBLISH_VALUE:
return { return {
@ -302,7 +332,7 @@ const ojFormReducer = (state = initialState, action) => {
if (tIndex === -1) { if (tIndex === -1) {
tempArr.push(action.payload); tempArr.push(action.payload);
} }
console.log(tempArr); // console.log(tempArr);
return { return {
...state, ...state,
openTestCodeIndex: tempArr openTestCodeIndex: tempArr
@ -312,6 +342,12 @@ const ojFormReducer = (state = initialState, action) => {
...state, ...state,
courseQuestions: action.payload courseQuestions: action.payload
} }
case types.CHANGE_KNOWLEDGES: {
return {
...state,
knowledges: action.payload
}
}
default: default:
return state; return state;
} }

Loading…
Cancel
Save