page.js 28 KB

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