page.js 35 KB

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