Browse Source

修复了成绩页面时间的问题

zhangyujun 3 years ago
parent
commit
6eae03724c

+ 84 - 0
src/components/countDown/index.vue

@@ -0,0 +1,84 @@
+<template>
+  <view>
+    <view
+      :style="{
+        background: background,
+        textAlign: textAlign,
+      }"
+      class="left-time"
+      >{{ formatterTime(privateTime, "mm:ss") }}</view
+    >
+  </view>
+</template>
+
+<script>
+export default {
+  data() {
+    return {
+      privateTime: this.time,
+    };
+  },
+  methods: {
+    formatterTime(time, format) {
+      function formatterTimer(timer, format) {
+        let formatArr = format.split(":");
+        return formatArr
+          .map((element) => {
+            switch (element) {
+              case "hh":
+                return timer.getHours();
+                break;
+              case "mm":
+                return timer.getMinutes();
+                break;
+              case "ss":
+                return timer.getSeconds();
+                break;
+            }
+          })
+          .join(":");
+      }
+      return formatterTimer(new Date(time), format);
+    },
+  },
+  props: {
+    time: {
+      type: Number,
+      default: 0,
+    },
+    textAlign: {
+      type: String,
+      default: "center",
+    },
+    background: {
+      type: String,
+      default: "#fff",
+    },
+  },
+  watch: {
+    time(newVal, oldVal) {
+      this.privateTime = Number(newVal);
+    },
+  },
+  mounted() {
+    let t = setInterval(() => {
+      this.privateTime = this.privateTime - 1000;
+      //第一参数是剩余时间,第二个是过去的时间
+      this.$emit("change", this.formatterTime(this.privateTime, "mm:ss"),this.formatterTime(this.time-this.privateTime, "mm:ss"));
+      if (this.privateTime == 0) {
+        clearInterval(t);
+          //第一参数是剩余时间,第二个是过去的时间
+        this.$emit("end", this.formatterTime(this.privateTime, "mm:ss"),this.formatterTime(this.time-this.privateTime, "mm:ss"));
+      }
+    }, 1000);
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.left-time {
+  width: 100%;
+  font-size: 28rpx;
+  text-align: center;
+}
+</style>

+ 16 - 8
src/components/m-do-topic/m-do-topic.vue

@@ -1,5 +1,6 @@
 <template>
   <view>
+    <countDown :time="examTime" @change="getUseTime" v-if="type == 'singleTest' || type == 'exam'"></countDown>
     <view v-if="!hiddenMode" class="mode">
       <view
         @click="
@@ -748,6 +749,7 @@
 </template>
 
 <script>
+import countDown from "@/components/countDown/index";
 import mRadio from "@/components/m-radio/m-radio.vue";
 import mRadioGroup from "@/components/m-radio-group/m-radio-group.vue";
 import mCheckbox from "@/components/m-checkbox/m-checkbox.vue";
@@ -832,6 +834,8 @@ export default {
         mtc: "摩托车",
         kc: "客车",
       },
+      examTime:1000*60*45,
+      useTime:'',
       problemListTotal: 1,
       explainJqVisible: false,
       selectProblemListVisible: false,
@@ -853,6 +857,10 @@ export default {
     },
   },
   methods: {
+    getUseTime(leftTime,useTime){
+      this.useTime = useTime
+
+    },
     stopAudio() {
       let audio = utils.wxUtils.getGlobAudio();
       audio.stop();
@@ -961,10 +969,9 @@ export default {
         content: "交卷后不可再修改了",
         success(res) {
           if (res.confirm) {
-            let useTime = "";
-            let useTimer = new Date(that.examTimeUse);
-            clearInterval(that.examTimer);
-            useTime = `${useTimer.getMinutes()}:${useTimer.getSeconds()}`;
+            let useTime = that.useTime;
+  
+      
             uni.navigateTo({
               url:
                 "/otherPages/mockExamEnd/index?" +
@@ -1236,6 +1243,7 @@ export default {
     tabbar,
     explainJs,
     funList,
+    countDown,
   },
 
   props: {
@@ -1283,10 +1291,10 @@ export default {
     },
   },
   mounted() {
-    let that =this
-   uni.showLoading({
-        title: "加载题目中"
-      });
+    let that = this;
+    uni.showLoading({
+      title: "加载题目中",
+    });
     switch (that.type) {
       case "specify":
         api.open

+ 6 - 0
src/otherPages/code/index.vue

@@ -1,6 +1,7 @@
 <template>
   <view>
     <text> {{ code }}</text>
+    <countDown :time="time"></countDown>
     <view class="menu">
       <button @click="copyCode" style="background: red">复制code</button>
       <button @click="freshCode" style="background: orange">
@@ -11,10 +12,12 @@
 </template>
 
 <script>
+import countDown from '@/components/countDown/index'
 export default {
   data() {
     return {
       code: "",
+      time:1000*60*45
     };
   },
   methods: {
@@ -39,6 +42,9 @@ export default {
   onLoad(op) {
     this.freshCode();
   },
+  components: {
+    countDown
+  },
 };
 </script>
 

+ 1 - 4
src/otherPages/exerciseExam/index.vue

@@ -4,12 +4,9 @@
     <!-- <view style="text-align:center;">
       <van-count-down :time="time"></van-count-down>
     </view> -->
-    <view style="text-align: center">
-      <van-count-down :time="time"></van-count-down>
-    </view>
-
     <m-do-topic
       v-if="isGetQuery"
+      type="singleTest"
       :hiddenAnswer="true"
       :hiddenMode="true"
       :bottomFunc="['previous', 'next', 'selectCatalogue', 'submitExam']"

+ 0 - 3
src/otherPages/mockExam/index.vue

@@ -1,9 +1,6 @@
 <template>
   <view class="box" @touchstart="touchStart" @touchend="touchEnd">
     <nav-bar :title="navTitle"> </nav-bar>
-    <view style="text-align: center">
-      <van-count-down :time="time"></van-count-down>
-    </view>
     <m-do-topic
       type="exam"
       :bottomFunc="['previous', 'next', 'submitExam', 'catalogue']"