add knowledge

dev_static
tangjiang 5 years ago
parent 6a377c17c5
commit 9540b348dd

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

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 10:35:40
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-06 16:17:22
* @LastEditTime : 2020-01-07 15:21:19
*/
import './index.scss';
// import 'katex/dist/katex.css';
@ -61,6 +61,7 @@ class EditTab extends React.Component {
top: 500,
bottom: 20,
offsetTop: 0,
showAdd: false
// knowledges: [],
// coursers: [] // 选中的课程
}
@ -147,13 +148,15 @@ class EditTab extends React.Component {
item.sub_disciplines && item.sub_disciplines.forEach(c => {
if (value[1] && c.id === value[1]) {
saveKnowledge(c.tag_disciplines)
console.log(c.tag_disciplines);
} else if (!value[1]) {
saveKnowledge([]);
}
});
}
});
this.setState({
showAdd: value[1] ? true : false
});
// this.props.validateOjCategory(value[1] || '');
this.props.validateOjSubDisciplineId(value[1] || '');
}
@ -167,6 +170,7 @@ class EditTab extends React.Component {
}
render () {
const { showAdd } = this.state;
const {
ojForm,
ojFormValidate,
@ -177,9 +181,10 @@ class EditTab extends React.Component {
openTestCodeIndex = [],
courseQuestions,
tag_discipline_id,
knowledges
knowledges,
tagDisciplines,
} = this.props;
console.log('knowledge======>>>>>>', knowledges);
// console.log('knowledge======>>>>>>', knowledges);
// const {knowledges} = this.state;
// 表单label
const myLabel = (name, subTitle, nostar) => {
@ -321,7 +326,7 @@ class EditTab extends React.Component {
}
});
console.log(choid_ids);
// console.log(choid_ids);
return (
<Cascader
placeholder="请选择"
@ -340,10 +345,19 @@ class EditTab extends React.Component {
values.forEach(v => {
_result.push(v.id);
});
console.log('下拉选择的值:===>>>', _result);
// console.log('下拉选择的值:===>>>', _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 (
<div className={'editor_area'} id="textCase">
@ -383,10 +397,12 @@ class EditTab extends React.Component {
className='input_area flex_100'
label={<span>{myLabel(jcLabel['knowledge'], '', 'nostar')}</span>}
>
<KnowLedge
<KnowLedge
showAdd={showAdd}
options={knowledges}
values={tag_discipline_id}
onChange={handleKnowledgeChange}
addKnowledge={handleAddKnowledge}
/>
</FormItem>
@ -514,7 +530,8 @@ const mapDispatchToProps = (dispatch) => ({
addTestCase: (value) => dispatch(actions.addTestCase(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))
});

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

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

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 16:35:46
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-03 16:40:54
* @LastEditTime : 2020-01-07 14:58:05
*/
import types from './actionTypes';
import CONST from '../../constants';
@ -13,7 +13,8 @@ import {
fetchGetOjById,
publishTask,
cancelPublicTask,
fetchQuestion
fetchQuestion,
fetchTagDisciplines
} from '../../services/ojService';
import { Base64 } from 'js-base64';
import { notification } from 'antd';
@ -675,14 +676,32 @@ export const updateOpenTestCaseIndex = (value) => {
// 获取课程题库
export const getQuestion = (params) => {
return (dispatch) => {
return (dispatch, getState) => {
const {ojForm: {sub_discipline_id}} = getState().ojFormReducer;
fetchQuestion(params).then(res => {
const { data = {} } = res;
const { disciplines = [] } = data;
dispatch({
type: types.GET_COURSE_QUESTION,
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
}
}
// 新增知识点
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
* @Github:
* @Date: 2019-11-27 16:27:09
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-12 17:36:51
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-07 15:23:39
*/
import types from "../actions/actionTypes";
@ -22,7 +22,7 @@ const initialState = {
}
const commonReducer = (state = initialState, action) => {
console.log(action)
// console.log(action)
switch (action.type) {
case types.SHOW_OR_HIDE_CONTROL:
return {

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 10:55:38
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-07 14:19:24
* @LastEditTime : 2020-01-07 15:23:19
*/
import axios from 'axios';
@ -71,7 +71,7 @@ export async function fetchUserProgramDetail (identifier) {
// 获取提交记录
export async function fetchUserCommitRecord (identifier, params) {
console.log('identifier=====', identifier);
// console.log('identifier=====', identifier);
const url = `/myproblems/${identifier}/submit_records.json`;
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