page.js 36 KB

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