page.js 28 KB

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