page.js 33 KB

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