page.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. let { questionNo } = userQuestion;
  50. if (!questionNo) ([questionNo] = questionNos);
  51. if (!question.answer) question.answer = { questions: [] };
  52. if (!question.answerDistributed) question.answerDistributed = { questions: [] };
  53. if (!userQuestion.userAnswer) userQuestion.userAnswer = { questions: [] };
  54. if ((report.setting || {}).disorder) {
  55. const { content } = question;
  56. // 还原做题顺序
  57. content.questions.forEach((q, i) => {
  58. q.select = sortListWithOrder(q.select, setting.questions[i]);
  59. });
  60. question.answer.questions.forEach((q, i) => {
  61. Object.keys(q).forEach((k) => {
  62. if (q[k]) q[k] = sortListWithOrder(q[k], setting.questions[i]);
  63. });
  64. });
  65. question.answerDistributed.questions.forEach((q, i) => {
  66. Object.keys(q).forEach((k) => {
  67. if (q[k]) q[k] = sortListWithOrder(q[k], setting.questions[i]);
  68. });
  69. });
  70. userQuestion.userAnswer.questions.forEach((q, i) => {
  71. Object.keys(q).forEach((k) => {
  72. if (q[k]) q[k] = sortListWithOrder(q[k], setting.questions[i]);
  73. });
  74. });
  75. }
  76. // 只显示单个提问
  77. if (search.askId) {
  78. const askId = Number(search.askId);
  79. userQuestion.asks = (userQuestion.asks || []).filter(row => row.askId === askId);
  80. }
  81. this.setState({ userQuestion, question, questionNo, note, paper, report, questionNos, questionStatus });
  82. });
  83. }
  84. renderView() {
  85. return (
  86. <Detail {...this.state} detail flow={this} />
  87. );
  88. }
  89. }