page.js 36 KB

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