page.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { sortListWithOrder } from '@src/services/Tools';
  5. import { AskTarget } from '../../../../Constant';
  6. import { Question } from '../../../stores/question';
  7. import Detail from './detail';
  8. export default class extends Page {
  9. initState() {
  10. return {
  11. step: 0,
  12. hideAnalysis: true,
  13. analysisTab: 'official',
  14. showAnswer: false,
  15. noteField: AskTarget[0].key,
  16. showIds: false,
  17. // question: {
  18. // content: {
  19. // typeset: 'one',
  20. // },
  21. // // questionType: 'awa',
  22. // answer: {
  23. // subject: [[{ text: 'like', uuid: 'hKyz' }]],
  24. // options: ['parallel'],
  25. // },
  26. // stem: "<p><span uuid='kBJe'>I</span> <span uuid='hKyz'>like</span> <span uuid='fQXh'>book</span></p>",
  27. // },
  28. // userQuestion: {
  29. // userAnswer: {
  30. // subject: [{ text: 'I', uuid: 'kBJe' }],
  31. // options: ['compare'],
  32. // },
  33. // no: 2,
  34. // },
  35. // paper: {
  36. // title: '长难句练习',
  37. // questionNumber: 20,
  38. // },
  39. // report: {
  40. // paperModule: 'sentence',
  41. // },
  42. };
  43. }
  44. initData() {
  45. const { id } = this.params;
  46. const { search } = this.state;
  47. Question.getDetailById(id).then(userQuestion => {
  48. const { question, questionNos, paper, note, report, setting, questionStatus } = userQuestion;
  49. paper.paperModule = 'examination';
  50. let { questionNo } = userQuestion;
  51. if (!questionNo) ([questionNo] = questionNos);
  52. if (!question.answer) question.answer = { questions: [] };
  53. if (!question.answerDistributed) question.answerDistributed = { questions: [] };
  54. if (!userQuestion.userAnswer) userQuestion.userAnswer = { questions: [] };
  55. if ((report.setting || {}).disorder) {
  56. const { content } = question;
  57. // 还原做题顺序
  58. content.questions.forEach((q, i) => {
  59. q.select = sortListWithOrder(q.select, setting.questions[i]);
  60. });
  61. question.answer.questions.forEach((q, i) => {
  62. Object.keys(q).forEach((k) => {
  63. if (q[k]) q[k] = sortListWithOrder(q[k], setting.questions[i]);
  64. });
  65. });
  66. question.answerDistributed.questions.forEach((q, i) => {
  67. Object.keys(q).forEach((k) => {
  68. if (q[k]) q[k] = sortListWithOrder(q[k], setting.questions[i]);
  69. });
  70. });
  71. userQuestion.userAnswer.questions.forEach((q, i) => {
  72. Object.keys(q).forEach((k) => {
  73. if (q[k]) q[k] = sortListWithOrder(q[k], setting.questions[i]);
  74. });
  75. });
  76. }
  77. // 只显示单个提问
  78. if (search.askId) {
  79. const askId = Number(search.askId);
  80. userQuestion.asks = (userQuestion.asks || []).filter(row => row.askId === askId);
  81. }
  82. this.setState({ userQuestion, question, questionNo, note, paper, questionNos, questionStatus });
  83. });
  84. }
  85. renderView() {
  86. return (
  87. <Detail {...this.state} detail flow={this} />
  88. );
  89. }
  90. }