add knowledge

dev_static
tangjiang 5 years ago
parent 6a377c17c5
commit 9540b348dd

@ -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 : 2020-01-07 14:19:39 * @LastEditTime : 2020-01-07 15:04:51
*/ */
import './index.scss'; import './index.scss';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
@ -18,7 +18,9 @@ function KnowLedge (props) {
options = [], // 下拉选项 options = [], // 下拉选项
values = [], // 已选择的下拉项 values = [], // 已选择的下拉项
onChange, // 获取选择的值 onChange, // 获取选择的值
form form,
showAdd, // 显示新增图标
addKnowledge // 调用新增知识点接口
} = props; } = props;
useEffect(() => { useEffect(() => {
@ -135,12 +137,14 @@ function KnowLedge (props) {
return; return;
} }
setVisible(false); setVisible(false);
console.log(values); form.resetFields();
// console.log(values);
addKnowledge && addKnowledge(values);
}) })
} }
const _styles = { const _styles = {
display: selectOptions.length > 0 || selectValue.length > 0 ? 'inline-block' : 'none' display: showAdd ? 'inline-block' : 'none'
}; };
return ( return (
@ -149,11 +153,11 @@ function KnowLedge (props) {
{ renderSelect(selectOptions) } { renderSelect(selectOptions) }
{/* 渲染下拉选择项 */} {/* 渲染下拉选择项 */}
<div className="knowledge-result"> <div className="knowledge-result">
{/* <i <i
style={_styles} style={_styles}
className="iconfont icon-roundaddfill icon-add-knowledge" className="iconfont icon-roundaddfill icon-add-knowledge"
onClick={handleAddKnowledge} onClick={handleAddKnowledge}
></i> */} ></i>
{ renderResult(selectValue) } { renderResult(selectValue) }
</div> </div>
</div> </div>

@ -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 : 2020-01-06 16:17:22 * @LastEditTime : 2020-01-07 15:21:19
*/ */
import './index.scss'; import './index.scss';
// import 'katex/dist/katex.css'; // import 'katex/dist/katex.css';
@ -61,6 +61,7 @@ class EditTab extends React.Component {
top: 500, top: 500,
bottom: 20, bottom: 20,
offsetTop: 0, offsetTop: 0,
showAdd: false
// knowledges: [], // knowledges: [],
// coursers: [] // 选中的课程 // coursers: [] // 选中的课程
} }
@ -147,13 +148,15 @@ class EditTab extends React.Component {
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]) {
saveKnowledge(c.tag_disciplines) saveKnowledge(c.tag_disciplines)
console.log(c.tag_disciplines);
} else if (!value[1]) { } else if (!value[1]) {
saveKnowledge([]); saveKnowledge([]);
} }
}); });
} }
}); });
this.setState({
showAdd: value[1] ? true : false
});
// this.props.validateOjCategory(value[1] || ''); // this.props.validateOjCategory(value[1] || '');
this.props.validateOjSubDisciplineId(value[1] || ''); this.props.validateOjSubDisciplineId(value[1] || '');
} }
@ -167,6 +170,7 @@ class EditTab extends React.Component {
} }
render () { render () {
const { showAdd } = this.state;
const { const {
ojForm, ojForm,
ojFormValidate, ojFormValidate,
@ -177,9 +181,10 @@ class EditTab extends React.Component {
openTestCodeIndex = [], openTestCodeIndex = [],
courseQuestions, courseQuestions,
tag_discipline_id, tag_discipline_id,
knowledges knowledges,
tagDisciplines,
} = this.props; } = this.props;
console.log('knowledge======>>>>>>', knowledges); // console.log('knowledge======>>>>>>', knowledges);
// const {knowledges} = this.state; // const {knowledges} = this.state;
// 表单label // 表单label
const myLabel = (name, subTitle, nostar) => { const myLabel = (name, subTitle, nostar) => {
@ -321,7 +326,7 @@ class EditTab extends React.Component {
} }
}); });
console.log(choid_ids); // console.log(choid_ids);
return ( return (
<Cascader <Cascader
placeholder="请选择" placeholder="请选择"
@ -340,10 +345,19 @@ class EditTab extends React.Component {
values.forEach(v => { values.forEach(v => {
_result.push(v.id); _result.push(v.id);
}); });
console.log('下拉选择的值:===>>>', _result); // console.log('下拉选择的值:===>>>', _result);
// 保存选择的知识点 // 保存选择的知识点
this.props.saveTagDisciplineId(_result); this.props.saveTagDisciplineId(_result);
} }
// 新增知识点
const handleAddKnowledge = (values) => {
// console.log('调用了新增知识点并返回了结果: ', values);
// 获取课程id
const {sub_discipline_id} = this.props.ojForm;
const obj = Object.assign({}, values, {sub_discipline_id})
tagDisciplines(obj);
}
return ( return (
<div className={'editor_area'} id="textCase"> <div className={'editor_area'} id="textCase">
@ -383,10 +397,12 @@ class EditTab extends React.Component {
className='input_area flex_100' className='input_area flex_100'
label={<span>{myLabel(jcLabel['knowledge'], '', 'nostar')}</span>} label={<span>{myLabel(jcLabel['knowledge'], '', 'nostar')}</span>}
> >
<KnowLedge <KnowLedge
showAdd={showAdd}
options={knowledges} options={knowledges}
values={tag_discipline_id} values={tag_discipline_id}
onChange={handleKnowledgeChange} onChange={handleKnowledgeChange}
addKnowledge={handleAddKnowledge}
/> />
</FormItem> </FormItem>
@ -514,7 +530,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)),
saveKnowledge: (value) => dispatch(actions.saveKnowledge(value)) saveKnowledge: (value) => dispatch(actions.saveKnowledge(value)),
tagDisciplines: (params) => dispatch(actions.tagDisciplines(params))
// 获取题库 // 获取题库
// getQuestion: (params) => dispatch(actions.getQuestion(params)) // getQuestion: (params) => dispatch(actions.getQuestion(params))
}); });

