1
0

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. 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.no = `${nodeString}-${data.no}`;
  133. data.questionId = data.id || 0;
  134. delete data.id;
  135. data.no = data.questionNo;
  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.questions[${index}].answer`) || [];
  204. answer = answer.map(() => !value);
  205. answer[k] = !!value;
  206. form.setFieldsValue({ [`content.questions[${index}].answer`]: 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.questions[${index}].answer`) || [];
  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.questions[${index}].answer`]: answer });
  228. }
  229. submit() {
  230. const { form } = this.props;
  231. const fields = ['type', 'place', 'difficult', 'content', '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.answer = row.answer.filter(r => r);
  240. row.select = row.select.filter(r => r);
  241. return row;
  242. });
  243. if (data.id) {
  244. handler = Question.add(data);
  245. } else {
  246. handler = Question.edit(data);
  247. }
  248. handler.then(() => {
  249. asyncSMessage('保存成功');
  250. }).catch((e) => {
  251. if (e.result) form.setFields(formatFormError(data, e.result));
  252. });
  253. }
  254. });
  255. }
  256. searchStem() {
  257. const { form } = this.props;
  258. const content = form.getFieldValue('stem').replace(/<[^>]+>/g, '');
  259. Question.searchStem({ content })
  260. .then(result => {
  261. if (result.list.length > 0) {
  262. asyncGet(() => import('../../../components/SimilarQuestionNo'),
  263. { title: '找到可匹配题目', questionNos: result.list, modal: true },
  264. (questionNo) => {
  265. this.inited = false;
  266. linkTo(`/subject/question/${questionNo.questionId}`);
  267. return Promise.resolve();
  268. });
  269. } else {
  270. asyncSMessage('无可匹配题目');
  271. }
  272. });
  273. }
  274. renderBase() {
  275. const { getFieldDecorator } = this.props.form;
  276. return <Block flex>
  277. <h1>题干信息</h1>
  278. <Form>
  279. {getFieldDecorator('id')(<input hidden />)}
  280. {getFieldDecorator('stem', {
  281. })(
  282. <Editor modules={{
  283. toolbar: {
  284. container: [
  285. ['image', 'table', 'select'],
  286. [{ header: '1' }, { header: '2' }],
  287. ['bold', 'underline', 'blockquote'],
  288. [{ list: 'ordered' }, { list: 'bullet' }, { indent: '-1' }, { indent: '+1' }],
  289. ],
  290. handlers: {
  291. table: (quill) => {
  292. const range = quill.getSelection(true);
  293. quill.insertText(range.index, '#table#');
  294. },
  295. select: (quill) => {
  296. const range = quill.getSelection(true);
  297. quill.insertText(range.index, '#select#');
  298. },
  299. },
  300. },
  301. }} placeholder='请输入内容' onUpload={(file) => System.uploadImage(file)} />,
  302. )}
  303. <Button style={{ marginBottom: '10px', marginTop: '10px' }} onClick={() => {
  304. this.searchStem();
  305. }}>查询相似</Button>
  306. <Row>
  307. <Col span={12}>
  308. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='递进层次'>
  309. {getFieldDecorator('content.step', {
  310. normalize: (value, preValue) => {
  311. if (value === undefined || value === '' || value === null) return preValue;
  312. if (Math.abs(value - preValue) > 1) return preValue;
  313. return value;
  314. },
  315. })(
  316. <InputNumber defaultValue={0} min={1} max={10} placeholder='输入数量' />,
  317. )}
  318. </Form.Item>
  319. </Col>
  320. <Col span={12}>
  321. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='折叠表格'>
  322. <Col span={1}>行</Col>
  323. <Col span={9} offset={1}>
  324. {getFieldDecorator('content.table.row')(
  325. <InputNumber placeholder='行' defaultValue={0} precision={0} min={0} />,
  326. )}
  327. </Col>
  328. <Col span={1} offset={1}>列</Col>
  329. <Col span={9} offset={1}>
  330. {getFieldDecorator('content.table.col')(
  331. <InputNumber placeholder='列' defaultValue={0} precision={0} min={0} />,
  332. )}
  333. </Col>
  334. </Form.Item>
  335. </Col>
  336. </Row>
  337. {this.renderTable()}
  338. </Form>
  339. </Block>;
  340. }
  341. renderTable() {
  342. const { getFieldDecorator, getFieldValue } = this.props.form;
  343. const row = Number(getFieldValue('content.table.row'));
  344. const col = Number(getFieldValue('content.table.col'));
  345. const table = [];
  346. if (row === 0 || col === 0) return table;
  347. const span = 100 / col;
  348. const colums = [];
  349. for (let i = 0; i < col; i += 1) {
  350. colums.push(<div style={{ width: `${span}%` }} className='table-col'>{getFieldDecorator(`content.table.header[${i}]`)(<Input size='small' />)}</div>);
  351. }
  352. table.push(<Row style={{ width: '100%' }} className='table-header' gutter={10}>{colums}</Row>);
  353. for (let index = 0; index < row; index += 1) {
  354. const cols = [];
  355. for (let i = 0; i < col; i += 1) {
  356. cols.push(<div style={{ width: `${span}%` }} className='table-col'>{getFieldDecorator(`content.table.data[${index}][${i}]`)(<Input size='small' />)}</div>);
  357. }
  358. table.push(<Row style={{ width: '100%' }} gutter={10}>{cols}</Row>);
  359. }
  360. return table;
  361. }
  362. renderStep() {
  363. const { getFieldDecorator, getFieldValue } = this.props.form;
  364. const number = getFieldValue('content.step');
  365. const result = [];
  366. for (let index = 0; index < Number(number); index += 1) {
  367. result.push(<Block flex>
  368. <h1>递进层次 {index + 1}</h1>
  369. <Form>
  370. <Form.Item>
  371. {getFieldDecorator(`content.steps[${index}].title`, {
  372. rules: [
  373. { required: true, message: '请输入标题' },
  374. ],
  375. })(
  376. <Input placeholder='请输入标题' />,
  377. )}
  378. </Form.Item>
  379. <Form.Item>
  380. {getFieldDecorator(`content.steps[${index}].stem`, {
  381. })(
  382. <Editor placeholder='请输入内容' />,
  383. )}
  384. </Form.Item>
  385. </Form>
  386. </Block>);
  387. }
  388. return result;
  389. }
  390. renderIdentity() {
  391. const { questionNos = [] } = this.state;
  392. const { getFieldDecorator } = this.props.form;
  393. return <Block flex>
  394. <h1>题目身份</h1>
  395. <Form>
  396. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 17 }} label='请输入题目id'>
  397. {getFieldDecorator('questionNoIds', {
  398. rules: [{
  399. required: true, message: '添加关联题目ID',
  400. }],
  401. })(<input hidden />)}
  402. {questionNos.map((no, index) => {
  403. return <Tag key={index} closable onClose={() => {
  404. this.removeNo(no.id);
  405. }}>
  406. {no.no}
  407. </Tag>;
  408. })}
  409. <Row>
  410. <Col span={14}>
  411. <Form.Item>
  412. {getFieldDecorator('moduleStruct', {
  413. rules: [{
  414. required: true, message: '选择题目编号关系',
  415. }],
  416. })(<Cascader fieldNames={{ label: 'title', value: 'value', children: 'children' }} onClick={(value) => {
  417. this.setState({ moduleStruct: value });
  418. }} placeholder='选择' options={this.state.moduleStructData} />)}
  419. </Form.Item>
  420. </Col>
  421. <Col span={4} offset={1}>
  422. <Form.Item>
  423. {getFieldDecorator('questionNo', {
  424. rules: [{
  425. required: true, message: '输入编号',
  426. }],
  427. })(<Input placeholder='题目id' onClick={(value) => {
  428. this.setState({ questionNo: value });
  429. }} />)}
  430. </Form.Item>
  431. </Col>
  432. <Col span={4} offset={1}>
  433. <Button size='small' onClick={() => {
  434. this.addNo();
  435. }}><Icon type='plus' /></Button>
  436. </Col>
  437. </Row>
  438. </Form.Item>
  439. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label={'关键词'}>
  440. {getFieldDecorator('keyword')(
  441. <Select mode='tags' maxTagCount={200} notFoundContent={null} placeholder='输入多个关键词, 逗号分隔' tokenSeparators={[',', ',']} />,
  442. )}
  443. </Form.Item>
  444. </Form>
  445. </Block>;
  446. }
  447. renderAttr() {
  448. const { getFieldDecorator } = this.props.form;
  449. return <Block flex>
  450. <h1>题目属性</h1>
  451. <Form>
  452. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='题型'>
  453. {getFieldDecorator('type', {
  454. rules: [
  455. { required: true, message: '请选择题型' },
  456. ],
  457. })(
  458. <Select select={QuestionType} placeholder='请选择题型' onChange={(v) => {
  459. this.refreshPlace(v);
  460. }} />,
  461. )}
  462. </Form.Item>
  463. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='考点'>
  464. {getFieldDecorator('place', {
  465. rules: [
  466. { required: true, message: '请选择考点' },
  467. ],
  468. })(
  469. <Select select={this.placeList} placeholder='请选择考点' onChange={(v) => {
  470. this.refreshPart(v);
  471. }} />,
  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.order(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(`content.questions[${index}].answer[${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(`content.questions[${index}].answer[${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(`content.questions[${index}].answer[${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. }