|
@@ -54,10 +54,12 @@ export default class extends Page {
|
|
|
return result;
|
|
|
});
|
|
|
} else {
|
|
|
- handler = Promise.resolve({ content: { number: 1, type: 'single', typeset: 'one', questions: [], steps: [] }, associationContent: [1], questionNoIds: [1], questionType: 'rc' });
|
|
|
+ handler = Promise.resolve({ content: { number: 1, type: 'single', typeset: 'one', questions: [], steps: [] } });
|
|
|
}
|
|
|
handler.then(result => {
|
|
|
this.uuid[0] = -1;
|
|
|
+ let type = result.content.type || 'single';
|
|
|
+ if (type === 'inline') type = 'single';
|
|
|
result.content.questions.forEach((row, index) => {
|
|
|
const keys = [];
|
|
|
this.uuid[index] = 0;
|
|
@@ -65,27 +67,26 @@ export default class extends Page {
|
|
|
for (; this.uuid[index] < row.select.length; this.uuid[index] += 1) {
|
|
|
keys.push(this.uuid[index]);
|
|
|
form.getFieldDecorator(`content.questions[${index}].select[${this.uuid}]`);
|
|
|
- form.getFieldDecorator(`content.questions[${index}].answer[${this.uuid}]`);
|
|
|
- }
|
|
|
- const answerMap = {};
|
|
|
- row.answer.forEach(r => {
|
|
|
- answerMap[r] = true;
|
|
|
- });
|
|
|
- row.answer = row.select.map(r => answerMap[r] || false);
|
|
|
- } else if (row.answer && row.answer.length > 0) {
|
|
|
- for (; this.uuid[index] < row.answer.length; this.uuid[index] += 1) {
|
|
|
- keys.push(this.uuid);
|
|
|
- form.getFieldDecorator(`content.questions[${index}].answer[${this.uuid}]`);
|
|
|
+ form.getFieldDecorator(`answer.questions[${index}].${type}[${this.uuid}]`);
|
|
|
}
|
|
|
}
|
|
|
form.getFieldDecorator(`content.questions[${index}].keys`);
|
|
|
row.keys = keys;
|
|
|
return row;
|
|
|
});
|
|
|
- result.content.steps.forEach((row, index) => {
|
|
|
+ (result.content.steps || []).forEach((row, index) => {
|
|
|
form.getFieldDecorator(`content.steps[${index}].title`);
|
|
|
form.getFieldDecorator(`content.steps[${index}].stem`);
|
|
|
});
|
|
|
+ const { row, col } = result.content.table;
|
|
|
+ for (let i = 0; i < col; i += 1) {
|
|
|
+ console.log(`content.table.header[${i}]`);
|
|
|
+ form.getFieldDecorator(`content.table.header[${i}]`);
|
|
|
+ for (let j = 0; j < row; j += 1) {
|
|
|
+ console.log(`content.table.data[${j}][${i}]`);
|
|
|
+ form.getFieldDecorator(`content.table.data[${j}][${i}]`);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
form.getFieldDecorator('content.step');
|
|
|
form.getFieldDecorator('content.number');
|
|
@@ -134,6 +135,7 @@ export default class extends Page {
|
|
|
handler.then(result => {
|
|
|
this.placeSetting = result;
|
|
|
this.placeList = result[type] || [];
|
|
|
+ this.setState({ placeList: this.placeList });
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -164,7 +166,7 @@ export default class extends Page {
|
|
|
const { questionNos = [] } = this.state;
|
|
|
questionNos.push(result);
|
|
|
this.setState({ questionNos });
|
|
|
- form.setFieldsValue({ moduleStruct: [], questionNo: '' });
|
|
|
+ form.setFieldsValue({ moduleStruct: [], questionNo: '', questionNoIds: questionNos.map(row => row.id) });
|
|
|
asyncSMessage('保存成功');
|
|
|
}).catch((e) => {
|
|
|
if (e.result) form.setFields(formatFormError(data, e.result));
|
|
@@ -212,7 +214,11 @@ export default class extends Page {
|
|
|
addQuestion(index) {
|
|
|
const { form } = this.props;
|
|
|
const keys = form.getFieldValue(`content.questions[${index}].keys`) || [];
|
|
|
- this.uuid[index] += 1;
|
|
|
+ if (!this.uuid[index]) {
|
|
|
+ this.uuid[index] = 1;
|
|
|
+ } else {
|
|
|
+ this.uuid[index] += 1;
|
|
|
+ }
|
|
|
const nextKeys = keys.concat(this.uuid[index]);
|
|
|
form.setFieldsValue({
|
|
|
[`content.questions[${index}].keys`]: nextKeys,
|
|
@@ -232,16 +238,16 @@ export default class extends Page {
|
|
|
|
|
|
changeQuestion(index, k, value) {
|
|
|
const { form } = this.props;
|
|
|
- let answer = form.getFieldValue(`content.answer[${index}].single`) || [];
|
|
|
+ let answer = form.getFieldValue(`answer.questions[${index}].single`) || [];
|
|
|
answer = answer.map(() => !value);
|
|
|
answer[k] = !!value;
|
|
|
- form.setFieldsValue({ [`content.answer[${index}].single`]: answer });
|
|
|
+ form.setFieldsValue({ [`answer.questions[${index}].single`]: answer });
|
|
|
}
|
|
|
|
|
|
changeDouble(index, k, o, value) {
|
|
|
const { form } = this.props;
|
|
|
const direction = form.getFieldValue(`content.questions[${index}].direction`);
|
|
|
- let answer = form.getFieldValue(`content.answer[${index}].double`) || [];
|
|
|
+ let answer = form.getFieldValue(`answer.questions[${index}].double`) || [];
|
|
|
switch (direction) {
|
|
|
case 'landscape':
|
|
|
answer[k] = answer[k].map(() => !value);
|
|
@@ -257,35 +263,47 @@ export default class extends Page {
|
|
|
break;
|
|
|
default:
|
|
|
}
|
|
|
- form.setFieldsValue({ [`content.answer[${index}].double`]: answer });
|
|
|
+ form.setFieldsValue({ [`answer.questions[${index}].double`]: answer });
|
|
|
}
|
|
|
|
|
|
submit() {
|
|
|
const { form } = this.props;
|
|
|
- const fields = ['type', 'place', 'difficult', 'content', 'answer', 'stem', 'keyword', 'questionNoIds', 'officialContent', 'qxContent', 'associationContent'];
|
|
|
+ const fields = ['id', 'questionType', 'place', 'difficult', 'content', 'answer', 'stem', 'keyword', 'questionNoIds', 'officialContent', 'qxContent', 'associationContent'];
|
|
|
form.validateFields(fields, (err) => {
|
|
|
if (!err) {
|
|
|
const data = form.getFieldsValue(fields);
|
|
|
let handler;
|
|
|
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);
|
|
|
+ data.stem = data.stem || '';
|
|
|
+ data.description = (data.stem || '').replace(/<[^>]+>/g, '');
|
|
|
+ data.qxContent = data.qxContent || '';
|
|
|
+ data.officialContent = data.officialContent || '';
|
|
|
+
|
|
|
+ data.content = data.content || {};
|
|
|
+ data.content.questions = (data.content.questions || []).map(row => {
|
|
|
+ delete row.keys;
|
|
|
+ row.select = (row.select || []).filter(r => r);
|
|
|
return row;
|
|
|
});
|
|
|
- data.answer.questions = data.answer.questions.map(row => {
|
|
|
+ data.answer = data.answer || {};
|
|
|
+ data.answer.questions = (data.answer.questions || []).map(row => {
|
|
|
if (row.single) row.single = row.single.filter(r => r);
|
|
|
if (row.double) row.double = row.double.filter(r => r);
|
|
|
return row;
|
|
|
});
|
|
|
data.relationQuestion = this.state.realtionQuestionNos.map(row => row.id);
|
|
|
- if (data.id) {
|
|
|
+ if (!data.id) {
|
|
|
handler = Question.add(data);
|
|
|
} else {
|
|
|
handler = Question.edit(data);
|
|
|
}
|
|
|
- handler.then(() => {
|
|
|
+ handler.then((result) => {
|
|
|
asyncSMessage('保存成功');
|
|
|
+ if (data.id) {
|
|
|
+ linkTo(`/subject/question/${data.id}`);
|
|
|
+ } else {
|
|
|
+ linkTo(`/subject/question/${result.id}`);
|
|
|
+ }
|
|
|
}).catch((e) => {
|
|
|
if (e.result) form.setFields(formatFormError(data, e.result));
|
|
|
});
|
|
@@ -341,11 +359,9 @@ export default class extends Page {
|
|
|
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 });
|
|
|
});
|
|
@@ -557,7 +573,7 @@ export default class extends Page {
|
|
|
{ required: true, message: '请选择考点' },
|
|
|
],
|
|
|
})(
|
|
|
- <Select select={this.placeList} placeholder='请选择考点' />,
|
|
|
+ <Select select={this.state.placeList} placeholder='请选择考点' />,
|
|
|
)}
|
|
|
</Form.Item>
|
|
|
<Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='难度'>
|
|
@@ -691,8 +707,8 @@ export default class extends Page {
|
|
|
{getFieldDecorator(`answer.questions[${index}].single[${k}]`, {
|
|
|
valuePropName: 'checked',
|
|
|
})(
|
|
|
- <Checkbox onChange={(value) => {
|
|
|
- this.changeQuestion(index, k, value);
|
|
|
+ <Checkbox onChange={(e) => {
|
|
|
+ this.changeQuestion(index, k, e.target.checked);
|
|
|
}} />,
|
|
|
)}
|
|
|
</Col>
|
|
@@ -769,8 +785,8 @@ export default class extends Page {
|
|
|
{getFieldDecorator(`answer.questions[${index}].double[${k}][0]`, {
|
|
|
valuePropName: 'checked',
|
|
|
})(
|
|
|
- <Checkbox onChange={(value) => {
|
|
|
- this.changeDouble(index, k, 0, value);
|
|
|
+ <Checkbox onChange={(e) => {
|
|
|
+ this.changeDouble(index, k, 0, e.target.checkedue);
|
|
|
}} />,
|
|
|
)}
|
|
|
</Col>
|
|
@@ -778,8 +794,8 @@ export default class extends Page {
|
|
|
{getFieldDecorator(`answer.questions[${index}].double[${k}][1]`, {
|
|
|
valuePropName: 'checked',
|
|
|
})(
|
|
|
- <Checkbox onChange={(value) => {
|
|
|
- this.changeDouble(index, k, 1, value);
|
|
|
+ <Checkbox onChange={(e) => {
|
|
|
+ this.changeDouble(index, k, 1, e.target.checked);
|
|
|
}} />,
|
|
|
)}
|
|
|
</Col>
|