index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. import React, { Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import './index.less';
  4. import { Checkbox, Icon as AntDIcon } from 'antd';
  5. import Assets from '@src/components/Assets';
  6. import { formatSeconds, formatSecond, getMap } from '@src/services/Tools';
  7. import Icon from '../../../../components/Icon';
  8. import Button from '../../../../components/Button';
  9. import Navigation from '../../../../components/Navigation';
  10. import Answer from '../../../../components/Answer';
  11. import Calculator from '../../../../components/Calculator';
  12. import AnswerSelect from '../../../../components/AnswerSelect';
  13. import AnswerTable from '../../../../components/AnswerTable';
  14. import Editor from '../../../../components/Editor';
  15. import { QuestionType } from '../../../../../Constant';
  16. const QuestionTypeMap = getMap(QuestionType, 'value');
  17. export default class extends Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. showTime: true,
  22. showNo: true,
  23. showCalculator: false,
  24. disorder: false,
  25. order: [],
  26. step: 0,
  27. answer: {},
  28. modal: null,
  29. };
  30. }
  31. onChangeQuestion(index, value) {
  32. const { question } = this.props;
  33. const { content } = question;
  34. const { answer = {} } = this.state;
  35. const type = content.type === 'double' ? 'double' : 'single';
  36. if (!answer.questions) {
  37. answer.questions = content.questions.map(() => {
  38. return {};
  39. });
  40. }
  41. answer.questions[index] = { [type]: value };
  42. console.log(answer);
  43. this.setState({ answer });
  44. }
  45. onChangeAwa(value) {
  46. const { answer = {} } = this.state;
  47. answer.awa = value;
  48. this.setState({ answer });
  49. }
  50. showConfirm(title, desc, cb) {
  51. this.showModal('confirm', title, desc, cb);
  52. }
  53. showToast(title, desc, cb) {
  54. this.showModal('toast', title, desc, cb);
  55. }
  56. showModal(type, title, desc, cb) {
  57. this.setState({ modal: { type, title, desc, cb } });
  58. }
  59. checkAnswer() {
  60. const { question } = this.props;
  61. const { answer } = this.state;
  62. let result = null;
  63. if (question.questionType === 'awa' && !answer.awa) result = 'Please answer the question first.';
  64. if (result) return this.showToast(null, result);
  65. return true;
  66. }
  67. hideModal(b) {
  68. if (b) {
  69. const { modal = {} } = this.state;
  70. if (modal.cb) modal.cb();
  71. }
  72. this.setState({ modal: null });
  73. }
  74. formatStrem(text) {
  75. if (!text) return '';
  76. const { question = { content: {} } } = this.props;
  77. const { table = {}, questions = [] } = question.content;
  78. text = text.replace(/#select#/g, "<span class='#select#' />");
  79. text = text.replace(/#table#/g, "<span class='#table#' />");
  80. setTimeout(() => {
  81. const selectList = document.getElementsByClassName('#select#');
  82. const tableList = document.getElementsByClassName('#table#');
  83. for (let i = 0; i < selectList.length; i += 1) {
  84. if (!questions[i]) break;
  85. ReactDOM.render(
  86. <AnswerSelect list={questions[i].select} type={'single'} onChange={v => this.onChangeQuestion(i, v)} />,
  87. selectList[i],
  88. );
  89. }
  90. if (table.row && table.col && table.header) {
  91. const columns = table.header.map((title, index) => {
  92. return { title, key: index };
  93. });
  94. for (let i = 0; i < tableList.length; i += 1) {
  95. ReactDOM.render(<AnswerTable list={columns} columns={columns} data={table.data} />, tableList[i]);
  96. }
  97. }
  98. }, 1);
  99. return text;
  100. }
  101. next() {
  102. const { flow } = this.props;
  103. const { answer } = this.state;
  104. if (this.checkAnswer()) {
  105. flow.submit(answer).then(() => {
  106. flow.next();
  107. });
  108. }
  109. }
  110. render() {
  111. const { modal } = this.state;
  112. const { scene, paper } = this.props;
  113. let content = null;
  114. switch (scene) {
  115. case 'start':
  116. content = paper.paperModule === 'examination' ? this.renderExaminationStart() : this.renderExerciseStart();
  117. break;
  118. case 'relax':
  119. content = this.renderRelax();
  120. break;
  121. default:
  122. content = this.renderDetail();
  123. break;
  124. }
  125. return (
  126. <div id="paper-process-base">
  127. {content}
  128. {modal ? this.renderModal() : ''}
  129. </div>
  130. );
  131. }
  132. renderContent() {
  133. const { question = { content: {} } } = this.props;
  134. const { step } = this.state;
  135. const { steps = [] } = question.content;
  136. return (
  137. <div className="block block-content">
  138. {steps.length > 0 && (
  139. <Navigation
  140. theme="process"
  141. list={question.content.steps}
  142. active={step}
  143. onChange={v => this.setState({ step: v })}
  144. />
  145. )}
  146. <div
  147. className="text"
  148. dangerouslySetInnerHTML={{ __html: this.formatStrem(steps.length > 0 ? steps[step].stem : question.stem) }}
  149. />
  150. </div>
  151. );
  152. }
  153. renderAnswer() {
  154. const { question = { content: {} } } = this.props;
  155. const { questions = [], type } = question.content;
  156. if (type === 'inline') return '';
  157. return (
  158. <div className="block block-answer">
  159. {question.questionType === 'awa' && <Editor onChange={v => this.onChangeAwa(v)} />}
  160. {questions.map((item, index) => {
  161. return (
  162. <div>
  163. <div className="text m-b-2">{item.description}</div>
  164. <Answer
  165. list={item.select}
  166. type={type}
  167. first={item.first}
  168. second={item.second}
  169. direction={item.direction}
  170. onChange={v => this.onChangeQuestion(index, v)}
  171. />
  172. </div>
  173. );
  174. })}
  175. </div>
  176. );
  177. }
  178. renderDetail() {
  179. const { paper, userQuestion, question = { content: {} }, singleTime, stageTime, flow } = this.props;
  180. if (!userQuestion.id) return null;
  181. const { showCalculator, showTime, showNo } = this.state;
  182. const { typeset = 'one' } = question.content;
  183. return (
  184. <div className="layout">
  185. <div className="fixed">
  186. {QuestionTypeMap[question.questionType].long}
  187. {question.questionType === 'ir' && (
  188. <Assets
  189. className="calculator-icon"
  190. name="calculator_icon"
  191. onClick={() => this.setState({ showCalculator: !showCalculator })}
  192. />
  193. )}
  194. {/* <Assets className="collect-icon" name="collect_icon" onClick={() => {
  195. flow.toggleCollect();
  196. }} /> */}
  197. <div className="collect-icon">
  198. <Icon name="star" active={userQuestion.collect} onClick={() => flow.toggleCollect()} />
  199. </div>
  200. </div>
  201. <Calculator show={showCalculator} />
  202. <div className="layout-header">
  203. <div className="title">{paper.title}</div>
  204. <div className="right">
  205. <div
  206. className="block"
  207. onClick={() => {
  208. this.setState({ showTime: !showTime });
  209. }}
  210. >
  211. <Assets name="timeleft_icon" />
  212. {showTime && stageTime && `Time left ${formatSecond(stageTime)}`}
  213. {showTime && singleTime && `Time cost ${formatSecond(singleTime)}`}
  214. </div>
  215. <div
  216. className="block"
  217. onClick={() => {
  218. this.setState({ showNo: !showNo });
  219. }}
  220. >
  221. <Assets name="subjectnumber_icon" />
  222. {showNo && `${userQuestion.no} of ${paper.questionNumber}`}
  223. </div>
  224. </div>
  225. </div>
  226. <div className={'layout-body'}>
  227. <div className={typeset}>
  228. {this.renderContent()}
  229. {this.renderAnswer()}
  230. </div>
  231. </div>
  232. <div className="layout-footer">
  233. <div className="help">
  234. <Assets name="help_icon" />
  235. Help
  236. </div>
  237. <div className="full">
  238. <Assets name="fullscreen_icon" onClick={() => flow.toggleFullscreen()} />
  239. </div>
  240. <div className="next" onClick={() => this.next()}>
  241. Next
  242. <Assets name="next_icon" />
  243. </div>
  244. </div>
  245. </div>
  246. );
  247. }
  248. renderExaminationStart() {
  249. const { disorder } = this.state;
  250. const { paper, flow } = this.props;
  251. return (
  252. <div className="start">
  253. <div className="bg" />
  254. <div className="fixed-content">
  255. <div className="title">{paper.title}</div>
  256. <div className="desc">
  257. <div className="block">
  258. <div className="desc-title">
  259. <Assets name="subject_icon" />
  260. 题目总数
  261. </div>
  262. <div className="desc-info">{paper.questionNumer}</div>
  263. </div>
  264. <div className="block">
  265. <div className="desc-title">
  266. <Assets name="time_icon" />
  267. 建议用时
  268. </div>
  269. <div className="desc-info">{formatSeconds(paper.time)}</div>
  270. </div>
  271. </div>
  272. <div className="tip">
  273. <Checkbox className="m-r-1" checked={disorder} onChange={() => this.setState({ disorder: !disorder })} />
  274. 题目选项乱序显示
  275. </div>
  276. <div className="submit">
  277. <Button size="lager" radius onClick={() => flow.start({ disorder })}>
  278. 开始练习
  279. </Button>
  280. </div>
  281. </div>
  282. </div>
  283. );
  284. }
  285. renderExerciseStart() {
  286. const { paper, userQuestion, singleTime, stageTime, flow } = this.props;
  287. const { showTime, showNo } = this.state;
  288. return (
  289. <div className="layout">
  290. <div className="layout-header">
  291. <div className="title">{paper.title}</div>
  292. <div className="right">
  293. <div
  294. className="block"
  295. onClick={() => {
  296. this.setState({ showTime: !showTime });
  297. }}
  298. >
  299. <Assets name="timeleft_icon" />
  300. {showTime && stageTime && `Time left ${formatSecond(stageTime)}`}
  301. {showTime && singleTime && `Time cost ${formatSecond(singleTime)}`}
  302. </div>
  303. <div
  304. className="block"
  305. onClick={() => {
  306. this.setState({ showNo: !showNo });
  307. }}
  308. >
  309. <Assets name="subjectnumber_icon" />
  310. {showNo && `${userQuestion.no} of ${paper.questionNumber}`}
  311. </div>
  312. </div>
  313. </div>
  314. <div className={'layout-body'}>{this.renderExerciseStartCAT()}</div>
  315. <div className="layout-footer">
  316. <div className="help">
  317. <Assets name="help_icon" />
  318. Help
  319. </div>
  320. <div className="full">
  321. <Assets name="fullscreen_icon" onClick={() => flow.toggleFullscreen()} />
  322. </div>
  323. <div className="next" onClick={() => this.next()}>
  324. Next
  325. <Assets name="next_icon" />
  326. </div>
  327. </div>
  328. </div>
  329. );
  330. }
  331. renderExerciseStartDefault() {
  332. return (
  333. <div className="exercise-start default">
  334. <div className="title">Section Ordering</div>
  335. <div className="desc">Select the order in which the exam sections are to be administered.</div>
  336. <div className="desc tip">
  337. NOTE: You have 1 minutes to make your selection. If you do not make your selection within 1 minutes, the first
  338. option listed will be selected and you will view the exam in the following order: Analytical Writing
  339. Assessment, Integrated Reasoning, Quantitative, Verbal.
  340. </div>
  341. <div className="desc">
  342. Once you select your section order, you must view ALL questions in each section, in the order you have
  343. selected, before moving on to the next section. You will NOT be able to return to this screen.
  344. </div>
  345. <div className="block-list">
  346. <div className="block-item">
  347. <div className="block-title">
  348. <div className="block-title-border">
  349. <AntDIcon type="check" />
  350. <span>ARQV</span>
  351. </div>
  352. </div>
  353. <div className="block-text">1.Analytical Writing Analysis </div>
  354. <div className="block-text">2.Integrated Reasoning </div>
  355. <div className="block-text">3.Quantitative </div>
  356. <div className="block-text">4.Verbal </div>
  357. </div>
  358. <div className="block-item">
  359. <div className="block-title">
  360. <div className="block-title-border">
  361. <AntDIcon type="check" />
  362. <span>VQRA </span>
  363. </div>
  364. </div>
  365. <div className="block-text">1.Verbal </div>
  366. <div className="block-text">2.Quantitative </div>
  367. <div className="block-text">3.Integrated Reasoning </div>
  368. <div className="block-text">4.Analytical Writing Analysis </div>
  369. </div>
  370. <div className="block-item">
  371. <div className="block-title">
  372. <div className="block-title-border">
  373. <AntDIcon type="check" />
  374. <span>QVRA</span>
  375. </div>
  376. </div>
  377. <div className="block-text">1.Quantitative</div>
  378. <div className="block-text">2.Verbal </div>
  379. <div className="block-text">3.Integrated Reasoning </div>
  380. <div className="block-text">4.Analytical Writing Analysis </div>
  381. </div>
  382. </div>
  383. <div className="bottom">
  384. <div className="text">
  385. <Checkbox checked /> 题目选项乱序显示
  386. </div>
  387. <div className="text">
  388. Click{' '}
  389. <div className="next" onClick={() => this.next()}>
  390. Next
  391. <Assets name="next_icon" />
  392. </div>{' '}
  393. button to start the exam. You will begin the GMAT exam on the next screen.{' '}
  394. </div>
  395. </div>
  396. </div>
  397. );
  398. }
  399. renderExerciseStartCAT() {
  400. return (
  401. <div className="exercise-start cat">
  402. <div className="title">Section Ordering</div>
  403. <div className="block-list">
  404. <div className="block-item">
  405. <div className="block-item-body active">
  406. <AntDIcon type="check" style={{ color: '#fff' }} />
  407. <div className="block-text">
  408. <Checkbox checked /> Analytical Writing Analysis{' '}
  409. </div>
  410. <div className="block-text">
  411. <Checkbox checked /> Integrated Reasoning{' '}
  412. </div>
  413. <div className="block-text">
  414. <Checkbox checked /> Quantitative{' '}
  415. </div>
  416. <div className="block-text">
  417. <Checkbox checked /> Verbal{' '}
  418. </div>
  419. </div>
  420. </div>
  421. <div className="block-item">
  422. <div className="block-item-body">
  423. <div className="block-text">
  424. <Checkbox /> Quantitative
  425. </div>
  426. <div className="block-text">
  427. <Checkbox /> Verbal{' '}
  428. </div>
  429. <div className="block-text">
  430. <Checkbox /> Integrated Reasoning{' '}
  431. </div>
  432. <div className="block-text">
  433. <Checkbox /> Analytical Writing Analysis{' '}
  434. </div>
  435. </div>
  436. </div>
  437. <div className="block-item">
  438. <div className="block-item-body">
  439. <div className="block-text">
  440. <Checkbox /> Verbal{' '}
  441. </div>
  442. <div className="block-text">
  443. <Checkbox /> Quantitative{' '}
  444. </div>
  445. <div className="block-text">
  446. <Checkbox /> Integrated Reasoning{' '}
  447. </div>
  448. <div className="block-text">
  449. <Checkbox /> Analytical Writing Analysis{' '}
  450. </div>
  451. </div>
  452. </div>
  453. </div>
  454. <div className="bottom">
  455. <div className="text">
  456. <Checkbox checked /> 题目选项乱序显示
  457. </div>
  458. <div className="text">
  459. Click{' '}
  460. <div className="next" onClick={() => this.next()}>
  461. Next
  462. <Assets name="next_icon" />
  463. </div>{' '}
  464. button to start the exam. You will begin the GMAT exam on the next screen.{' '}
  465. </div>
  466. <div className="text tip">*实战可选择考试顺序但无法选择考试内容。</div>
  467. </div>
  468. </div>
  469. );
  470. }
  471. renderRelax() {
  472. const { paper, userQuestion, singleTime, stageTime, flow } = this.props;
  473. const { showTime, showNo } = this.state;
  474. return (
  475. <div className="layout">
  476. <div className="layout-header">
  477. <div className="title">{paper.title}</div>
  478. <div className="right">
  479. <div
  480. className="block"
  481. onClick={() => {
  482. this.setState({ showTime: !showTime });
  483. }}
  484. >
  485. <Assets name="timeleft_icon" />
  486. {showTime && stageTime && `Time left ${formatSecond(stageTime)}`}
  487. {showTime && singleTime && `Time cost ${formatSecond(singleTime)}`}
  488. </div>
  489. <div
  490. className="block"
  491. onClick={() => {
  492. this.setState({ showNo: !showNo });
  493. }}
  494. >
  495. <Assets name="subjectnumber_icon" />
  496. {showNo && `${userQuestion.no} of ${paper.questionNumber}`}
  497. </div>
  498. </div>
  499. </div>
  500. <div className={'layout-body'}>
  501. <div className="relax">
  502. <div className="title">
  503. Optional Break <Icon name="question" />
  504. </div>
  505. <div className="time">
  506. <div className="block">0</div>
  507. <div className="block">1</div>
  508. <div className="div">:</div>
  509. <div className="block">2</div>
  510. <div className="block">3</div>
  511. </div>
  512. </div>
  513. </div>
  514. <div className="layout-footer">
  515. <div className="help">
  516. <Assets name="help_icon" />
  517. Help
  518. </div>
  519. <div className="full">
  520. <Assets name="fullscreen_icon" onClick={() => flow.toggleFullscreen()} />
  521. </div>
  522. <div className="next" onClick={() => this.next()}>
  523. Next
  524. <Assets name="next_icon" />
  525. </div>
  526. </div>
  527. </div>
  528. );
  529. }
  530. renderModal() {
  531. const { modal } = this.state;
  532. return (
  533. <div className="modal">
  534. <div className="mask" />
  535. <div className="body">
  536. <div className="title">{modal.title}</div>
  537. <div className="desc">{modal.desc}</div>
  538. {modal.type === 'confirm' ? (
  539. <div className="btn-list">
  540. <div className="btn" onClick={() => this.hideModal(true)}>
  541. <span className="t-d-l">Y</span>es
  542. </div>
  543. <div className="btn" onClick={() => this.hideModal(false)}>
  544. <span className="t-d-l">N</span>o
  545. </div>
  546. </div>
  547. ) : (
  548. <div className="btn-list">
  549. <div className="btn" onClick={() => this.hideModal(true)}>
  550. <span className="t-d-l">O</span>k
  551. </div>
  552. </div>
  553. )}
  554. </div>
  555. </div>
  556. );
  557. }
  558. }