@ -36,7 +36,8 @@ import {
handleClickCancelPublish, handleClickCancelPublish,
getQuestion, getQuestion,
saveKnowledge, saveKnowledge,
setOjInitialValue setOjInitialValue,
tagDisciplines
} from './ojForm'; } from './ojForm';
import { import {
@ -125,6 +126,7 @@ export default {
getQuestion, getQuestion,
saveKnowledge, saveKnowledge,
setOjInitialValue, setOjInitialValue,
tagDisciplines,
// //
addTestCase, addTestCase,
deleteTestCase, deleteTestCase,

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-27 13:42:11 * @Date: 2019-11-27 13:42:11
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2020-01-02 14:17:49 * @LastEditTime : 2020-01-07 14:45:52
*/ */
import types from "./actionTypes"; import types from "./actionTypes";
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
@ -18,7 +18,7 @@ import {
fetchUpdateCode, fetchUpdateCode,
fetchUserCodeSubmit, fetchUserCodeSubmit,
fetchRestoreInitialCode, fetchRestoreInitialCode,
fetchAddNotes fetchAddNotes,
} from "../../services/ojService"; } from "../../services/ojService";
import { notification } from "antd"; import { notification } from "antd";
@ -523,4 +523,4 @@ export const addNotes = (identifier, params, cb) => {
}); });
}) })
} }
} }

@ -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 : 2020-01-03 16:40:54 * @LastEditTime : 2020-01-07 14:58:05
*/ */
import types from './actionTypes'; import types from './actionTypes';
import CONST from '../../constants'; import CONST from '../../constants';
@ -13,7 +13,8 @@ import {
fetchGetOjById, fetchGetOjById,
publishTask, publishTask,
cancelPublicTask, cancelPublicTask,
fetchQuestion fetchQuestion,
fetchTagDisciplines
} from '../../services/ojService'; } from '../../services/ojService';
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
import { notification } from 'antd'; import { notification } from 'antd';
@ -675,14 +676,32 @@ export const updateOpenTestCaseIndex = (value) => {
// 获取课程题库 // 获取课程题库
export const getQuestion = (params) => { export const getQuestion = (params) => {
return (dispatch) => { return (dispatch, getState) => {
const {ojForm: {sub_discipline_id}} = getState().ojFormReducer;
fetchQuestion(params).then(res => { fetchQuestion(params).then(res => {
const { data = {} } = res; const { data = {} } = res;
const { disciplines = [] } = data; const { disciplines = [] } = data;
dispatch({ dispatch({
type: types.GET_COURSE_QUESTION, type: types.GET_COURSE_QUESTION,
payload: disciplines payload: disciplines
}) });
// 如果课程id号存在 同步更新知识点
if (sub_discipline_id) {
let temp_knowledges = [];
disciplines.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 || [];
}
});
}
});
dispatch({
type: types.CHANGE_KNOWLEDGES,
payload: temp_knowledges
})
}
}) })
} }
} }
@ -710,3 +729,22 @@ export const setOjInitialValue = (params) => {
payload: params payload: params
} }
} }
// 新增知识点
export const tagDisciplines = (params) => {
return (dispatch) => {
fetchTagDisciplines(params).then(res => {
console.log('新增知识点成功======>>>>', res);
if (res.data.status === 0) {
notification.success({
message: '提示',
description: '新增知识点成功'
});
// 重新调用获取课程列表接口
dispatch(getQuestion({
source: 'question'
}));
}
});
}
}

@ -3,8 +3,8 @@
* @Author: tangjiang * @Author: tangjiang
* @Github: * @Github:
* @Date: 2019-11-27 16:27:09 * @Date: 2019-11-27 16:27:09
* @LastEditors: tangjiang * @LastEditors : tangjiang
* @LastEditTime: 2019-12-12 17:36:51 * @LastEditTime : 2020-01-07 15:23:39
*/ */
import types from "../actions/actionTypes"; import types from "../actions/actionTypes";
@ -22,7 +22,7 @@ const initialState = {
} }
const commonReducer = (state = initialState, action) => { const commonReducer = (state = initialState, action) => {
console.log(action) // console.log(action)
switch (action.type) { switch (action.type) {
case types.SHOW_OR_HIDE_CONTROL: case types.SHOW_OR_HIDE_CONTROL:
return { return {

@ -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 : 2020-01-07 14:19:24 * @LastEditTime : 2020-01-07 15:23:19
*/ */
import axios from 'axios'; import axios from 'axios';
@ -71,7 +71,7 @@ export async function fetchUserProgramDetail (identifier) {
// 获取提交记录 // 获取提交记录
export async function fetchUserCommitRecord (identifier, params) { export async function fetchUserCommitRecord (identifier, params) {
console.log('identifier=====', identifier); // console.log('identifier=====', identifier);
const url = `/myproblems/${identifier}/submit_records.json`; const url = `/myproblems/${identifier}/submit_records.json`;
return axios.get(url, { params }); return axios.get(url, { params });
} }
@ -151,4 +151,7 @@ export async function fetchQuestion (params) {
} }
// 新增选题 // 新增选题
export async function fetchExaminationItems () {} export async function fetchTagDisciplines (params) {
const url = `/tag_disciplines.json`;
return axios.post(url, params);
}
Loading…
Cancel
Save