common.js 4.87 KB
Newer Older
zhanghaozhe committed
1
import React from "react"
wangshuo committed
2
function format(content) {
zhanghaozhe committed
3 4 5
  if (content) {
    if (content.includes("<img")) {
      content = content.replace(/<img/g, "<img style='width: 100%'")
wangshuo committed
6
    }
zhanghaozhe committed
7 8 9 10 11 12 13
    content = content.replace(/&lt;/g, "<")
    content = content.replace(/&gt;/g, ">")
    content = content.replace(/&amp;gt;/g, "")
    content = content.replace(/&quot;/g, '"')
    content = content.replace(/&amp;nbsp;/g, "")
  }
  return content
wangshuo committed
14 15 16
}

function Header(props) {
zhanghaozhe committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  return (
    <div className="camp-test-header layout-flex-between">
      <div>
        <i
          onClick={props.close}
          className={"iconfont iconiconfront-77 icon-close"}
        />
      </div>
      <div className="layout-flex-center camp-test-time">
        <i className="icon icon-clock" />
        <span>{props.time}</span>
      </div>
      <div
        onClick={props.showCardEve}
        className={`icon icon-order ${props.showCard ? "no_height" : ""}`}
      />
    </div>
  )
wangshuo committed
35 36 37
}

function CampTitle(props) {
zhanghaozhe committed
38 39 40 41 42 43
  return (
    <div className="layout-flex-between camp-test-title">
      <div className="qtitle">{`课后练习:${props.qtitle}`}</div>
      <div className="qnumber">{`${props.questionIndex}/${props.examList.length}`}</div>
    </div>
  )
wangshuo committed
44 45 46
}

function TestItem(props) {
zhanghaozhe committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  let { questionIndex, currentExam, currentQuestionOption } = props
  return (
    <div className="test-item-container">
      <div
        className="ques item-title"
        dangerouslySetInnerHTML={{
          __html: `${questionIndex}.${format(currentExam.ques)}`,
        }}
      />
      <ul>
        {currentExam.options &&
          currentExam.options.map((item, index) => {
            return (
              <li
                key={index}
                onClick={() => props.checkOption(item)}
                className={`
                                        ${
                                          currentQuestionOption === item.opt_id
                                            ? "option_checked"
                                            : ""
                                        }
                                        ${
                                          (currentExam.user_answer === 0 ||
                                            currentExam.user_answer) &&
                                          currentExam.user_answer ===
                                            item.opt_id
                                            ? "user_check"
                                            : ""
                                        }
                                        ${
                                          (currentExam.user_answer === 0 ||
                                            currentExam.user_answer) &&
                                          currentExam.answer_id === item.opt_id
                                            ? "right_check"
                                            : ""
                                        }
wangshuo committed
84
                                    `}
zhanghaozhe committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
              >
                <span className="letter">
                  {String.fromCharCode(Number(index) + 65)}
                </span>
                <span
                  className="des"
                  dangerouslySetInnerHTML={{ __html: format(item.des) }}
                />
              </li>
            )
          })}
      </ul>
      {props.children}
    </div>
  )
wangshuo committed
100 101 102
}

function ChangeQuestion(props) {
zhanghaozhe committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  return (
    <div className={"layout-flex-around change_question_container"}>
      <div
        onClick={props.preQuestion}
        className={`change_button pre_question ${
          props.questionIndex === 1 ? "first_question" : ""
        }`}
      >
        上一题
      </div>
      <div
        onClick={props.nextQuestion}
        className={`change_button next_question`}
      >
        下一题
      </div>
    </div>
  )
wangshuo committed
121 122 123
}

function Resolve(props) {
zhanghaozhe committed
124 125 126
  let { currentExam } = props
  let Test = currentExam.compare === 0 ? "错误" : "正确"
  let UserIndex, rightIndex
zhanghaozhe committed
127
  currentExam.options.forEach((item, index) => {
zhanghaozhe committed
128 129
    if (currentExam.answer_id === item.opt_id) {
      rightIndex = index
wangshuo committed
130
    }
zhanghaozhe committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    if (
      currentExam.user_answer !== 0 &&
      currentExam.user_answer === item.opt_id
    ) {
      UserIndex = (
        <span>{`您的答案是${String.fromCharCode(Number(index) + 65)},`}</span>
      )
    }
  })
  if (currentExam.user_answer === 0) {
    UserIndex = <span>{`您的答案是空,`}</span>
  }
  return (
    <div className={"test-resolve"}>
      <div className={"isRight"}>
        <span>{`正确答案是${String.fromCharCode(
          Number(rightIndex) + 65
        )},`}</span>
        {UserIndex}
        <span>{`回答${Test}。`}</span>
      </div>
      <p>解析</p>
      <div
        className={"resolve-content"}
        dangerouslySetInnerHTML={{ __html: `${format(currentExam.analysis)}` }}
      />
    </div>
  )
wangshuo committed
159 160
}

zhanghaozhe committed
161
export { Header, CampTitle, TestItem, ChangeQuestion, Resolve }