page.js 37 KB

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