From 71156118b918e1346052889e024eecc5f86aa680 Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Thu, 2 Jan 2020 18:33:10 +0800 Subject: [PATCH] add course --- public/react/src/constants/index.js | 5 +- .../developer/components/knowledge/index.js | 3 +- .../modules/developer/newOrEditTask/index.js | 8 +- .../newOrEditTask/leftpane/editorTab/index.js | 115 ++++++++++-------- public/react/src/redux/actions/actionTypes.js | 3 + public/react/src/redux/actions/index.js | 8 +- public/react/src/redux/actions/ojForm.js | 72 +++++++---- .../react/src/redux/reducers/ojFormReducer.js | 56 +++++++-- 8 files changed, 180 insertions(+), 90 deletions(-) diff --git a/public/react/src/constants/index.js b/public/react/src/constants/index.js index 623cff362..e9401e76e 100644 --- a/public/react/src/constants/index.js +++ b/public/react/src/constants/index.js @@ -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: '代码格式', diff --git a/public/react/src/modules/developer/components/knowledge/index.js b/public/react/src/modules/developer/components/knowledge/index.js index ded8b3b1f..6bbc1efd0 100644 --- a/public/react/src/modules/developer/components/knowledge/index.js +++ b/public/react/src/modules/developer/components/knowledge/index.js @@ -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 ( @@ -384,6 +383,7 @@ class EditTab extends React.Component { > @@ -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( diff --git a/public/react/src/redux/actions/actionTypes.js b/public/react/src/redux/actions/actionTypes.js index e3ae7044b..867563ea7 100644 --- a/public/react/src/redux/actions/actionTypes.js +++ b/public/react/src/redux/actions/actionTypes.js @@ -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', // 用户编程题详情 diff --git a/public/react/src/redux/actions/index.js b/public/react/src/redux/actions/index.js index 263e367df..99ab53f2f 100644 --- a/public/react/src/redux/actions/index.js +++ b/public/react/src/redux/actions/index.js @@ -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, diff --git a/public/react/src/redux/actions/ojForm.js b/public/react/src/redux/actions/ojForm.js index f639cdbcb..539798ff4 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-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 + } +} diff --git a/public/react/src/redux/reducers/ojFormReducer.js b/public/react/src/redux/reducers/ojFormReducer.js index 5beba6653..d604a6156 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-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; }