page.js 36 KB

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