page.js 33 KB

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