page.js 36 KB

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