page.js 28 KB

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