调整数据

yslnewtiku
杨树林 5 years ago
parent b40f9626f5
commit 329cec5830

@ -1,6 +1,6 @@
import React, {Component} from "react";
import {Link, NavLink} from 'react-router-dom';
import {WordsBtn, ActionBtn,SnackbarHOC,getImageUrl} from 'educoder';
import {WordsBtn, ActionBtn, SnackbarHOC, getImageUrl} from 'educoder';
import axios from 'axios';
import {
notification,
@ -31,18 +31,21 @@ class Questionitem_banks extends Component {
super(props);
this.contentMdRef = React.createRef();
this.answerMdRef = React.createRef();
this.Choques= React.createRef();
this.Judquestio= React.createRef();
this.Choques = React.createRef();
this.Judquestio = React.createRef();
this.state = {
item_type:null,
item_banksedit:[],
myquestion_choicesco:[],
item_type: null,
item_banksedit: [],
myquestion_choicesco: [],
disciplinesdata: [],
knowledgepoints: [],
disciplmy:[]
}
}
//初始化
componentDidMount(){
componentDidMount() {
// let {defaultActiveKey}= this.state;
// var data={
// public:defaultActiveKey
@ -64,44 +67,99 @@ class Questionitem_banks extends Component {
// }
// }
// });
const params= this.props&&this.props.match&&this.props.match.params;
if(JSON.stringify(params)==="{}"){
//新增
}else{
const params = this.props && this.props.match && this.props.match.params;
if (JSON.stringify(params) === "{}") {
//新增
} else {
//编辑
const url=`/item_banks/${this.props.match.params.id}/edit.json`;
const url = `/item_banks/${this.props.match.params.id}/edit.json`;
axios.get((url)).then((response) => {
if(response===null||response===undefined){
if (response === null || response === undefined) {
return
}
if (response.data.status === 403||response.data.status === 401||response.data.status === 500) {
return
}
if (response.data.status === 403 || response.data.status === 401 || response.data.status === 500) {
}else{
} else {
}
//////console.log("item_banks");
//console.log("Questionitem_banks");
//console.log(response.data);
}
//////console.log("item_banks");
//console.log("Questionitem_banks");
//console.log(response.data);
this.setState({
item_banksedit:response.data,
item_banksedit: response.data,
})
}).catch((error) => {
//////console.log(error)
}).catch((error) => {
//////console.log(error)
});
});
}
let urls = `/disciplines.json`;
axios.get(urls, {
params: {
source: "question"
}
}).then((response) => {
if (response) {
this.setState({
disciplinesdata: response.data.disciplines,
})
if (response.data) {
if (response.data.disciplines) {
const didata = response.data.disciplines;
for (var i = 0; i < didata.length; i++) {
//方向
const fxdidata = didata[i].sub_disciplines;
for (var j = 0; j < fxdidata.length; j++) {
//课程
const zsddata = fxdidata[j].tag_disciplines;
const datakec={
value: didata[i].id,
label: didata[i].name,
children: [
{
value: fxdidata[j].id,
label: fxdidata[j].name,
},
],
}
this.state.disciplmy.push(datakec);
for (var k = 0; k < zsddata.length; k++) {
//知识点
this.state.knowledgepoints.push(zsddata[k]);
}
}
}
this.setState({
knowledgepoints: this.state.knowledgepoints,
disciplmy:this.state.disciplmy,
})
}
}
}
});
}
getdata =(data)=>{
getdata = (data) => {
// const url=`/item_banks.json`;
// axios.get((url),{params:data}).then((response) => {
// if(response===null||response===undefined){
@ -121,19 +179,19 @@ class Questionitem_banks extends Component {
// });
}
getcontentMdRef=(Ref)=>{
this.contentMdRef=Ref;
}
getanswerMdRef=(Ref)=>{
this.answerMdRef=Ref;
getcontentMdRef = (Ref) => {
this.contentMdRef = Ref;
}
getanswerMdRef = (Ref) => {
this.answerMdRef = Ref;
}
getJudquestio=(Ref)=>{
this.Judquestio=Ref;
getJudquestio = (Ref) => {
this.Judquestio = Ref;
}
getChoquesEditor=(Ref)=>{
this.Choques=Ref;
getChoquesEditor = (Ref) => {
this.Choques = Ref;
}
//跳转道描点的地方
scrollToAnchor = (anchorName) => {
@ -146,12 +204,12 @@ class Questionitem_banks extends Component {
anchorElement.scrollIntoView();
}
}
}catch (e) {
} catch (e) {
}
}
preservation=()=>{
preservation = () => {
//////console.log("preservation");
// //////console.log(this.contentMdRef);
// //////console.log(this.answerMdRef);
@ -159,136 +217,135 @@ class Questionitem_banks extends Component {
//////console.log(this.contentMdRef.Getdatas());
//////console.log("preservation3333");
//////console.log(this.answerMdRef.onSave());
const params= this.props&&this.props.match&&this.props.match.params;
var url="";
var boolnew=true;
if(JSON.stringify(params)==="{}"){
const params = this.props && this.props.match && this.props.match.params;
var url = "";
var boolnew = true;
if (JSON.stringify(params) === "{}") {
// "新增"
url="/item_banks.json";
boolnew=true;
}else{
url=`/item_banks/${params.id}.json`;
boolnew=false;
url = "/item_banks.json";
boolnew = true;
} else {
url = `/item_banks/${params.id}.json`;
boolnew = false;
// "编辑"
}
if(this.contentMdRef.Getdatas().length===0){
this.scrollToAnchor("Itembankstopid");
return;
}
if(this.state.item_type===null){
return
}
if(this.state.item_type==="SINGLE"){
if( this.answerMdRef!=null){
//单选题
// //console.log(this.answerMdRef.onSave());
if(this.answerMdRef.onSave().length===0){
return;
}
var anserdata=this.answerMdRef.onSave();
const choices=[];
// 1: [3]
// 2: (4) ["1", "2", "3", "4"]
for(var k=0;k<anserdata[2].length;k++){
const choicesdata={
choice_text:anserdata[2][k],
is_answer:anserdata[1][0]===(k+1)?1:0,
}
choices.push(choicesdata);
}
// repertoire_id:1,
// sub_repertoire_id:1,
// tag_repertoire_id:[1,3],
var data={
discipline_id:1,
sub_discipline_id:1,
tag_discipline_id:[1,3],
name:anserdata[0],
item_type:"SINGLE",
difficulty:2,
analysis:anserdata[3],
choices:choices,
};
if(boolnew===true){
axios.post(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`新增单选题成功`);
this.props.history.replace('/question');
}
}).catch((error) => {
//console.log(error);
})
}else{
axios.put(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`编辑单选题成功`);
this.props.history.replace('/question');
}
}).catch((error) => {
//console.log(error);
})
}
}
}
if(this.state.item_type==="MULTIPLE"){
if(this.Choques!=null){
if (this.contentMdRef.Getdatas().length === 0) {
this.scrollToAnchor("Itembankstopid");
return;
}
if (this.state.item_type === null) {
return
}
if (this.state.item_type === "SINGLE") {
if (this.answerMdRef != null) {
//单选题
// //console.log(this.answerMdRef.onSave());
if (this.answerMdRef.onSave().length === 0) {
return;
}
var anserdata = this.answerMdRef.onSave();
const choices = [];
// 1: [3]
// 2: (4) ["1", "2", "3", "4"]
for (var k = 0; k < anserdata[2].length; k++) {
const choicesdata = {
choice_text: anserdata[2][k],
is_answer: anserdata[1][0] === (k + 1) ? 1 : 0,
}
choices.push(choicesdata);
}
// repertoire_id:1,
// sub_repertoire_id:1,
// tag_repertoire_id:[1,3],
var data = {
discipline_id: 1,
sub_discipline_id: 1,
tag_discipline_id: [1, 3],
name: anserdata[0],
item_type: "SINGLE",
difficulty: 2,
analysis: anserdata[3],
choices: choices,
};
if (boolnew === true) {
axios.post(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`新增单选题成功`);
this.props.history.replace('/question');
}
}).catch((error) => {
//console.log(error);
})
} else {
axios.put(url, data)
.then((result) => {
if (result.data.status == 0) {
this.props.showNotification(`编辑单选题成功`);
this.props.history.replace('/question');
}
}).catch((error) => {
//console.log(error);
})
}
}
}
if (this.state.item_type === "MULTIPLE") {
if (this.Choques != null) {
//多选题
// //console.log(this.Choques.onSave());
if(this.Choques.onSave().length===0){
if (this.Choques.onSave().length === 0) {
return;
}
var anserdata=this.Choques.onSave();
const choices=[];
var anserdata = this.Choques.onSave();
const choices = [];
// 1: [3]
// 2: (4) ["1", "2", "3", "4"]
//console.log("MULTIPLE");
//console.log(anserdata);
for(var k=0;k<anserdata[2].length;k++){
for (var k = 0; k < anserdata[2].length; k++) {
var bool =false
for(var y=0;y<anserdata[1].length;y++){
if(anserdata[1][y]===(k+1)){
bool=true
var bool = false
for (var y = 0; y < anserdata[1].length; y++) {
if (anserdata[1][y] === (k + 1)) {
bool = true
}
}
const choicesdata={
choice_text:anserdata[2][k],
is_answer:bool===true?1:0,
const choicesdata = {
choice_text: anserdata[2][k],
is_answer: bool === true ? 1 : 0,
}
choices.push(choicesdata);
}
var data={
discipline_id:1,
sub_discipline_id:1,
tag_discipline_id:[1,3],
name:anserdata[0],
item_type:"MULTIPLE",
difficulty:2,
analysis:anserdata[3],
choices:choices,
var data = {
discipline_id: 1,
sub_discipline_id: 1,
tag_discipline_id: [1, 3],
name: anserdata[0],
item_type: "MULTIPLE",
difficulty: 2,
analysis: anserdata[3],
choices: choices,
}
if(boolnew===true) {
if (boolnew === true) {
axios.post(url, data)
.then((result) => {
if (result.data.status == 0) {
@ -301,7 +358,7 @@ class Questionitem_banks extends Component {
//console.log(error);
})
}else{
} else {
axios.put(url, data)
.then((result) => {
if (result.data.status == 0) {
@ -316,46 +373,41 @@ class Questionitem_banks extends Component {
}
}
}
if(this.state.item_type==="JUDGMENT"){
if( this.Judquestio !=null){
if (this.state.item_type === "JUDGMENT") {
if (this.Judquestio != null) {
//判断题
// //console.log(this.Judquestio.onSave());
if(this.Judquestio.onSave().length===0){
if (this.Judquestio.onSave().length === 0) {
return;
}
var anserdata=this.Judquestio.onSave();
const choices=[];
const choicesdata={
choice_text:"正确",
is_answer:anserdata[1]==="0"?1:0,
}
choices.push(choicesdata);
var anserdata = this.Judquestio.onSave();
const choices = [];
const choicesdata = {
choice_text: "正确",
is_answer: anserdata[1] === "0" ? 1 : 0,
}
choices.push(choicesdata);
const choicesdatas={
choice_text:"错误",
is_answer:anserdata[1]==="1"?1:0,
const choicesdatas = {
choice_text: "错误",
is_answer: anserdata[1] === "1" ? 1 : 0,
}
choices.push(choicesdatas);
var data={
discipline_id:1,
sub_discipline_id:1,
tag_discipline_id:[1,3],
name:anserdata[0],
item_type:"JUDGMENT",
difficulty:2,
analysis:anserdata[2],
choices:choices,
var data = {
discipline_id: 1,
sub_discipline_id: 1,
tag_discipline_id: [1, 3],
name: anserdata[0],
item_type: "JUDGMENT",
difficulty: 2,
analysis: anserdata[2],
choices: choices,
}
if(boolnew===true) {
if (boolnew === true) {
axios.post(url, data)
.then((result) => {
if (result.data.status == 0) {
@ -367,7 +419,7 @@ class Questionitem_banks extends Component {
//console.log(error);
})
}else{
} else {
axios.put(url, data)
.then((result) => {
if (result.data.status == 0) {
@ -381,143 +433,128 @@ class Questionitem_banks extends Component {
}
}
}
if(this.state.item_type==="PROGRAM"){
if (this.state.item_type === "PROGRAM") {
//编程题 跳转到 oj 中创建
}
}
setitem_type=(item_type)=>{
setitem_type = (item_type) => {
this.setState({
item_type:item_type
item_type: item_type
})
}
render() {
let {page,limit,count,Headertop,visible,placement,modalsType,item_type}=this.state;
let {page, limit, count, Headertop, visible, placement, modalsType, item_type} = this.state;
{/*<Option value="SINGLE">单选题</Option>*/}
{/*<Option value="MULTIPLE">多选题</Option>*/}
{/*<Option value="JUDGMENT">判断题</Option>*/}
{/*<Option value="PROGRAM">编程题</Option>*/}
{/*<Option value="SINGLE">单选题</Option>*/
}
{/*<Option value="MULTIPLE">多选题</Option>*/
}
{/*<Option value="JUDGMENT">判断题</Option>*/
}
{/*<Option value="PROGRAM">编程题</Option>*/
}
//////console.log("塞选的数据");
//////console.log("塞选的数据");
//////console.log(item_type);
const params= this.props&&this.props.match&&this.props.match.params;
// //console.log(params);
const params = this.props && this.props.match && this.props.match.params;
// //console.log(params);
return (
<div>
<div id={"Itembankstopid"} className="newMain clearfix intermediatecenter "
style={{
<div id={"Itembankstopid"} className="newMain clearfix intermediatecenter "
style={{}}
>
}}
>
<style>
{
`
<style>
{
`
.newFooter{
display: none;
}
`
}
</style>
<div className="w1200mss">
<div className="w100s mt30">
<Breadcrumb separator=">">
<Breadcrumb.Item href="/question">试题库</Breadcrumb.Item>
<Breadcrumb.Item >{JSON.stringify(params)==="{}"?"新增":"编辑"}试题</Breadcrumb.Item>
</Breadcrumb>
</div>
<Itembankstop
{...this.state}
{...this.props}
getcontentMdRef={(ref)=>this.getcontentMdRef(ref)}
setitem_type={(item)=>this.setitem_type(item)}
>
</Itembankstop>
{
item_type&&item_type==="SINGLE"?
<div className=" clearfix educontent w100s w1200fpx mt19" >
<SingleEditor
{...this.state}
{...this.props}
getanswerMdRef={(ref)=>this.getanswerMdRef(ref)}
>
</SingleEditor>
</div>
:item_type&&item_type==="MULTIPLE"?
<div className=" clearfix educontent w100s w1200fpx mt19" >
<ChoquesEditor
{...this.state}
{...this.props}
getanswerMdRef={(ref)=>this.getChoquesEditor(ref)}
>
</ChoquesEditor>
</div>
:item_type&&item_type==="JUDGMENT"?
<div className=" clearfix educontent w100s w1200fpx mt19" >
<JudquestionEditor
}
</style>
<div className="w1200mss">
<div className="w100s mt30">
<Breadcrumb separator=">">
<Breadcrumb.Item href="/question">试题库</Breadcrumb.Item>
<Breadcrumb.Item>{JSON.stringify(params) === "{}" ? "新增" : "编辑"}试题</Breadcrumb.Item>
</Breadcrumb>
</div>
<Itembankstop
{...this.state}
{...this.props}
getcontentMdRef={(ref) => this.getcontentMdRef(ref)}
setitem_type={(item) => this.setitem_type(item)}
>
</Itembankstop>
{
item_type && item_type === "SINGLE" ?
<div className=" clearfix educontent w100s w1200fpx mt19">
<SingleEditor
{...this.state}
{...this.props}
item_banksedit={this.state.item_banksedit}
getanswerMdRef={(ref)=>this.getJudquestio(ref)}
getanswerMdRef={(ref) => this.getanswerMdRef(ref)}
>
</JudquestionEditor>
</SingleEditor>
</div>
: item_type && item_type === "MULTIPLE" ?
<div className=" clearfix educontent w100s w1200fpx mt19">
<ChoquesEditor
{...this.state}
{...this.props}
getanswerMdRef={(ref) => this.getChoquesEditor(ref)}
>
</ChoquesEditor>
</div>
: item_type && item_type === "JUDGMENT" ?
:item_type&&item_type==="PROGRAM"?
""
:""
}
</div>
<div className=" clearfix educontent w100s w1200fpx mt19">
<JudquestionEditor
{...this.state}
{...this.props}
item_banksedit={this.state.item_banksedit}
getanswerMdRef={(ref) => this.getJudquestio(ref)}
>
</JudquestionEditor>
</div>
: item_type && item_type === "PROGRAM" ?
""
: ""
}
</div>
</div>
</div>
{
item_type===null?
""
:
<Bottomsubmit {...this.props} {...this.state} bottomvalue={item_type==="PROGRAM"?"创建":"保存"} onSubmits={() => this.preservation()} url={'/question'}></Bottomsubmit>
item_type === null ?
""
:
<Bottomsubmit {...this.props} {...this.state} bottomvalue={item_type === "PROGRAM" ? "创建" : "保存"}
onSubmits={() => this.preservation()} url={'/question'}></Bottomsubmit>
}
</div>
)
@ -525,9 +562,9 @@ class Questionitem_banks extends Component {
}
}
export default SnackbarHOC() (TPMIndexHOC ( Questionitem_banks ));
export default SnackbarHOC()(TPMIndexHOC(Questionitem_banks));
// {
// item_type===null?

@ -20,18 +20,12 @@ const InputGroup = Input.Group;
const { Option } = Select;
const options = [
{
value: 'zhejiang',
label: 'Zhejiang',
value: '方向',
label: '方向',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [
{
value: 'xihu',
label: 'West Lake',
},
],
value: '课程',
label: '课程',
},
],
},
@ -42,12 +36,6 @@ const options = [
{
value: 'nanjing',
label: 'Nanjing',
children: [
{
value: 'zhonghuamen',
label: 'Zhong Hua Men',
},
],
},
],
},
@ -60,6 +48,8 @@ class Itembankstop extends Component {
page:1,
Knowpoints:[],
rbtx:undefined,
knowledgepoints:[],
options:[],
}
}
//初始化
@ -69,6 +59,10 @@ class Itembankstop extends Component {
}catch (e) {
}
this.setState({
knowledgepoints:this.props.knowledgepoints,
options:this.props.disciplmy
})
////console.log("componentDidMount");
////console.log(this.state);
////console.log(this.props);
@ -101,6 +95,21 @@ class Itembankstop extends Component {
}
}
if(prevProps.knowledgepoints !== this.props.knowledgepoints){
this.setState({
knowledgepoints:this.props.knowledgepoints
})
}
if(prevProps.disciplmy !== this.props.disciplmy){
this.setState({
options:this.props.disciplmy
})
}
}
onChange=(e)=> {
////console.log(`checked = ${e.target.checked}`);
@ -155,6 +164,26 @@ class Itembankstop extends Component {
rbkc:value,
});
var arr= this.state.knowledgepoints;
for(let data of arr) {
if(data.id===value){
this.state.Knowpoints.push(data);
}
}
var tmp = JSON.parse(JSON.stringify(this.state.knowledgepoints));
for(var i=0;i<tmp.length;i++){
debugger
if(tmp[i].id===value) {
this.state.knowledgepoints.splice(i, 1);
}
}
this.setState({
Knowpoints:this.state.Knowpoints,
knowledgepoints:this.state.knowledgepoints,
})
}
handleFormzhishidian=(value)=>{
@ -164,9 +193,7 @@ class Itembankstop extends Component {
this.props.form.setFieldsValue({
rbzsd:value,
});
this.setState({
Knowpoints:value,
})
}
handleFormtixing=(value)=>{
@ -186,6 +213,14 @@ class Itembankstop extends Component {
////console.log('Clicked! But prevent default.');
}
deletesobject=(item,index)=>{
var arr= this.state.Knowpoints ;
for(let data of arr) {
if(data.id===item.id){
this.state.knowledgepoints.push(data);
}
}
var tmp = JSON.parse(JSON.stringify(this.state.Knowpoints));
for(var i=0;i<tmp.length;i++){
if(i>=index){
@ -197,22 +232,17 @@ class Itembankstop extends Component {
this.props.form.setFieldsValue({
rbzsd:this.state.Knowpoints,
});
this.setState({
Knowpoints:this.state.Knowpoints,
})
// ////console.log("deletesobject");
// ////console.log(item);
// ////console.log(index);
// ////console.log(this.state.Knowpoints);
// ////console.log("tmp");
// ////console.log(tmp);
}
render() {
let {page}=this.state;
let {page,options}=this.state;
const { getFieldDecorator } = this.props.form;
//console.log("renderrenderrender");
//console.log(this.props.item_banksedit);
@ -251,39 +281,62 @@ class Itembankstop extends Component {
}
</style>
<div className="h12"></div>
<Form onSubmit={this.handleSubmit}>
<Form.Item
<Form.Item
label="课程"
>
{getFieldDecorator("rbkc",
{getFieldDecorator("rbzsd",
{
rules: [{ required: true, message: '请选择课程' }],
}
)(
<div className="sortinxdirection">
<InputGroup compact >
<Cascader style={{ width: '258px' }} defaultValue={this.state.Knowpoints} options={options} onChange={this.handleFormzhishidian} placeholder="请选择..." />
</InputGroup>
<InputGroup compact >
<Select style={{ width: '258px' }} onChange={this.handleFormkechen} placeholder="请选择...">
<Option value="Home">Home</Option>
<Option value="Company">Company</Option>
</Select>
</InputGroup>
{/*<div className="sortinxdirection" style={{*/}
{/* height: "33px",*/}
{/* lineHeight: "28px",*/}
{/*}}>*/}
{/* {this.state.Knowpoints === undefined ? "" : this.state.Knowpoints.map((object, index) => {*/}
{/* return (*/}
{/* <div className="mytags" style={{*/}
{/* position: "relative",*/}
{/* }}>*/}
{/* <p className="w100s stestcen lh32">{object}</p>*/}
{/* <i className="iconfont icon-roundclose font-25 lg ml7 icondowncolorss" onClick={()=>this.deletesobject(object,index)}></i>*/}
{/* </div>*/}
{/* )*/}
{/* })}*/}
{/*</div>*/}
</div>
)}
</Form.Item>
<Form.Item
<Form onSubmit={this.handleSubmit}>
<Form.Item
label="知识点"
>
{getFieldDecorator("rbzsd",
{getFieldDecorator("rbkc",
{
rules: [{ required: true, message: '请选择知识点' }],
}
)(
<div className="sortinxdirection">
<InputGroup compact >
<Cascader style={{ width: '258px' }} defaultValue={this.state.Knowpoints} options={options} onChange={this.handleFormzhishidian} placeholder="请选择..." />
</InputGroup>
<InputGroup compact >
<Select style={{ width: '258px' }} onChange={this.handleFormkechen} placeholder="请选择...">
{this.state.knowledgepoints&&this.state.knowledgepoints.map((object, index) => {
return (
<Option value={object.id}>{object.name}</Option>
)
})}
</Select>
</InputGroup>
<div className="sortinxdirection" style={{
height: "33px",
lineHeight: "28px",
@ -295,7 +348,7 @@ class Itembankstop extends Component {
<div className="mytags" style={{
position: "relative",
}}>
<p className="w100s stestcen lh32">{object}</p>
<p className="w100s stestcen lh32">{object.name}</p>
<i className="iconfont icon-roundclose font-25 lg ml7 icondowncolorss" onClick={()=>this.deletesobject(object,index)}></i>
</div>
)
@ -303,7 +356,6 @@ class Itembankstop extends Component {
</div>
</div>
)}
</Form.Item>

Loading…
Cancel
Save