page.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. import React from 'react';
  2. import { Tabs, Form, Tag, InputNumber, Radio, Row, Col, Checkbox, Icon, Input, Button, List, Cascader, Switch } from 'antd';
  3. import './index.less';
  4. import DragList from '@src/components/DragList';
  5. import Editor from '@src/components/Editor';
  6. import Page from '@src/containers/Page';
  7. import Block from '@src/components/Block';
  8. import Select from '@src/components/Select';
  9. import { getMap, formatFormError, formatTreeData, generateSearch } from '@src/services/Tools';
  10. import { asyncSMessage, asyncGet } from '@src/services/AsyncTools';
  11. import { QuestionType, QuestionDifficult, QuestionStyleType, QuestionRadioDirection } from '../../../../Constant';
  12. import QuestionNoList from '../../../components/QuestionNoList';
  13. import { System } from '../../../stores/system';
  14. import { Question } from '../../../stores/question';
  15. import { Examination } from '../../../stores/examination';
  16. import { Exercise } from '../../../stores/exercise';
  17. const QuestionStyleTypeMap = getMap(QuestionStyleType, 'value', 'label');
  18. const DifficultScoreMap = {
  19. verbal: {
  20. easy: [{ label: 6, value: 6 }, { label: 7.6, value: 7.6 }, { label: 9.2, value: 9.2 }, { label: 10.8, value: 10.8 }, { label: 12.4, value: 12.4 }],
  21. medium: [{ label: 14, value: 14 }, { label: 15.6, value: 15.6 }, { label: 17.2, value: 17.2 }, { label: 18.8, value: 18.8 }, { label: 20.4, value: 20.4 }],
  22. hard: [{ label: 22, value: 22 }, { label: 23.6, value: 23.6 }, { label: 25.2, value: 25.2 }, { label: 26.8, value: 26.8 }, { label: 28.4, value: 28.4 }],
  23. },
  24. quant: {
  25. easy: [{ label: 12, value: 12 }, { label: 13.5, value: 13.5 }],
  26. medium: [{ label: 15, value: 15 }, { label: 16.5, value: 16.5 }, { label: 18, value: 18 }, { label: 19.5, value: 19.5 }, { label: 21, value: 21 }],
  27. hard: [{ label: 22.5, value: 22.5 }, { label: 24, value: 24 }, { label: 25.5, value: 25.5 }, { label: 27, value: 27 }, { label: 28.5, value: 28.5 }],
  28. },
  29. };
  30. export default class extends Page {
  31. constructor(props) {
  32. super(props);
  33. this.placeList = [];
  34. this.placeSetting = null;
  35. this.uuid = [];
  36. this.examinationStructMap = {};
  37. this.exerciseStructMap = {};
  38. this.questionTypeToSubject = {};
  39. }
  40. init() {
  41. Promise.all([
  42. Exercise.allStruct().then(result => {
  43. result = result.filter(row => row.isExamination);
  44. this.exerciseStructMap = getMap(result, 'id');
  45. result.forEach((row) => {
  46. if (row.level !== 2) return;
  47. const subject = this.exerciseStructMap[row.parentId];
  48. this.questionTypeToSubject[row.extend] = subject.extend;
  49. });
  50. return { value: 'exercise', key: 'exercise', label: '练习', title: '练习', children: formatTreeData(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; return row; }), 'id', 'title', 'parentId') };
  51. }),
  52. Examination.allStruct().then(result => {
  53. this.examinationStructMap = getMap(result, 'id');
  54. return { value: 'examination', key: 'examination', label: '模考', title: '模考', children: formatTreeData(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; return row; }), 'id', 'title', 'parentId') };
  55. }),
  56. ]).then(result => {
  57. this.setState({ moduleStructData: result });
  58. });
  59. }
  60. initData() {
  61. const { id } = this.params;
  62. const { form } = this.props;
  63. let handler;
  64. if (id) {
  65. handler = Question.get({ id }).then(result => {
  66. result.content = result.content || { questions: [], steps: [] };
  67. result.keyword = result.keyword ? result.keyword.filter(row => row) : [];
  68. return result;
  69. });
  70. } else {
  71. handler = Promise.resolve({ content: { number: 1, type: 'single', typeset: 'one', questions: [], steps: [], table: {} } });
  72. }
  73. handler.then(result => {
  74. this.uuid[0] = -1;
  75. let type = result.content.type || 'single';
  76. if (type === 'inline') type = 'single';
  77. result.content.questions.forEach((row, index) => {
  78. const keys = [];
  79. this.uuid[index] = 0;
  80. if (row.select && row.select.length > 0) {
  81. for (; this.uuid[index] < row.select.length; this.uuid[index] += 1) {
  82. keys.push(this.uuid[index]);
  83. form.getFieldDecorator(`content.questions[${index}].select[${this.uuid[index]}]`);
  84. form.getFieldDecorator(`content.questions[${index}].direction`);
  85. form.getFieldDecorator(`content.questions[${index}].first`);
  86. form.getFieldDecorator(`content.questions[${index}].second`);
  87. form.getFieldDecorator(`content.questions[${index}].description`);
  88. if (type === 'double') {
  89. form.getFieldDecorator(`answer.questions[${index}].${type}[${this.uuid[index]}][0]`);
  90. form.getFieldDecorator(`answer.questions[${index}].${type}[${this.uuid[index]}][1]`);
  91. } else {
  92. form.getFieldDecorator(`answer.questions[${index}].${type}[${this.uuid[index]}]`);
  93. }
  94. }
  95. }
  96. form.getFieldDecorator(`content.questions[${index}].keys`);
  97. row.keys = keys;
  98. return row;
  99. });
  100. (result.content.steps || []).forEach((row, index) => {
  101. form.getFieldDecorator(`content.steps[${index}].title`);
  102. form.getFieldDecorator(`content.steps[${index}].stem`);
  103. });
  104. const { row, col } = result.content.table;
  105. for (let i = 0; i < col; i += 1) {
  106. form.getFieldDecorator(`content.table.header[${i}]`);
  107. for (let j = 0; j < row; j += 1) {
  108. // console.log(`content.table.data[${j}][${i}]`);
  109. form.getFieldDecorator(`content.table.data[${j}][${i}]`);
  110. }
  111. }
  112. form.getFieldDecorator('content.step');
  113. form.getFieldDecorator('content.number');
  114. form.getFieldDecorator('content.table.row');
  115. form.getFieldDecorator('content.table.col');
  116. form.getFieldDecorator('stem');
  117. form.getFieldDecorator('difficult');
  118. form.getFieldDecorator('difficultScore');
  119. form.getFieldDecorator('questionType');
  120. form.getFieldDecorator('place');
  121. form.getFieldDecorator('id');
  122. form.getFieldDecorator('questionNoIds');
  123. form.getFieldDecorator('relationQuestion');
  124. form.setFieldsValue(result);
  125. return result;
  126. })
  127. .then((result) => {
  128. this.refreshPlace(result.questionType);
  129. this.refreshDifficultScore(result.questionType, result.difficult);
  130. form.getFieldDecorator('difficultScore');
  131. form.setFieldsValue({ difficultScore: result.difficultScore });
  132. this.setState({ associationContentQuestionNos: [], relationQuestionNos: [] });
  133. if (result.questionNoIds && result.questionNoIds.length > 0) {
  134. Question.listNo({ ids: result.questionNoIds }).then(list => {
  135. this.setState({ questionNos: list });
  136. return list;
  137. }).then(rr => {
  138. // 阅读关联题目: 只有一个id
  139. if (rr.length === 1 && rr[0].relationQuestion && rr[0].relationQuestion.length > 0) {
  140. form.getFieldDecorator('rcType');
  141. form.setFieldsValue({ rcType: true });
  142. this.bindRelationQuestion(rr[0].relationQuestion);
  143. } else {
  144. this.bindRelationQuestion();
  145. }
  146. return null;
  147. });
  148. } else {
  149. this.bindRelationQuestion();
  150. }
  151. this.bindAssociationContent(result.associationContent);
  152. return null;
  153. });
  154. }
  155. refreshPlace(type) {
  156. let handler = null;
  157. if (this.placeSetting) {
  158. handler = Promise.resolve(this.placeSetting);
  159. } else {
  160. handler = System.getPlace();
  161. }
  162. handler.then(result => {
  163. this.placeSetting = result;
  164. this.placeList = result[type] || [];
  165. this.setState({ placeList: this.placeList });
  166. });
  167. }
  168. refreshDifficultScore(questionType, difficult) {
  169. const subject = this.questionTypeToSubject[questionType];
  170. const difficultScore = (DifficultScoreMap[subject] || {})[difficult] || [];
  171. this.setState({ difficultScore });
  172. }
  173. addNo() {
  174. const { form } = this.props;
  175. form.validateFields(['moduleStruct', 'questionNo'], (err) => {
  176. if (!err) {
  177. const data = form.getFieldsValue(['id', 'moduleStruct', 'questionNo']);
  178. data.moduleStruct = data.moduleStruct.map(row => row);
  179. data.module = data.moduleStruct.shift();
  180. const node = data.moduleStruct[data.moduleStruct.length - 1];
  181. let nodeString;
  182. switch (data.module) {
  183. case 'exercise':
  184. nodeString = this.exerciseStructMap[node].titleZh;
  185. break;
  186. case 'examination':
  187. nodeString = this.examinationStructMap[node].titleZh;
  188. break;
  189. default:
  190. }
  191. data.questionId = data.id || 0;
  192. delete data.id;
  193. data.no = data.questionNo;
  194. data.title = `${nodeString}-${data.no}`;
  195. delete data.questionNo;
  196. Question.addNo(data).then((result) => {
  197. const { questionNos = [] } = this.state;
  198. questionNos.push(result);
  199. this.setState({ questionNos });
  200. form.setFieldsValue({ moduleStruct: [], questionNo: '', questionNoIds: questionNos.map(row => row.id) });
  201. asyncSMessage('保存成功');
  202. }).catch((e) => {
  203. if (e.result) {
  204. form.setFields(formatFormError(data, e.result));
  205. } else {
  206. asyncSMessage(e.message);
  207. }
  208. });
  209. }
  210. });
  211. }
  212. removeNo(noId) {
  213. let { questionNos } = this.state;
  214. questionNos = questionNos.filter(row => row.id !== noId);
  215. Question.delNo({ id: noId }).then(() => {
  216. this.setState({ questionNos });
  217. });
  218. }
  219. changeType(type) {
  220. const { getFieldValue, setFieldsValue, getFieldDecorator } = this.props.form;
  221. const number = getFieldValue('content.number');
  222. // const keys = [];
  223. this.uuid = [];
  224. for (let index = 0; index < Number(number); index += 1) {
  225. this.uuid[index] = 0;
  226. switch (type) {
  227. case 'double':
  228. getFieldDecorator(`content.questions[${index}].direction`);
  229. setFieldsValue({ [`content.questions[${index}].direction`]: 'landscape' });
  230. break;
  231. default:
  232. }
  233. }
  234. }
  235. removeQuestion(index, k) {
  236. const { form } = this.props;
  237. const keys = form.getFieldValue(`content.questions[${index}].keys`);
  238. if (keys.length === 1) {
  239. return;
  240. }
  241. form.setFieldsValue({
  242. [`content.questions[${index}].keys`]: keys.filter(key => key !== k),
  243. });
  244. }
  245. addQuestion(index) {
  246. const { form } = this.props;
  247. const keys = form.getFieldValue(`content.questions[${index}].keys`) || [];
  248. if (!this.uuid[index]) {
  249. this.uuid[index] = 1;
  250. } else {
  251. this.uuid[index] += 1;
  252. }
  253. const nextKeys = keys.concat(this.uuid[index]);
  254. form.setFieldsValue({
  255. [`content.questions[${index}].keys`]: nextKeys,
  256. });
  257. }
  258. orderQuestion(index, oldIndex, newIndex) {
  259. const { form } = this.props;
  260. const keys = form.getFieldValue(`content.questions[${index}].keys`) || [];
  261. const tmp = keys[oldIndex];
  262. keys[oldIndex] = keys[newIndex];
  263. keys[newIndex] = tmp;
  264. form.setFieldsValue({
  265. [`content.questions[${index}].keys`]: keys,
  266. });
  267. }
  268. changeQuestion(index, k, value) {
  269. const { form } = this.props;
  270. let answer = form.getFieldValue(`answer.questions[${index}].single`) || [];
  271. answer = answer.map(() => false);
  272. answer[k] = !!value;
  273. form.setFieldsValue({ [`answer.questions[${index}].single`]: answer });
  274. }
  275. autoChangeQuestion(index) {
  276. const { form } = this.props;
  277. const keys = form.getFieldValue(`content.questions[${index}].keys`) || [];
  278. const answer = form.getFieldValue(`answer.questions[${index}].single`) || [];
  279. if (answer.filter(row => row).length === 0) {
  280. this.changeQuestion(index, keys[0], true);
  281. }
  282. }
  283. changeDouble(index, k, o, value) {
  284. const { form } = this.props;
  285. const direction = form.getFieldValue(`content.questions[${index}].direction`);
  286. let answer = form.getFieldValue(`answer.questions[${index}].double`) || [];
  287. switch (direction) {
  288. case 'landscape':
  289. answer[k] = answer[k].map(() => false);
  290. if (o >= 0) {
  291. answer[k][o] = !!value;
  292. }
  293. break;
  294. case 'portrait':
  295. answer = answer.map((row) => { row[o] = false; return row; });
  296. if (o >= 0) {
  297. answer[k][o] = !!value;
  298. }
  299. break;
  300. default:
  301. }
  302. form.setFieldsValue({ [`answer.questions[${index}].double`]: answer });
  303. }
  304. autoChangeDouble(index) {
  305. const { form } = this.props;
  306. const direction = form.getFieldValue(`content.questions[${index}].direction`);
  307. const answer = form.getFieldValue(`answer.questions[${index}].double`) || [];
  308. const { length } = answer;
  309. switch (direction) {
  310. case 'landscape':
  311. answer.forEach((row, k) => {
  312. if (row.filter(r => r).length === 0) {
  313. this.changeDouble(index, k, 0, true);
  314. }
  315. });
  316. break;
  317. case 'portrait':
  318. for (let i = 0; i < length; i += 1) {
  319. let flag = 0;
  320. answer.forEach(row => {
  321. flag += row[i] ? 1 : 0;
  322. });
  323. if (!flag) {
  324. this.changeDouble(index, i, 0, true);
  325. }
  326. }
  327. break;
  328. default:
  329. }
  330. }
  331. submit() {
  332. const { form } = this.props;
  333. const fields = ['id', 'questionType', 'place', 'difficult', 'difficultScore', 'content', 'answer', 'stem', 'keyword', 'questionNoIds', 'officialContent', 'qxContent', 'associationContent'];
  334. form.validateFields(fields, (err) => {
  335. if (!err) {
  336. const data = form.getFieldsValue(fields);
  337. let handler;
  338. data.associationContent = this.state.associationContentQuestionNos.map(row => row.id);
  339. data.stem = data.stem || ''; // .replace(/<span\s*class=\"ql-formula\"<\/span>/, '')
  340. data.description = (data.stem || '').replace(/<[^>]+>/g, '').replace(/#select#/, '').replace(/#table#/, '').replace(/&nbsp;/, '');
  341. data.qxContent = data.qxContent || '';
  342. data.officialContent = data.officialContent || '';
  343. data.content = data.content || {};
  344. data.answer = data.answer || {};
  345. data.answer.questions = (data.answer.questions || []).map((row, index) => {
  346. if (row.single) row.single = row.single.filter((r, i) => data.content.questions[index].select[i]);
  347. if (row.double) row.double = row.double.filter((r, i) => data.content.questions[index].select[i]);
  348. return row;
  349. });
  350. data.content.questions = (data.content.questions || []).map(row => {
  351. delete row.keys;
  352. row.select = (row.select || []).filter(r => r);
  353. return row;
  354. });
  355. data.relationQuestion = this.state.relationQuestionNos.map(row => row.id);
  356. if (!data.id) {
  357. handler = Question.add(data);
  358. } else {
  359. handler = Question.edit(data);
  360. }
  361. handler.then((result) => {
  362. asyncSMessage('保存成功');
  363. if (data.id) {
  364. linkTo(`/subject/question/${data.id}`);
  365. } else {
  366. linkTo(`/subject/question/${result.id}`);
  367. }
  368. }).catch((e) => {
  369. if (e.result) form.setFields(formatFormError(data, e.result));
  370. });
  371. }
  372. });
  373. }
  374. searchStem() {
  375. const { form } = this.props;
  376. const content = (form.getFieldValue('stem') || '').replace(/<[^>]+>/g, '');
  377. const questionType = (form.getFieldValue('questionType') || '');
  378. Question.searchStem({ content, questionType })
  379. .then(result => {
  380. if (result.list.length > 0) {
  381. asyncGet(() => import('../../../components/SimilarQuestionNo'),
  382. { title: '找到可匹配题目', questionNos: result.list, modal: true },
  383. (questionNo) => {
  384. this.inited = false;
  385. linkTo(`/subject/question/${questionNo.questionId}`);
  386. return Promise.resolve();
  387. });
  388. } else {
  389. asyncSMessage('无可匹配题目', 'warn');
  390. }
  391. });
  392. }
  393. bindAssociationContent(associationContent) {
  394. generateSearch('associationContent', { mode: 'multiple' }, this, (search) => {
  395. return this.searchQuestion(search);
  396. }, (row) => {
  397. return {
  398. title: row.title,
  399. value: row.id,
  400. };
  401. }, associationContent, null);
  402. if (associationContent) this.listQuestion(associationContent, 'ids', 'associationContentQuestionNos');
  403. }
  404. bindRelationQuestion(relationQuestion) {
  405. generateSearch('relationQuestion', { mode: 'multiple' }, this, (search) => {
  406. return this.searchQuestion(search);
  407. }, (row) => {
  408. return {
  409. title: row.title,
  410. value: row.id,
  411. };
  412. }, relationQuestion, null);
  413. if (relationQuestion) this.listQuestion(relationQuestion, 'ids', 'relationQuestionNos');
  414. }
  415. listQuestion(values, field, targetField) {
  416. if (!values || values.length === 0) {
  417. this.setState({ [targetField]: [] });
  418. return;
  419. }
  420. this.setState({ [`${targetField}Loading`]: true });
  421. Question.listNo({ [field]: values }).then(result => {
  422. const map = getMap(result, 'id');
  423. const questionNos = values.map(row => map[row]).filter(row => row);
  424. this.setState({ [targetField]: questionNos, [`${targetField}Loading`]: false });
  425. });
  426. }
  427. searchQuestion(params) {
  428. return Question.searchNo(params);
  429. }
  430. renderBase() {
  431. const { getFieldDecorator } = this.props.form;
  432. return <Block flex>
  433. <h1>题干信息</h1>
  434. <Form>
  435. {getFieldDecorator('id')(<input hidden />)}
  436. {getFieldDecorator('stem', {
  437. })(
  438. <Editor modules={{
  439. toolbar: {
  440. container: [
  441. ['image', 'table', 'select'],
  442. [{ header: '1' }, { header: '2' }],
  443. ['bold', 'underline', 'blockquote'],
  444. [{ color: [] }, { background: [] }],
  445. [{ list: 'ordered' }, { list: 'bullet' }, { indent: '-1' }, { indent: '+1' }],
  446. ['formula'],
  447. ['clean'],
  448. ],
  449. handlers: {
  450. table: (quill) => {
  451. const range = quill.getSelection(true);
  452. quill.insertText(range.index, '#table#');
  453. },
  454. select: (quill) => {
  455. const range = quill.getSelection(true);
  456. quill.insertText(range.index, '#select#');
  457. },
  458. },
  459. },
  460. }} placeholder='请输入内容' onUpload={(file) => System.uploadImage(file)} />,
  461. )}
  462. <Button style={{ marginBottom: '10px', marginTop: '10px' }} onClick={() => {
  463. this.searchStem();
  464. }}>查询相似</Button>
  465. <Row>
  466. <Col span={12}>
  467. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='递进层次'>
  468. {getFieldDecorator('content.step', {
  469. normalize: (value, preValue) => {
  470. if (value === undefined || value === '' || value === null) return preValue;
  471. if (Math.abs(value - preValue) > 1) return preValue;
  472. return value;
  473. },
  474. })(
  475. <InputNumber defaultValue={0} min={1} max={10} placeholder='输入数量' />,
  476. )}
  477. </Form.Item>
  478. </Col>
  479. <Col span={12}>
  480. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='折叠表格'>
  481. <Col span={1}>行</Col>
  482. <Col span={9} offset={1}>
  483. {getFieldDecorator('content.table.row')(
  484. <InputNumber placeholder='行' defaultValue={0} precision={0} min={0} />,
  485. )}
  486. </Col>
  487. <Col span={1} offset={1}>列</Col>
  488. <Col span={9} offset={1}>
  489. {getFieldDecorator('content.table.col')(
  490. <InputNumber placeholder='列' defaultValue={0} precision={0} min={0} />,
  491. )}
  492. </Col>
  493. </Form.Item>
  494. </Col>
  495. </Row>
  496. {this.renderTable()}
  497. </Form>
  498. </Block>;
  499. }
  500. renderTable() {
  501. const { getFieldDecorator, getFieldValue } = this.props.form;
  502. const row = Number(getFieldValue('content.table.row'));
  503. const col = Number(getFieldValue('content.table.col'));
  504. const table = [];
  505. if (row === 0 || col === 0) return table;
  506. const span = 100 / col;
  507. const colums = [];
  508. for (let i = 0; i < col; i += 1) {
  509. colums.push(<div style={{ width: `${span}%` }} className='table-col'>{getFieldDecorator(`content.table.header[${i}]`)(<Input size='small' />)}</div>);
  510. }
  511. table.push(<Row style={{ width: '100%' }} className='table-header' gutter={10}>{colums}</Row>);
  512. for (let index = 0; index < row; index += 1) {
  513. const cols = [];
  514. for (let i = 0; i < col; i += 1) {
  515. cols.push(<div style={{ width: `${span}%` }} className='table-col'>{getFieldDecorator(`content.table.data[${index}][${i}]`)(<Input size='small' />)}</div>);
  516. }
  517. table.push(<Row style={{ width: '100%' }} gutter={10}>{cols}</Row>);
  518. }
  519. return table;
  520. }
  521. renderStep() {
  522. const { getFieldDecorator, getFieldValue } = this.props.form;
  523. const number = getFieldValue('content.step');
  524. const result = [];
  525. for (let index = 0; index < Number(number); index += 1) {
  526. result.push(<Block flex>
  527. <h1>递进层次 {index + 1}</h1>
  528. <Form>
  529. <Form.Item>
  530. {getFieldDecorator(`content.steps[${index}].title`, {
  531. rules: [
  532. { required: true, message: '请输入标题' },
  533. ],
  534. })(
  535. <Input placeholder='请输入标题' />,
  536. )}
  537. </Form.Item>
  538. <Form.Item>
  539. {getFieldDecorator(`content.steps[${index}].stem`, {
  540. })(
  541. <Editor placeholder='请输入内容' onUpload={(file) => System.uploadImage(file)} />,
  542. )}
  543. </Form.Item>
  544. </Form>
  545. </Block>);
  546. }
  547. return result;
  548. }
  549. renderIdentity() {
  550. const { questionNos = [] } = this.state;
  551. const { getFieldDecorator } = this.props.form;
  552. return <Block flex>
  553. <h1>题目身份</h1>
  554. <Form>
  555. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 17 }} label='请输入题目id'>
  556. {getFieldDecorator('questionNoIds', {
  557. rules: [{
  558. required: true, message: '添加关联题目ID',
  559. }],
  560. })(<input hidden />)}
  561. {questionNos.map((no, index) => {
  562. return <Tag key={index} closable onClose={() => {
  563. this.removeNo(no.id);
  564. }}>
  565. {no.title}
  566. </Tag>;
  567. })}
  568. <Row>
  569. <Col span={14}>
  570. <Form.Item>
  571. {getFieldDecorator('moduleStruct', {
  572. rules: [{
  573. required: true, message: '选择题目编号关系',
  574. }],
  575. })(<Cascader fieldNames={{ label: 'title', value: 'value', children: 'children' }} onClick={(value) => {
  576. this.setState({ moduleStruct: value });
  577. }} placeholder='选择' options={this.state.moduleStructData} />)}
  578. </Form.Item>
  579. </Col>
  580. <Col span={4} offset={1}>
  581. <Form.Item>
  582. {getFieldDecorator('questionNo', {
  583. rules: [{
  584. required: true, message: '输入编号',
  585. }],
  586. })(<InputNumber placeholder='题目id' min={1} onClick={(value) => {
  587. this.setState({ questionNo: value });
  588. }} />)}
  589. </Form.Item>
  590. </Col>
  591. <Col span={4} offset={1}>
  592. <Button size='small' onClick={() => {
  593. this.addNo();
  594. }}><Icon type='plus' /></Button>
  595. </Col>
  596. </Row>
  597. </Form.Item>
  598. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label={'关键词'}>
  599. {getFieldDecorator('keyword')(
  600. <Select mode='tags' maxTagCount={200} notFoundContent={null} placeholder='输入多个关键词, 逗号分隔' tokenSeparators={[',', ',']} />,
  601. )}
  602. </Form.Item>
  603. </Form>
  604. </Block>;
  605. }
  606. renderAttr() {
  607. const { getFieldDecorator, getFieldValue, setFieldsValue } = this.props.form;
  608. // const { questionNos = [] } = this.state;
  609. const isRc = getFieldValue('questionType') === 'rc';
  610. const rcType = getFieldValue('rcType') || false;
  611. return <Block flex>
  612. <h1>题目属性</h1>
  613. <Form>
  614. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='题型'>
  615. {getFieldDecorator('questionType', {
  616. rules: [
  617. { required: true, message: '请选择题型' },
  618. ],
  619. })(
  620. <Select select={QuestionType} placeholder='请选择题型' onChange={(v) => {
  621. this.refreshPlace(v);
  622. this.refreshDifficultScore(v, getFieldValue('difficult'));
  623. }} />,
  624. )}
  625. </Form.Item>
  626. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='考点'>
  627. {getFieldDecorator('place', {
  628. rules: [
  629. { required: true, message: '请选择考点' },
  630. ],
  631. })(
  632. <Select select={this.state.placeList} placeholder='请选择考点' />,
  633. )}
  634. </Form.Item>
  635. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='难度'>
  636. {getFieldDecorator('difficult', {
  637. rules: [
  638. { required: true, message: '请选择难度' },
  639. ],
  640. })(
  641. <Select select={QuestionDifficult} placeholder='请选择难度' onChange={(v) => {
  642. this.refreshDifficultScore(getFieldValue('questionType'), v);
  643. }} />,
  644. )}
  645. </Form.Item>
  646. {this.state.difficultScore && this.state.difficultScore.length > 0 && <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='难度分'>
  647. {getFieldDecorator('difficultScore', {
  648. rules: [
  649. { required: true, message: '请选择难度分' },
  650. ],
  651. })(
  652. <Select select={this.state.difficultScore} placeholder='请选择难度分' />,
  653. )}
  654. </Form.Item>}
  655. {/* 阅读题,并且只有一个id才能关联 */}
  656. {isRc && <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='阅读题模式' >
  657. {getFieldDecorator('rcType', {
  658. valuePropName: 'checked',
  659. })(
  660. <Switch checkedChildren='on' unCheckedChildren='off' />,
  661. )}
  662. </Form.Item>}
  663. {rcType && <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='关联题目'>
  664. {getFieldDecorator('relationQuestion', {
  665. rules: [{
  666. required: true, message: '请输入关联题目',
  667. }],
  668. })(
  669. <Select mode='multiple' maxTagCount={200} notFoundContent={null} placeholder='输入题目id, 逗号分隔' tokenSeparators={[',', ',']} {...this.state.relationQuestion} onChange={(values) => {
  670. this.listQuestion(values, 'ids', 'relationQuestionNos');
  671. // this.setState({ relationQuestion: values });
  672. }} />,
  673. )}
  674. <QuestionNoList type='inline' loading={this.state.relationQuestionNosLoading} questionNos={this.state.relationQuestionNos} onChange={(nos) => {
  675. getFieldDecorator('relationQuestion');
  676. setFieldsValue({ relationQuestion: nos.map(row => row.id) });
  677. this.setState({ relationQuestionNos: nos });
  678. }}
  679. render={(row, dragClass, close) => {
  680. return <Tag className={dragClass} closable onClose={() => {
  681. close();
  682. }}>
  683. {row.title}
  684. </Tag>;
  685. }}
  686. />
  687. </Form.Item>}
  688. </Form>
  689. </Block>;
  690. }
  691. renderStyle() {
  692. const { getFieldDecorator } = this.props.form;
  693. return <Block flex>
  694. <h1>题目样式</h1>
  695. <Form>
  696. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='选项类型'>
  697. {getFieldDecorator('content.type', {
  698. rules: [
  699. { required: true, message: '请选择类型' },
  700. ],
  701. })(
  702. <Select select={QuestionStyleType} placeholder='请选择类型' onChange={(type) => {
  703. this.changeType(type);
  704. }} />,
  705. )}
  706. </Form.Item>
  707. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='题目数量'>
  708. {getFieldDecorator('content.number', {
  709. normalize: (value, preValue) => {
  710. if (value === undefined || value === '' || value === null) return preValue;
  711. if (Math.abs(value - preValue) > 1) return preValue;
  712. return value;
  713. },
  714. })(
  715. <InputNumber defaultValue={1} min={1} max={10} placeholder='请输入数量' />,
  716. )}
  717. </Form.Item>
  718. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='排版方式'>
  719. {getFieldDecorator('content.typeset')(
  720. <Radio.Group defaultValue='one'>
  721. <Radio value='one'>单排</Radio>
  722. <Radio value='two'>双排</Radio>
  723. </Radio.Group>,
  724. )}
  725. </Form.Item>
  726. </Form>
  727. </Block>;
  728. }
  729. renderSelect() {
  730. const { getFieldDecorator, getFieldValue } = this.props.form;
  731. const number = getFieldValue('content.number');
  732. const type = getFieldValue('content.type');
  733. const result = [];
  734. let handler = null;
  735. switch (type) {
  736. case 'single':
  737. handler = (index) => this.renderSelectSingle(index);
  738. break;
  739. case 'double':
  740. handler = (index) => this.renderSelectDouble(index);
  741. break;
  742. case 'inline':
  743. handler = (index) => this.renderSelectInline(index);
  744. break;
  745. default:
  746. }
  747. for (let index = 0; index < Number(number); index += 1) {
  748. result.push(<Block flex className={type}>
  749. <h1>选项信息({QuestionStyleTypeMap[type]})</h1>
  750. <Form>
  751. {type !== 'inline' && (
  752. <Form.Item>
  753. {getFieldDecorator(`content.questions[${index}].description`, {})(
  754. <Editor placeholder='选项问题说明' />,
  755. )}
  756. </Form.Item>
  757. )}
  758. {handler(index)}
  759. </Form>
  760. </Block>);
  761. }
  762. return result;
  763. }
  764. renderSelectSingle(index) {
  765. const { getFieldDecorator, getFieldValue } = this.props.form;
  766. getFieldDecorator(`content.questions[${index}].keys`);
  767. const keys = getFieldValue(`content.questions[${index}].keys`) || [];
  768. return [
  769. <DragList
  770. loading={false}
  771. dataSource={keys || []}
  772. handle={'.icon'}
  773. onMove={(oldIndex, newIndex) => {
  774. this.orderQuestion(index, oldIndex, newIndex);
  775. }}
  776. renderItem={(k) => (
  777. <List.Item actions={[<Icon type='bars' className='icon' />]}>
  778. <Row key={k} style={{ width: '100%' }}>
  779. <Col span={1}>
  780. {getFieldDecorator(`answer.questions[${index}].single[${k}]`, {
  781. valuePropName: 'checked',
  782. })(
  783. <Checkbox onChange={(e) => {
  784. this.changeQuestion(index, k, e.target.checked);
  785. }} />,
  786. )}
  787. </Col>
  788. <Col span={23}>
  789. <Form.Item
  790. key={k}
  791. hidden
  792. >
  793. {getFieldDecorator(`content.questions[${index}].select[${k}]`, {
  794. rules: [{
  795. required: true,
  796. whitespace: true,
  797. message: '请填写选项信息',
  798. }],
  799. })(
  800. <Input />,
  801. )}
  802. {keys.length > 1 ? (
  803. <Icon
  804. type='minus-circle-o'
  805. disabled={keys.length === 1}
  806. onClick={() => {
  807. this.removeQuestion(index, k);
  808. // this.autoChangeQuestion(index);
  809. }}
  810. />
  811. ) : null}
  812. </Form.Item>
  813. </Col>
  814. </Row>
  815. </List.Item>
  816. )}
  817. />,
  818. <Form.Item>
  819. <Button type='dashed' onClick={() => {
  820. this.addQuestion(index);
  821. // this.autoChangeQuestion(index);
  822. }} >
  823. <Icon type='plus' /> 新增
  824. </Button>
  825. </Form.Item>,
  826. ];
  827. }
  828. renderSelectDouble(index) {
  829. const { getFieldDecorator, getFieldValue } = this.props.form;
  830. getFieldDecorator(`content.questions[${index}].keys`);
  831. const keys = getFieldValue(`content.questions[${index}].keys`) || [];
  832. return [
  833. <Form.Item className='no-validate' labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='单选方向'>
  834. {getFieldDecorator(`content.questions[${index}].direction`)(
  835. <Select select={QuestionRadioDirection} placeholder='请选择方向' onChange={(value) => {
  836. keys.forEach((k) => this.changeDouble(index, k, -1, value));
  837. }} />,
  838. )}
  839. </Form.Item>,
  840. <List.Item actions={[<Icon type='bars' style={{ display: 'none' }} className='icon' />]}><Row style={{ width: '100%' }}>
  841. <Col span={4}>
  842. {getFieldDecorator(`content.questions[${index}].first`)(
  843. <Input placeholder='选项一' />,
  844. )}
  845. </Col>
  846. <Col span={4} offset={1}>
  847. {getFieldDecorator(`content.questions[${index}].second`)(
  848. <Input placeholder='选项二' />,
  849. )}
  850. </Col>
  851. </Row></List.Item>,
  852. <DragList
  853. loading={false}
  854. dataSource={keys.map(key => {
  855. return {
  856. key,
  857. };
  858. }) || []}
  859. rowKey={'key'}
  860. handle={'.icon'}
  861. onMove={(oldIndex, newIndex) => {
  862. this.orderQuestion(index, oldIndex, newIndex);
  863. }}
  864. renderItem={({ key }) => {
  865. return <List.Item actions={[<Icon type='bars' className='icon' />]}>
  866. <Row style={{ width: '100%' }}>
  867. <Col span={4}>
  868. {getFieldDecorator(`answer.questions[${index}].double[${key}][0]`, {
  869. valuePropName: 'checked',
  870. })(
  871. <Checkbox onChange={(e) => {
  872. this.changeDouble(index, key, 0, e.target.checked);
  873. }} />,
  874. )}
  875. </Col>
  876. <Col span={4} offset={1}>
  877. {getFieldDecorator(`answer.questions[${index}].double[${key}][1]`, {
  878. valuePropName: 'checked',
  879. })(
  880. <Checkbox onChange={(e) => {
  881. this.changeDouble(index, key, 1, e.target.checked);
  882. }} />,
  883. )}
  884. </Col>
  885. <Col span={14} offset={1}>
  886. <Form.Item
  887. key={key}
  888. hidden
  889. >
  890. {getFieldDecorator(`content.questions[${index}].select[${key}]`, {
  891. rules: [{
  892. required: true,
  893. whitespace: true,
  894. message: '请填写选项信息',
  895. }],
  896. })(
  897. <Input />,
  898. )}
  899. {keys.length > 1 ? (
  900. <Icon
  901. type='minus-circle-o'
  902. disabled={keys.length === 1}
  903. onClick={() => this.removeQuestion(index, key)}
  904. />
  905. ) : null}
  906. </Form.Item>
  907. </Col>
  908. </Row>
  909. </List.Item>;
  910. }}
  911. />,
  912. <Form.Item>
  913. <Button type='dashed' onClick={() => {
  914. this.addQuestion(index);
  915. // this.autoChangeQuestion(index);
  916. }}>
  917. <Icon type='plus' /> 新增
  918. </Button>
  919. </Form.Item>,
  920. ];
  921. }
  922. renderSelectInline(index) {
  923. return this.renderSelectSingle(index);
  924. }
  925. renderOffical() {
  926. const { getFieldDecorator } = this.props.form;
  927. return <Block flex>
  928. <Form>
  929. <Form.Item label='官方解析'>
  930. {getFieldDecorator('officialContent', {
  931. })(
  932. <Editor placeholder='输入内容' onUpload={(file) => System.uploadImage(file)} />,
  933. )}
  934. </Form.Item>
  935. </Form>
  936. </Block>;
  937. }
  938. renderQX() {
  939. const { getFieldDecorator } = this.props.form;
  940. return <Block flex>
  941. <Form>
  942. <Form.Item label='千行解析'>
  943. {getFieldDecorator('qxContent', {
  944. })(
  945. <Editor placeholder='输入内容' onUpload={(file) => System.uploadImage(file)} />,
  946. )}
  947. </Form.Item>
  948. </Form>
  949. </Block>;
  950. }
  951. renderAssociation() {
  952. const { getFieldDecorator, setFieldsValue } = this.props.form;
  953. return <Block flex>
  954. <h1>题源联想</h1>
  955. <Form>
  956. <Form.Item>
  957. {getFieldDecorator('associationContent')(
  958. <Select mode='multiple' maxTagCount={200} notFoundContent={null} placeholder='输入题目id, 逗号分隔' tokenSeparators={[',', ',']} {...this.state.associationContent} onChange={(values) => {
  959. this.listQuestion(values, 'ids', 'associationContentQuestionNos');
  960. // this.setState({ associationContent: values });
  961. }} />,
  962. )}
  963. </Form.Item>
  964. <QuestionNoList loading={this.state.associationContentQuestionNosLoading} questionNos={this.state.associationContentQuestionNos} onChange={(nos) => {
  965. getFieldDecorator('associationContent');
  966. setFieldsValue({ associationContent: nos.map(row => row.id) });
  967. this.setState({ associationContentQuestionNos: nos });
  968. }} />
  969. </Form>
  970. </Block>;
  971. }
  972. renderTab() {
  973. return <Tabs activeKey='base' onChange={(tab) => {
  974. switch (tab) {
  975. case 'sentence':
  976. linkTo('/subject/sentence/question');
  977. break;
  978. case 'textbook':
  979. linkTo('/subject/textbook/question');
  980. break;
  981. default:
  982. }
  983. }}>
  984. <Tabs.TabPane key='base' tab='考试题型' />
  985. <Tabs.TabPane key='sentence' tab='长难句' />
  986. <Tabs.TabPane key='textbook' tab='数学机经' />
  987. </Tabs>;
  988. }
  989. renderView() {
  990. return <div flex >
  991. {this.renderTab()}
  992. {this.renderBase()}
  993. {this.renderStep()}
  994. {this.renderIdentity()}
  995. {this.renderAttr()}
  996. {this.renderStyle()}
  997. {this.renderSelect()}
  998. {this.renderOffical()}
  999. {this.renderQX()}
  1000. {this.renderAssociation()}
  1001. <Row type="flex" justify="center">
  1002. <Col>
  1003. <Button type="primary" onClick={() => {
  1004. this.submit();
  1005. }}>保存</Button>
  1006. </Col>
  1007. </Row>
  1008. </div>;
  1009. }
  1010. }