page.js 37 KB

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