page.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  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. [{ color: ['red', 'green', 'blue', 'orange', 'violet', '#d0d1d2', 'black'] }],
  403. [{ list: 'ordered' }, { list: 'bullet' }, { indent: '-1' }, { indent: '+1' }],
  404. ],
  405. handlers: {
  406. table: (quill) => {
  407. const range = quill.getSelection(true);
  408. quill.insertText(range.index, '#table#');
  409. },
  410. select: (quill) => {
  411. const range = quill.getSelection(true);
  412. quill.insertText(range.index, '#select#');
  413. },
  414. },
  415. },
  416. }} placeholder='请输入内容' onUpload={(file) => System.uploadImage(file)} />,
  417. )}
  418. <Button style={{ marginBottom: '10px', marginTop: '10px' }} onClick={() => {
  419. this.searchStem();
  420. }}>查询相似</Button>
  421. <Row>
  422. <Col span={12}>
  423. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='递进层次'>
  424. {getFieldDecorator('content.step', {
  425. normalize: (value, preValue) => {
  426. if (value === undefined || value === '' || value === null) return preValue;
  427. if (Math.abs(value - preValue) > 1) return preValue;
  428. return value;
  429. },
  430. })(
  431. <InputNumber defaultValue={0} min={1} max={10} placeholder='输入数量' />,
  432. )}
  433. </Form.Item>
  434. </Col>
  435. <Col span={12}>
  436. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='折叠表格'>
  437. <Col span={1}>行</Col>
  438. <Col span={9} offset={1}>
  439. {getFieldDecorator('content.table.row')(
  440. <InputNumber placeholder='行' defaultValue={0} precision={0} min={0} />,
  441. )}
  442. </Col>
  443. <Col span={1} offset={1}>列</Col>
  444. <Col span={9} offset={1}>
  445. {getFieldDecorator('content.table.col')(
  446. <InputNumber placeholder='列' defaultValue={0} precision={0} min={0} />,
  447. )}
  448. </Col>
  449. </Form.Item>
  450. </Col>
  451. </Row>
  452. {this.renderTable()}
  453. </Form>
  454. </Block>;
  455. }
  456. renderTable() {
  457. const { getFieldDecorator, getFieldValue } = this.props.form;
  458. const row = Number(getFieldValue('content.table.row'));
  459. const col = Number(getFieldValue('content.table.col'));
  460. const table = [];
  461. if (row === 0 || col === 0) return table;
  462. const span = 100 / col;
  463. const colums = [];
  464. for (let i = 0; i < col; i += 1) {
  465. colums.push(<div style={{ width: `${span}%` }} className='table-col'>{getFieldDecorator(`content.table.header[${i}]`)(<Input size='small' />)}</div>);
  466. }
  467. table.push(<Row style={{ width: '100%' }} className='table-header' gutter={10}>{colums}</Row>);
  468. for (let index = 0; index < row; index += 1) {
  469. const cols = [];
  470. for (let i = 0; i < col; i += 1) {
  471. cols.push(<div style={{ width: `${span}%` }} className='table-col'>{getFieldDecorator(`content.table.data[${index}][${i}]`)(<Input size='small' />)}</div>);
  472. }
  473. table.push(<Row style={{ width: '100%' }} gutter={10}>{cols}</Row>);
  474. }
  475. return table;
  476. }
  477. renderStep() {
  478. const { getFieldDecorator, getFieldValue } = this.props.form;
  479. const number = getFieldValue('content.step');
  480. const result = [];
  481. for (let index = 0; index < Number(number); index += 1) {
  482. result.push(<Block flex>
  483. <h1>递进层次 {index + 1}</h1>
  484. <Form>
  485. <Form.Item>
  486. {getFieldDecorator(`content.steps[${index}].title`, {
  487. rules: [
  488. { required: true, message: '请输入标题' },
  489. ],
  490. })(
  491. <Input placeholder='请输入标题' />,
  492. )}
  493. </Form.Item>
  494. <Form.Item>
  495. {getFieldDecorator(`content.steps[${index}].stem`, {
  496. })(
  497. <Editor placeholder='请输入内容' />,
  498. )}
  499. </Form.Item>
  500. </Form>
  501. </Block>);
  502. }
  503. return result;
  504. }
  505. renderIdentity() {
  506. const { questionNos = [] } = this.state;
  507. const { getFieldDecorator } = this.props.form;
  508. return <Block flex>
  509. <h1>题目身份</h1>
  510. <Form>
  511. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 17 }} label='请输入题目id'>
  512. {getFieldDecorator('questionNoIds', {
  513. rules: [{
  514. required: true, message: '添加关联题目ID',
  515. }],
  516. })(<input hidden />)}
  517. {questionNos.map((no, index) => {
  518. return <Tag key={index} closable onClose={() => {
  519. this.removeNo(no.id);
  520. }}>
  521. {no.title}
  522. </Tag>;
  523. })}
  524. <Row>
  525. <Col span={14}>
  526. <Form.Item>
  527. {getFieldDecorator('moduleStruct', {
  528. rules: [{
  529. required: true, message: '选择题目编号关系',
  530. }],
  531. })(<Cascader fieldNames={{ label: 'title', value: 'value', children: 'children' }} onClick={(value) => {
  532. this.setState({ moduleStruct: value });
  533. }} placeholder='选择' options={this.state.moduleStructData} />)}
  534. </Form.Item>
  535. </Col>
  536. <Col span={4} offset={1}>
  537. <Form.Item>
  538. {getFieldDecorator('questionNo', {
  539. rules: [{
  540. required: true, message: '输入编号',
  541. }],
  542. })(<InputNumber placeholder='题目id' onClick={(value) => {
  543. this.setState({ questionNo: value });
  544. }} />)}
  545. </Form.Item>
  546. </Col>
  547. <Col span={4} offset={1}>
  548. <Button size='small' onClick={() => {
  549. this.addNo();
  550. }}><Icon type='plus' /></Button>
  551. </Col>
  552. </Row>
  553. </Form.Item>
  554. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label={'关键词'}>
  555. {getFieldDecorator('keyword')(
  556. <Select mode='tags' maxTagCount={200} notFoundContent={null} placeholder='输入多个关键词, 逗号分隔' tokenSeparators={[',', ',']} />,
  557. )}
  558. </Form.Item>
  559. </Form>
  560. </Block>;
  561. }
  562. renderAttr() {
  563. const { getFieldDecorator, getFieldValue, setFieldsValue } = this.props.form;
  564. // const { questionNos = [] } = this.state;
  565. const isRc = getFieldValue('questionType') === 'rc';
  566. const rcType = getFieldValue('rcType') || false;
  567. return <Block flex>
  568. <h1>题目属性</h1>
  569. <Form>
  570. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='题型'>
  571. {getFieldDecorator('questionType', {
  572. rules: [
  573. { required: true, message: '请选择题型' },
  574. ],
  575. })(
  576. <Select select={QuestionType} placeholder='请选择题型' onChange={(v) => {
  577. this.refreshPlace(v);
  578. this.refreshDifficultScore(v, getFieldValue('difficult'));
  579. }} />,
  580. )}
  581. </Form.Item>
  582. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='考点'>
  583. {getFieldDecorator('place', {
  584. rules: [
  585. { required: true, message: '请选择考点' },
  586. ],
  587. })(
  588. <Select select={this.state.placeList} placeholder='请选择考点' />,
  589. )}
  590. </Form.Item>
  591. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='难度'>
  592. {getFieldDecorator('difficult', {
  593. rules: [
  594. { required: true, message: '请选择难度' },
  595. ],
  596. })(
  597. <Select select={QuestionDifficult} placeholder='请选择难度' onChange={(v) => {
  598. this.refreshDifficultScore(getFieldValue('questionType'), v);
  599. }} />,
  600. )}
  601. </Form.Item>
  602. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='难度分'>
  603. {getFieldDecorator('difficultScore', {
  604. rules: [
  605. { required: true, message: '请选择难度分' },
  606. ],
  607. })(
  608. <Select select={this.state.difficultScore} placeholder='请选择难度分' />,
  609. )}
  610. </Form.Item>
  611. {/* 阅读题,并且只有一个id才能关联 */}
  612. {isRc && <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='阅读题模式' >
  613. {getFieldDecorator('rcType', {
  614. valuePropName: 'checked',
  615. })(
  616. <Switch checkedChildren='on' unCheckedChildren='off' />,
  617. )}
  618. </Form.Item>}
  619. {rcType && <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='关联题目'>
  620. {getFieldDecorator('relationQuestion', {
  621. rules: [{
  622. required: true, message: '请输入关联题目',
  623. }],
  624. })(
  625. <Select mode='multiple' maxTagCount={200} notFoundContent={null} placeholder='输入题目id, 逗号分隔' tokenSeparators={[',', ',']} {...this.state.relationQuestion} onChange={(values) => {
  626. this.listQuestion(values, 'ids', 'relationQuestionNos');
  627. // this.setState({ relationQuestion: values });
  628. }} />,
  629. )}
  630. <QuestionNoList type='inline' loading={this.state.relationQuestionNosLoading} questionNos={this.state.relationQuestionNos} onChange={(nos) => {
  631. getFieldDecorator('relationQuestion');
  632. setFieldsValue({ relationQuestion: nos.map(row => row.id) });
  633. this.setState({ relationQuestionNos: nos });
  634. }}
  635. render={(row, dragClass, close) => {
  636. return <Tag className={dragClass} closable onClose={() => {
  637. close();
  638. }}>
  639. {row.title}
  640. </Tag>;
  641. }}
  642. />
  643. </Form.Item>}
  644. </Form>
  645. </Block>;
  646. }
  647. renderStyle() {
  648. const { getFieldDecorator } = this.props.form;
  649. return <Block flex>
  650. <h1>题目样式</h1>
  651. <Form>
  652. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='选项类型'>
  653. {getFieldDecorator('content.type', {
  654. rules: [
  655. { required: true, message: '请选择类型' },
  656. ],
  657. })(
  658. <Select select={QuestionStyleType} placeholder='请选择类型' onChange={(type) => {
  659. this.changeType(type);
  660. }} />,
  661. )}
  662. </Form.Item>
  663. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='题目数量'>
  664. {getFieldDecorator('content.number', {
  665. normalize: (value, preValue) => {
  666. if (value === undefined || value === '' || value === null) return preValue;
  667. if (Math.abs(value - preValue) > 1) return preValue;
  668. return value;
  669. },
  670. })(
  671. <InputNumber defaultValue={1} min={1} max={10} placeholder='请输入数量' />,
  672. )}
  673. </Form.Item>
  674. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='排版方式'>
  675. {getFieldDecorator('content.typeset')(
  676. <Radio.Group defaultValue='one'>
  677. <Radio value='one'>单排</Radio>
  678. <Radio value='two'>双排</Radio>
  679. </Radio.Group>,
  680. )}
  681. </Form.Item>
  682. </Form>
  683. </Block>;
  684. }
  685. renderSelect() {
  686. const { getFieldDecorator, getFieldValue } = this.props.form;
  687. const number = getFieldValue('content.number');
  688. const type = getFieldValue('content.type');
  689. const result = [];
  690. let handler = null;
  691. switch (type) {
  692. case 'single':
  693. handler = (index) => this.renderSelectSingle(index);
  694. break;
  695. case 'double':
  696. handler = (index) => this.renderSelectDouble(index);
  697. break;
  698. case 'inline':
  699. handler = (index) => this.renderSelectInline(index);
  700. break;
  701. default:
  702. }
  703. for (let index = 0; index < Number(number); index += 1) {
  704. result.push(<Block flex className={type}>
  705. <h1>选项信息({QuestionStyleTypeMap[type]})</h1>
  706. <Form>
  707. {type !== 'inline' && (
  708. <Form.Item>
  709. {getFieldDecorator(`content.questions[${index}].description`, {
  710. })(
  711. <Editor placeholder='选项问题说明' />,
  712. )}
  713. </Form.Item>
  714. )}
  715. {handler(index)}
  716. </Form>
  717. </Block>);
  718. }
  719. return result;
  720. }
  721. renderSelectSingle(index) {
  722. const { getFieldDecorator, getFieldValue } = this.props.form;
  723. getFieldDecorator(`content.questions[${index}].keys`);
  724. const keys = getFieldValue(`content.questions[${index}].keys`) || [];
  725. return [
  726. <DragList
  727. loading={false}
  728. dataSource={keys || []}
  729. handle={'.icon'}
  730. onMove={(oldIndex, newIndex) => {
  731. this.orderQuestion(index, oldIndex, newIndex);
  732. }}
  733. renderItem={(k) => (
  734. <List.Item actions={[<Icon type='bars' className='icon' />]}>
  735. <Row key={k} style={{ width: '100%' }}>
  736. <Col span={1}>
  737. {getFieldDecorator(`answer.questions[${index}].single[${k}]`, {
  738. valuePropName: 'checked',
  739. })(
  740. <Checkbox onChange={(e) => {
  741. this.changeQuestion(index, k, e.target.checked);
  742. }} />,
  743. )}
  744. </Col>
  745. <Col span={23}>
  746. <Form.Item
  747. key={k}
  748. hidden
  749. >
  750. {getFieldDecorator(`content.questions[${index}].select[${k}]`, {
  751. rules: [{
  752. required: true,
  753. whitespace: true,
  754. message: '请填写选项信息',
  755. }],
  756. })(
  757. <Input />,
  758. )}
  759. {keys.length > 1 ? (
  760. <Icon
  761. type='minus-circle-o'
  762. disabled={keys.length === 1}
  763. onClick={() => this.removeQuestion(index, k)}
  764. />
  765. ) : null}
  766. </Form.Item>
  767. </Col>
  768. </Row>
  769. </List.Item>
  770. )}
  771. />,
  772. <Form.Item>
  773. <Button type='dashed' onClick={() => this.addQuestion(index)} >
  774. <Icon type='plus' /> 新增
  775. </Button>
  776. </Form.Item>,
  777. ];
  778. }
  779. renderSelectDouble(index) {
  780. const { getFieldDecorator, getFieldValue } = this.props.form;
  781. getFieldDecorator(`content.questions[${index}].keys`);
  782. const keys = getFieldValue(`content.questions[${index}].keys`) || [];
  783. return [
  784. <Form.Item className='no-validate' labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='单选方向'>
  785. {getFieldDecorator(`content.questions[${index}].direction`)(
  786. <Select select={QuestionRadioDirection} placeholder='请选择方向' onChange={(value) => {
  787. keys.forEach((k) => this.changeDouble(index, k, -1, value));
  788. }} />,
  789. )}
  790. </Form.Item>,
  791. <List.Item actions={[<Icon type='bars' style={{ display: 'none' }} className='icon' />]}><Row style={{ width: '100%' }}>
  792. <Col span={4}>
  793. {getFieldDecorator(`content.questions[${index}].first`)(
  794. <Input placeholder='选项一' />,
  795. )}
  796. </Col>
  797. <Col span={4} offset={1}>
  798. {getFieldDecorator(`content.questions[${index}].second`)(
  799. <Input placeholder='选项二' />,
  800. )}
  801. </Col>
  802. </Row></List.Item>,
  803. <DragList
  804. loading={false}
  805. dataSource={keys.map(key => {
  806. return {
  807. key,
  808. };
  809. }) || []}
  810. rowKey={'key'}
  811. handle={'.icon'}
  812. onMove={(oldIndex, newIndex) => {
  813. this.orderQuestion(index, oldIndex, newIndex);
  814. }}
  815. renderItem={({ key }) => {
  816. return <List.Item actions={[<Icon type='bars' className='icon' />]}>
  817. <Row style={{ width: '100%' }}>
  818. <Col span={4}>
  819. {getFieldDecorator(`answer.questions[${index}].double[${key}][0]`, {
  820. valuePropName: 'checked',
  821. })(
  822. <Checkbox onChange={(e) => {
  823. this.changeDouble(index, key, 0, e.target.checked);
  824. }} />,
  825. )}
  826. </Col>
  827. <Col span={4} offset={1}>
  828. {getFieldDecorator(`answer.questions[${index}].double[${key}][1]`, {
  829. valuePropName: 'checked',
  830. })(
  831. <Checkbox onChange={(e) => {
  832. this.changeDouble(index, key, 1, e.target.checked);
  833. }} />,
  834. )}
  835. </Col>
  836. <Col span={14} offset={1}>
  837. <Form.Item
  838. key={key}
  839. hidden
  840. >
  841. {getFieldDecorator(`content.questions[${index}].select[${key}]`, {
  842. rules: [{
  843. required: true,
  844. whitespace: true,
  845. message: '请填写选项信息',
  846. }],
  847. })(
  848. <Input />,
  849. )}
  850. {keys.length > 1 ? (
  851. <Icon
  852. type='minus-circle-o'
  853. disabled={keys.length === 1}
  854. onClick={() => this.removeQuestion(index, key)}
  855. />
  856. ) : null}
  857. </Form.Item>
  858. </Col>
  859. </Row>
  860. </List.Item>;
  861. }}
  862. />,
  863. <Form.Item>
  864. <Button type='dashed' onClick={() => this.addQuestion(index)} >
  865. <Icon type='plus' /> 新增
  866. </Button>
  867. </Form.Item>,
  868. ];
  869. }
  870. renderSelectInline(index) {
  871. return this.renderSelectSingle(index);
  872. }
  873. renderOffical() {
  874. const { getFieldDecorator } = this.props.form;
  875. return <Block flex>
  876. <Form>
  877. <Form.Item label='官方解析'>
  878. {getFieldDecorator('officialContent', {
  879. })(
  880. <Editor placeholder='输入内容' />,
  881. )}
  882. </Form.Item>
  883. </Form>
  884. </Block>;
  885. }
  886. renderQX() {
  887. const { getFieldDecorator } = this.props.form;
  888. return <Block flex>
  889. <Form>
  890. <Form.Item label='千行解析'>
  891. {getFieldDecorator('qxContent', {
  892. })(
  893. <Editor placeholder='输入内容' />,
  894. )}
  895. </Form.Item>
  896. </Form>
  897. </Block>;
  898. }
  899. renderAssociation() {
  900. const { getFieldDecorator, setFieldsValue } = this.props.form;
  901. return <Block flex>
  902. <h1>题源联想</h1>
  903. <Form>
  904. <Form.Item>
  905. {getFieldDecorator('associationContent')(
  906. <Select mode='multiple' maxTagCount={200} notFoundContent={null} placeholder='输入题目id, 逗号分隔' tokenSeparators={[',', ',']} {...this.state.associationContent} onChange={(values) => {
  907. this.listQuestion(values, 'ids', 'associationContentQuestionNos');
  908. // this.setState({ associationContent: values });
  909. }} />,
  910. )}
  911. </Form.Item>
  912. <QuestionNoList loading={this.state.associationContentQuestionNosLoading} questionNos={this.state.associationContentQuestionNos} onChange={(nos) => {
  913. getFieldDecorator('associationContent');
  914. setFieldsValue({ associationContent: nos.map(row => row.id) });
  915. this.setState({ associationContentQuestionNos: nos });
  916. }} />
  917. </Form>
  918. </Block>;
  919. }
  920. renderTab() {
  921. return <Tabs activeKey='base' onChange={(tab) => {
  922. switch (tab) {
  923. case 'sentence':
  924. linkTo('/subject/sentence/question');
  925. break;
  926. case 'textbook':
  927. linkTo('/subject/textbook/question');
  928. break;
  929. default:
  930. }
  931. }}>
  932. <Tabs.TabPane key='base' tab='考试题型' />
  933. <Tabs.TabPane key='sentence' tab='长难句' />
  934. <Tabs.TabPane key='textbook' tab='数学机经' />
  935. </Tabs>;
  936. }
  937. renderView() {
  938. return <div flex >
  939. {this.renderTab()}
  940. {this.renderBase()}
  941. {this.renderStep()}
  942. {this.renderIdentity()}
  943. {this.renderAttr()}
  944. {this.renderStyle()}
  945. {this.renderSelect()}
  946. {this.renderOffical()}
  947. {this.renderQX()}
  948. {this.renderAssociation()}
  949. <Row type="flex" justify="center">
  950. <Col>
  951. <Button type="primary" onClick={() => {
  952. this.submit();
  953. }}>保存</Button>
  954. </Col>
  955. </Row>
  956. </div>;
  957. }
  958. }