Administrator
2022-05-09 c7735db135f9c3c99224d8b5d2157926efde0977
src/views/startexam/index.vue
@@ -104,8 +104,8 @@
                        type="success"
                        @click="submitExam"
                        :disabled="subjectIndex != 60"
                        >完成考试 {{ time }}</el-button
                      >
                        >完成考试 {{ time }}
                      </el-button>
                    </div>
                  </div>
                </div>
@@ -164,7 +164,7 @@
  messageSuccess,
  messageFail,
  messageWarn,
  isNotEmpty,
  isNotEmpty
} from "@/util/util";
import Tinymce from "@/components/Tinymce";
import Choices from "@/components/Subjects/Choices";
@@ -184,7 +184,7 @@
    Choices,
    MultipleChoices,
    PracticalOperation,
    Judgement,
    Judgement
    // ShortAnswer,
  },
  data() {
@@ -203,7 +203,7 @@
        examRecordId: undefined,
        subjectId: undefined,
        userId: undefined,
        type: 0,
        type: 0
      },
      subject: {},
      answer: "",
@@ -230,7 +230,7 @@
        remark: "全国计算机统考练习题10道",
        newRecord: false,
        newRecord: false
      },
      firstFlag: true,
      times: ["30", "00"],
@@ -238,29 +238,36 @@
      timeOTiv: null,
      timesIT: true,
      timesITValue: 0,
      first: true,
      first: true
    };
  },
  computed: {
    ...mapState({
      userInfo: (state) => state.user.userInfo,
      scoreId: (state) =>
      userInfo: state => state.user.userInfo,
      scoreId: state =>
        state.exam.scoreId
          ? state.exam.scoreId
          : window.localStorage.getItem("scoreId"),
          : window.localStorage.getItem("scoreId")
    }),
    time() {
      var d = [+this.times[0], +this.times[1]];
    },
    }
  },
  created() {
    if (window.name == "") {
      // console.log("首次被加载");
      window.name = "first"; // 在首次进入页面时我们可以给window.name设置一个固定值
      this.first = true;
    } else if (window.name == "first") {
      // console.log("页面被刷新");
    var useInfo = this.$store.state.exam.examUserData;
    if (useInfo.isExam == 3) {
      window.name = "first";
      this.first = false;
    } else {
      if (window.name == "") {
        // console.log("首次被加载");
        window.name = "first"; // 在首次进入页面时我们可以给window.name设置一个固定值
        this.first = true;
      } else if (window.name == "first") {
        // console.log("页面被刷新");
        this.first = false;
      }
    }
    const examInfo = this.$route.params.id;
@@ -282,19 +289,24 @@
      // this.exam.totalScore = this.$route.query.totalScore
      // this.exam.status = this.$route.query.examStatus
      // this.exam.remark = this.$route.query.remark
      this.validateExamTime();
    }
  },
  methods: {
    countDownS_cb: function () {
    countDownS_cb: function() {
      // console.log(12456);
      messageSuccess(this, "考试开始");
      this.startTime = this.getCurrentTimes();
    },
    countDownE_cb: function() {
      messageWarn(this, "考试结束");
      //   this.disableSubmit = true;
      // this.submitExam("over");
    },
    bottonControl(time) {
      //倒计时循环
      let times = time * 60;
      var setTime = function (time) {
      var setTime = function(time) {
        let a, b, d;
        a = parseInt(time / 60);
        b = time - a * 60;
@@ -302,35 +314,36 @@
        return d;
      };
      if (this.timeOTiv == null) {
        this.timeOTiv = setInterval((res) => {
        this.timeOTiv = setInterval(res => {
          times--;
          this.timesITValue = setTime(times);
        }, 1000);
      } else {
        clearTimeout(this.timeOTiv);
        this.timeOTiv = null;
        this.timeOTiv = setInterval((res) => {
        this.timeOTiv = setInterval(res => {
          times--;
          this.timesITValue = setTime(times);
        }, 1000);
      }
      //倒计时定时
      if (this.timeOut == null) {
        this.timeOut = setTimeout((res) => {
        this.timeOut = setTimeout(res => {
          this.timesIT = false;
          this.timesITValue--;
        }, time * 3600);
      } else {
        clearTimeout(this.timeOut);
        this.timeOut = null;
        this.timeOut = setTimeout((res) => {
        this.timeOut = setTimeout(res => {
          this.timesIT = false;
        }, time * 3600);
      }
    },
    validateExamTime() {
      getCurrentTime()
        .then((response) => {
        .then(response => {
          // console.log(response, 7777);
          const currentTime = moment(response.data.data);
          if (currentTime.isAfter(this.exam.endTime)) {
            messageWarn(this, "考试已结束");
@@ -371,7 +384,7 @@
      //   this.endTime = current + 60 * 60 * 1000;
      // }
      if (!this.first) {
        getSubjectRefresh(scoreId).then((obj) => {
        getSubjectRefresh(scoreId).then(obj => {
          const objs = obj.data.data;
          // console.log(objs, "objobjobjobjobjobj");
          const subjectData = objs.examSubjectChoicesVOSList;
@@ -388,7 +401,7 @@
                score: subjectData[i].score,
                color: "#fff",
                fontColor: "#000",
                title: subjectData[i].subjectName,
                title: subjectData[i].subjectName
              });
            }
@@ -428,7 +441,7 @@
                    for (var k = 0; k < ans.length; k++) {
                      anw.push({
                        key: k + 1,
                        value: ans[k],
                        value: ans[k]
                      });
                    }
                    this.subjectIds[i].answer = anw;
@@ -442,7 +455,8 @@
            }
            //适应时间
            const datyTime = objs.examScore.examTime;
            var duibiTime = function (newTime, oldTime) {
            // console.log(objs, "datyTimedatyTimedatyTime");
            var duibiTime = function(newTime, oldTime) {
              var newYear = newTime.split(" ")[0],
                newDat = newTime.split(" ")[1],
                oldYear = oldTime.split(" ")[0],
@@ -453,12 +467,12 @@
                let newD = {
                  s: +newDat.split(":")[0],
                  f: +newDat.split(":")[1],
                  m: +newDat.split(":")[2],
                  m: +newDat.split(":")[2]
                };
                let oldD = {
                  s: +oldDat.split(":")[0],
                  f: +oldDat.split(":")[1],
                  m: +oldDat.split(":")[2],
                  m: +oldDat.split(":")[2]
                };
                if (newD.s - oldD.s > 1) {
                  return false;
@@ -476,7 +490,6 @@
              // return false;
            };
            var listTime = duibiTime(currentTime._i, datyTime);
            // console.log(listTime, "listTimelistTimelistTime");
            const current = currentTime.valueOf();
            this.currentTime = current;
            this.startTime = current;
@@ -499,7 +512,7 @@
      // 获取题目ID列表
      // console.log("subjectResponsesubjectResponsesubjectResponse");
      getSubjectIds(scoreId)
        .then((subjectResponse) => {
        .then(subjectResponse => {
          const subjectData = subjectResponse.data.data;
          // console.log(
          //   subjectResponse,
@@ -517,7 +530,7 @@
                answer: "",
                score: subjectData[i].score,
                color: "#fff",
                fontColor: "#000",
                fontColor: "#000"
              });
            }
@@ -529,9 +542,9 @@
            this.updateSubjectIndex();
            // 获取当前题目信息
            getSubjectResultInfo({
              id: this.subjectIds[0].everyID,
              id: this.subjectIds[0].everyID
            })
              .then((response) => {
              .then(response => {
                if (isNotEmpty(response.data.data)) {
                  response.data.data.answer = "";
                  this.setSubjectInfo(response.data.data);
@@ -546,11 +559,7 @@
          messageFail(this, "开始考试失败!4646549888*8*");
        });
    },
    countDownE_cb: function () {
      messageWarn(this, "考试结束");
      //   this.disableSubmit = true;
      this.submitExam("over");
    },
    last() {
      for (let i = 0; i < this.subjectIds.length; i++) {
        if (this.subjectIds[i].everyID == this.query.subjectId) {
@@ -583,7 +592,7 @@
          if (this.getAnswer() == "") {
            this.$message({
              message: "请选择答案",
              type: "warning",
              type: "warning"
            });
            return;
          }
@@ -606,7 +615,7 @@
            if (!goShiCao) {
              this.$message({
                message: "实操题目请选择完整顺序!",
                type: "warning",
                type: "warning"
              });
              return;
            }
@@ -646,7 +655,7 @@
      var str = "";
      if (Array.isArray(answerData)) {
        answerData.forEach((item) => {
        answerData.forEach(item => {
          str += item.value + ",";
        });
@@ -659,10 +668,10 @@
        id: nextSubjectId,
        preSubJectId: this.query.subjectId,
        preResult: answerData,
        scoreId: this.scoreId,
        scoreId: this.scoreId
      };
      getSubjectResultInfo(data)
        .then((response) => {
        .then(response => {
          if (response.data.data !== null) {
            // 保存成功后更新答题卡状态
            const subject = response.data.data;
@@ -694,17 +703,20 @@
            }
            this.setSubjectInfo(subject);
            // console.log(subject);
            console.log(subject);
            this.$store.commit("setWindowSizeHeightAdd");
            // store.dispatch('SetSubjectInfo', subject).then(() => { })
          }
          // 更新时间
          getCurrentTime().then((response) => {
          getCurrentTime().then(response => {
            this.subjectStartTime = moment(response.data.data);
          });
          this.endLoading(nextType);
        })
        .catch((error) => {
        .catch(error => {
          console.log(error);
          this.$store.commit("setWindowSizeHeightAdd");
          messageFail(this, "获取题目失败");
          this.endLoading(nextType);
        });
@@ -714,10 +726,10 @@
      this.startLoading(nextType);
      var data = {
        id: nextSubjectId,
        id: nextSubjectId
      };
      getSubjectResultInfo(data)
        .then((response) => {
        .then(response => {
          if (response.data.data !== null) {
            // 保存成功后更新答题卡状态
            const subject = response.data.data;
@@ -751,12 +763,12 @@
            // store.dispatch('SetSubjectInfo', subject).then(() => { })
          }
          // 更新时间
          getCurrentTime().then((response) => {
          getCurrentTime().then(response => {
            this.subjectStartTime = moment(response.data.data);
          });
          this.endLoading(nextType);
        })
        .catch((error) => {
        .catch(error => {
          console.log(error);
          messageFail(this, "获取题目失败");
          this.endLoading(nextType);
@@ -824,7 +836,7 @@
      this.$confirm("确定要提交吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        type: "warning"
      })
        .then(() => {
          this.disableSubmit = true;
@@ -844,7 +856,7 @@
        examTime: this.startTime,
        papersId: this.$route.query.id,
        examEndTime: this.getCurrentTimes(),
        examResultVOS: null,
        examResultVOS: null
      };
      var arr = [];
      console.log(this.subjectIds);
@@ -858,7 +870,7 @@
          if (item.answer.length > 0) {
            //如果是数组
            if (item.answer instanceof Array) {
              item.answer.forEach((it) => {
              item.answer.forEach(it => {
                if (it.value != "") {
                  str += it.value + ",";
                }
@@ -869,13 +881,13 @@
              arr.push({
                subjectChoicesId: item.everyID,
                value: a,
                grade: item.score,
                grade: item.score
              });
            } else {
              arr.push({
                subjectChoicesId: item.everyID,
                value: item.answer,
                grade: item.score,
                grade: item.score
              });
            }
          }
@@ -883,7 +895,7 @@
          arr.push({
            subjectChoicesId: item.everyID,
            value: item.answer,
            grade: item.score,
            grade: item.score
          });
        }
      }
@@ -894,17 +906,17 @@
      // console.log(obj.examResultVOS, 789);
      saveAndNext(obj)
        .then((response) => {
        .then(response => {
          messageSuccess(this, "提交成功");
          if (response) {
            this.$store.commit("DEL_TAG", this.$store.state.tags.tag);
            var obj = {
              userId: this.userInfo.user_id,
              examId: this.$route.query.id,
              examId: this.$route.query.id
            };
            this.$router.push({
              path: `/singleperformance/index`,
              query: obj,
              query: obj
            });
          }
        })
@@ -1039,8 +1051,8 @@
          console.error(error);
        }
      }
    },
  },
    }
  }
};
</script>