|
@@ -6,7 +6,7 @@ import Editor from '@src/components/Editor';
|
|
|
import Page from '@src/containers/Page';
|
|
|
import Block from '@src/components/Block';
|
|
|
import Select from '@src/components/Select';
|
|
|
-import { getMap, formatFormError, formatTreeData } from '@src/services/Tools';
|
|
|
+import { getMap, formatFormError, formatTreeData, generateSearch } from '@src/services/Tools';
|
|
|
import { asyncSMessage, asyncGet } from '@src/services/AsyncTools';
|
|
|
import { QuestionType, QuestionDifficult, QuestionStyleType, QuestionRadioDirection } from '../../../../Constant';
|
|
|
import QuestionNoList from '../../../components/QuestionNoList';
|
|
@@ -22,7 +22,6 @@ export default class extends Page {
|
|
|
super(props);
|
|
|
this.placeList = [];
|
|
|
this.placeSetting = null;
|
|
|
- this.associationContent = [];
|
|
|
this.uuid = [];
|
|
|
this.examinationStructMap = {};
|
|
|
this.exerciseStructMap = {};
|
|
@@ -31,6 +30,7 @@ export default class extends Page {
|
|
|
init() {
|
|
|
Promise.all([
|
|
|
Exercise.allStruct().then(result => {
|
|
|
+ result = result.filter(row => row.isExamination);
|
|
|
this.exerciseStructMap = getMap(result, 'id');
|
|
|
return { value: 'exercise', key: 'exercise', label: '练习', title: '练习', children: formatTreeData(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; return row; }), 'id', 'title', 'parentId') };
|
|
|
}),
|
|
@@ -54,7 +54,7 @@ export default class extends Page {
|
|
|
return result;
|
|
|
});
|
|
|
} else {
|
|
|
- handler = Promise.resolve({ content: { number: 1, type: 'single', typeset: 'one', questions: [], steps: [] } });
|
|
|
+ handler = Promise.resolve({ content: { number: 1, type: 'single', typeset: 'one', questions: [], steps: [] }, associationContent: [1], questionNoIds: [1], questionType: 'rc' });
|
|
|
}
|
|
|
handler.then(result => {
|
|
|
this.uuid[0] = -1;
|
|
@@ -89,16 +89,37 @@ export default class extends Page {
|
|
|
|
|
|
form.getFieldDecorator('content.step');
|
|
|
form.getFieldDecorator('content.number');
|
|
|
+ form.getFieldDecorator('content.table.row');
|
|
|
+ form.getFieldDecorator('content.table.col');
|
|
|
+ form.getFieldDecorator('stem');
|
|
|
+ form.getFieldDecorator('difficult');
|
|
|
+ form.getFieldDecorator('questionType');
|
|
|
+ form.getFieldDecorator('place');
|
|
|
+ form.getFieldDecorator('id');
|
|
|
+ form.getFieldDecorator('questionNoIds');
|
|
|
+ form.getFieldDecorator('relationQuestion');
|
|
|
form.setFieldsValue(result);
|
|
|
return result;
|
|
|
})
|
|
|
.then((result) => {
|
|
|
- this.setState({ associationContentIds: result.associationContent || [] });
|
|
|
+ this.setState({ associationContentQuestionNos: [], realtionQuestionNos: [] });
|
|
|
if (result.questionNoIds && result.questionNoIds.length > 0) {
|
|
|
- return Question.listNo({ ids: result.questionNoIds }).then(list => {
|
|
|
+ Question.listNo({ ids: result.questionNoIds }).then(list => {
|
|
|
this.setState({ questionNos: list });
|
|
|
+ return list;
|
|
|
+ }).then(rr => {
|
|
|
+ // 阅读关联题目: 只有一个id
|
|
|
+ if (rr.length === 1 && rr[0].relationQuestion && rr[0].relationQuestion.length > 0) {
|
|
|
+ this.bindRelationQuestion(rr[0].relationQuestion);
|
|
|
+ } else {
|
|
|
+ this.bindRelationQuestion();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
});
|
|
|
+ } else {
|
|
|
+ this.bindRelationQuestion();
|
|
|
}
|
|
|
+ this.bindAssociationContent(result.associationContent);
|
|
|
return null;
|
|
|
});
|
|
|
}
|
|
@@ -137,7 +158,7 @@ export default class extends Page {
|
|
|
data.questionId = data.id || 0;
|
|
|
delete data.id;
|
|
|
data.no = data.questionNo;
|
|
|
- data.no = `${nodeString}-${data.no}`;
|
|
|
+ data.title = `${nodeString}-${data.no}`;
|
|
|
delete data.questionNo;
|
|
|
Question.addNo(data).then((result) => {
|
|
|
const { questionNos = [] } = this.state;
|
|
@@ -246,7 +267,7 @@ export default class extends Page {
|
|
|
if (!err) {
|
|
|
const data = form.getFieldsValue(fields);
|
|
|
let handler;
|
|
|
- data.associationContent = this.state.associationContent.map(row => row.id);
|
|
|
+ data.associationContent = this.state.associationContentQuestionNos.map(row => row.id);
|
|
|
data.description = data.stem.replace(/<[^>]+>/g, '');
|
|
|
data.content.questions = data.content.questions.map(row => {
|
|
|
row.select = row.select.filter(r => r);
|
|
@@ -257,6 +278,7 @@ export default class extends Page {
|
|
|
if (row.double) row.double = row.double.filter(r => r);
|
|
|
return row;
|
|
|
});
|
|
|
+ data.relationQuestion = this.state.realtionQuestionNos.map(row => row.id);
|
|
|
if (data.id) {
|
|
|
handler = Question.add(data);
|
|
|
} else {
|
|
@@ -290,6 +312,49 @@ export default class extends Page {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ bindAssociationContent(associationContent) {
|
|
|
+ generateSearch('associationContent', { mode: 'multiple' }, this, (search) => {
|
|
|
+ return this.searchQuestion(search);
|
|
|
+ }, (row) => {
|
|
|
+ return {
|
|
|
+ title: row.title,
|
|
|
+ value: row.id,
|
|
|
+ };
|
|
|
+ }, associationContent, null);
|
|
|
+ if (associationContent) this.listQuestion(associationContent, 'ids', 'associationContentQuestionNos');
|
|
|
+ }
|
|
|
+
|
|
|
+ bindRelationQuestion(relationQuestion) {
|
|
|
+ generateSearch('relationQuestion', { mode: 'multiple' }, this, (search) => {
|
|
|
+ return this.searchQuestion(search);
|
|
|
+ }, (row) => {
|
|
|
+ return {
|
|
|
+ title: row.title,
|
|
|
+ value: row.id,
|
|
|
+ };
|
|
|
+ }, relationQuestion, null);
|
|
|
+ if (relationQuestion) this.listQuestion(relationQuestion, 'ids', 'realtionQuestionNos');
|
|
|
+ }
|
|
|
+
|
|
|
+ listQuestion(values, field, targetField) {
|
|
|
+ if (!values || values.length === 0) {
|
|
|
+ this.setState({ [targetField]: [] });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log(targetField, 'loading');
|
|
|
+ this.setState({ [`${targetField}Loading`]: true });
|
|
|
+ Question.listNo({ [field]: values }).then(result => {
|
|
|
+ const map = getMap(result, 'id');
|
|
|
+ console.log(targetField, 'finish');
|
|
|
+ const questionNos = values.map(row => map[row]).filter(row => row);
|
|
|
+ this.setState({ [targetField]: questionNos, [`${targetField}Loading`]: false });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ searchQuestion(params) {
|
|
|
+ return Question.searchNo(params);
|
|
|
+ }
|
|
|
+
|
|
|
renderBase() {
|
|
|
const { getFieldDecorator } = this.props.form;
|
|
|
return <Block flex>
|
|
@@ -426,7 +491,7 @@ export default class extends Page {
|
|
|
return <Tag key={index} closable onClose={() => {
|
|
|
this.removeNo(no.id);
|
|
|
}}>
|
|
|
- {no.no}
|
|
|
+ {no.title}
|
|
|
</Tag>;
|
|
|
})}
|
|
|
<Row>
|
|
@@ -447,7 +512,7 @@ export default class extends Page {
|
|
|
rules: [{
|
|
|
required: true, message: '输入编号',
|
|
|
}],
|
|
|
- })(<Input placeholder='题目id' onClick={(value) => {
|
|
|
+ })(<InputNumber placeholder='题目id' onClick={(value) => {
|
|
|
this.setState({ questionNo: value });
|
|
|
}} />)}
|
|
|
</Form.Item>
|
|
@@ -469,7 +534,9 @@ export default class extends Page {
|
|
|
}
|
|
|
|
|
|
renderAttr() {
|
|
|
- const { getFieldDecorator } = this.props.form;
|
|
|
+ const { getFieldDecorator, getFieldValue, setFieldsValue } = this.props.form;
|
|
|
+ const { questionNos = [] } = this.state;
|
|
|
+ const isRc = getFieldValue('questionType') === 'rc';
|
|
|
return <Block flex>
|
|
|
<h1>题目属性</h1>
|
|
|
<Form>
|
|
@@ -502,6 +569,29 @@ export default class extends Page {
|
|
|
<Select select={QuestionDifficult} placeholder='请选择难度' />,
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
+ {/* 阅读题,并且只有一个id才能关联 */}
|
|
|
+ {isRc && questionNos.length === 1 && <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='关联题目'>
|
|
|
+ {getFieldDecorator('relationQuestion')(
|
|
|
+ <Select mode='multiple' maxTagCount={200} notFoundContent={null} placeholder='输入题目id, 逗号分隔' tokenSeparators={[',', ',']} {...this.state.relationQuestion} onChange={(values) => {
|
|
|
+ this.listQuestion(values, 'ids', 'relationQuestionNos');
|
|
|
+ // this.setState({ relationQuestion: values });
|
|
|
+ }} />,
|
|
|
+ )}
|
|
|
+ <QuestionNoList type='inline' loading={this.state.relationQuestionNosLoading} questionNos={this.state.relationQuestionNos} onChange={(nos) => {
|
|
|
+ getFieldDecorator('relationQuestion');
|
|
|
+ setFieldsValue({ relationQuestion: nos.map(row => row.id) });
|
|
|
+ this.setState({ relationQuestionNos: nos });
|
|
|
+ }}
|
|
|
+ render={(row, dragClass, close) => {
|
|
|
+ return <Tag className={dragClass} closable onClose={() => {
|
|
|
+ close();
|
|
|
+ }}>
|
|
|
+ {row.title}
|
|
|
+ </Tag>;
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </Form.Item>}
|
|
|
+
|
|
|
</Form>
|
|
|
</Block>;
|
|
|
}
|
|
@@ -767,15 +857,16 @@ export default class extends Page {
|
|
|
<Form>
|
|
|
<Form.Item>
|
|
|
{getFieldDecorator('associationContent')(
|
|
|
- <Select mode='tags' maxTagCount={200} notFoundContent={null} placeholder='输入题目id, 逗号分隔' tokenSeparators={[',', ',']} onChange={(values) => {
|
|
|
- this.setState({ associationContent: values });
|
|
|
+ <Select mode='multiple' maxTagCount={200} notFoundContent={null} placeholder='输入题目id, 逗号分隔' tokenSeparators={[',', ',']} {...this.state.associationContent} onChange={(values) => {
|
|
|
+ this.listQuestion(values, 'ids', 'associationContentQuestionNos');
|
|
|
+ // this.setState({ associationContent: values });
|
|
|
}} />,
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
- <QuestionNoList loading={false} ids={this.state.associationContentIds} nos={this.state.associationContent} onChange={(questionNos) => {
|
|
|
- this.associationContent = questionNos;
|
|
|
+ <QuestionNoList loading={this.state.associationContentQuestionNosLoading} questionNos={this.state.associationContentQuestionNos} onChange={(nos) => {
|
|
|
getFieldDecorator('associationContent');
|
|
|
- setFieldsValue({ associationContent: questionNos.map(row => row.no) });
|
|
|
+ setFieldsValue({ associationContent: nos.map(row => row.id) });
|
|
|
+ this.setState({ associationContentQuestionNos: nos });
|
|
|
}} />
|
|
|
</Form>
|
|
|
</Block>;
|