natasha 14 hodín pred
rodič
commit
73ca4d08ac

+ 5 - 1
src/views/book/courseware/preview/components/video_interaction/ExercisePreview.vue

@@ -51,7 +51,11 @@ export default {
       this.$emit('handleCancle');
     },
     submitAdd() {
-      this.$emit('submitAdd', this.exercise_id, this.$refs.preview.answer, this.$refs.preview.data);
+      let obj = {
+        content: this.content,
+        title: this.title,
+      };
+      this.$emit('submitAdd', this.exercise_id, this.$refs.preview.answer, obj);
     },
     handleData() {
       this.loading = true;

+ 181 - 0
src/views/book/courseware/preview/components/video_interaction/Report.vue

@@ -0,0 +1,181 @@
+<template>
+  <div class="Exercise-report">
+    <div class="report-box">
+      <div class="report-item">
+        <span>总题数</span>
+        <b>{{ reportResult.total }}</b>
+      </div>
+      <div class="report-item">
+        <span>正确</span>
+        <b>{{ reportResult.right }}</b>
+      </div>
+      <div class="report-item">
+        <span>错误</span>
+        <b>{{ reportResult.error }}</b>
+      </div>
+      <div class="report-item">
+        <span>正确率</span>
+        <b>{{ reportResult.rightRate }}</b>
+      </div>
+    </div>
+    <div class="type-content" v-loading="loading">
+      <el-button plain style="cursor: inherit">第{{ index + 1 }}题</el-button>
+      <el-button plain type="primary" @click="handlePage('-')">上一题</el-button>
+      <el-button plain type="primary" @click="handlePage('+')">下一题</el-button>
+      <div class="type-content-inner">
+        <div class="rich-text" v-html="sanitizeHTML(title)"></div>
+        <component :is="getViewCom" :content="content" ref="preview" type="interaction" />
+      </div>
+    </div>
+    <footer style="text-align: right">
+      <el-button type="primary" @click="submitAdd">确 定</el-button>
+    </footer>
+  </div>
+</template>
+
+<script>
+import SelectPreview from '@/views/book/courseware/preview/components/select/SelectPreview.vue';
+import JudgePreview from '@/views/book/courseware/preview/components/judge/JudgePreview.vue';
+import { GetCoursewareExerciseView } from '@/api/book';
+import { sanitizeHTML } from '@/utils/common';
+export default {
+  name: 'ExerciseReport',
+  components: { SelectPreview, JudgePreview },
+  props: ['reportResult', 'exerciseList', 'userAnswer', 'fileList'],
+  data() {
+    return {
+      sanitizeHTML,
+      loading: false,
+      title: '',
+      content: '',
+      index: 0,
+      exerciseLists: this.exerciseList,
+      typeValue: '',
+    };
+  },
+  computed: {
+    getViewCom() {
+      switch (this.typeValue) {
+        case 'select':
+          return SelectPreview;
+        case 'judge':
+          return JudgePreview;
+      }
+    },
+  },
+  watch: {
+    index: {
+      handler(val) {
+        this.handleData();
+      },
+      immediate: true,
+    },
+    'data.property.file_list': 'handleMindMap',
+  },
+  // 生命周期 - 创建完成(可以访问当前this实例)
+  created() {
+    this.handleData();
+  },
+  methods: {
+    componentMove() {},
+
+    handleCancle() {
+      this.$emit('handleCancle');
+    },
+    submitAdd() {
+      this.$emit('handleCancle');
+    },
+    handleData() {
+      let exercise_id = this.fileList[this.index].id;
+      if (this.exerciseLists[exercise_id]) {
+        this.content = this.exerciseLists[exercise_id].content;
+        this.title = this.exerciseLists[exercise_id].title;
+        this.typeValue = this.exerciseLists[exercise_id].content
+          ? JSON.parse(this.exerciseLists[exercise_id].content).type
+          : '';
+        setTimeout(() => {
+          this.$refs.preview.showAnswer(true, true, this.userAnswer[exercise_id], true);
+        }, 100);
+        return;
+      }
+      this.loading = true;
+      let data = {
+        exercise_id: exercise_id,
+        courseware_id: this.$route.params.id,
+      };
+      GetCoursewareExerciseView(data)
+        .then((res) => {
+          this.loading = false;
+          if (res.status === 1) {
+            this.content = res.content_exercise;
+            this.title = res.content_title;
+            this.typeValue = res.content_exercise ? JSON.parse(res.content_exercise).type : '';
+            setTimeout(() => {
+              this.$refs.preview.showAnswer(true, true, null, true);
+            }, 100);
+            let obj = {
+              content: res.content_exercise,
+              title: res.content_title,
+            };
+            this.$set(this.exerciseLists, exercise_id, obj);
+          }
+        })
+        .catch(() => {
+          this.loading = false;
+        });
+    },
+    handlePage(type) {
+      if (type === '-') {
+        if (this.index > 0) {
+          this.index--;
+        } else {
+          this.$message.warning('已经是第一题');
+        }
+      } else {
+        if (this.index < this.fileList.length - 1) {
+          this.index++;
+        } else {
+          this.$message.warning('已经是最后一题');
+        }
+      }
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+.type-content {
+  margin: 12px 0;
+}
+
+.type-content-inner {
+  width: 100%;
+}
+
+:deep .sn-position {
+  display: none;
+}
+
+.report-box {
+  display: flex;
+  gap: 80px;
+  justify-content: center;
+  padding: 24px;
+  background: #f7f7f7;
+
+  .report-item {
+    span {
+      display: block;
+      margin-bottom: 8px;
+      font-size: 16px;
+      line-height: 24px;
+    }
+
+    b {
+      font-size: 24px;
+      line-height: 32px;
+      color: #000;
+    }
+  }
+}
+</style>

+ 41 - 13
src/views/book/courseware/preview/components/video_interaction/VideoInteractionPreview.vue

@@ -13,13 +13,8 @@
         controlsList="nodownload"
       ></video>
     </div>
-
-    <el-button
-      type="primary"
-      v-if="Object.keys(this.userAnswer).length === data.file_info_list.length"
-      @click="lookReport"
-      >查看答题报告</el-button
-    >
+    <!-- v-if="Object.keys(this.userAnswer).length === data.file_info_list.length" -->
+    <el-button type="primary" @click="lookReport">查看答题报告</el-button>
     <el-dialog
       v-if="visible"
       :visible.sync="visible"
@@ -29,16 +24,35 @@
       :append-to-body="true"
       :lock-scroll="true"
       width="80%"
-      @close="handleClose"
     >
       <ExercisePreview :exercise_id="exercise_id" @handleCancle="handleClose" @submitAdd="submitAdd"></ExercisePreview>
       <!-- <iframe v-if="visible" :src="newpath" width="100%" :height="iframeHeight" frameborder="0"></iframe> -->
     </el-dialog>
+    <el-dialog
+      v-if="reportFlag"
+      :visible.sync="reportFlag"
+      :show-close="true"
+      :close-on-click-modal="true"
+      :modal-append-to-body="true"
+      :append-to-body="true"
+      :lock-scroll="true"
+      width="80%"
+      @close="handleClose"
+    >
+      <Report
+        :reportResult="reportResult"
+        :exerciseList="exerciseList"
+        :userAnswer="userAnswer"
+        :fileList="data.file_info_list"
+        @handleCancle="handleClose"
+      ></Report>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import ExercisePreview from './ExercisePreview.vue';
+import Report from './Report.vue';
 import PreviewMixin from '../common/PreviewMixin';
 import { getVideoInteractionData } from '@/views/book/courseware/data/videoInteraction';
 import { GetFileURLMap } from '@/api/app';
@@ -46,7 +60,7 @@ import { getConfig } from '@/utils/auth';
 export default {
   name: 'VideoInteractionPreview',
 
-  components: { ExercisePreview },
+  components: { ExercisePreview, Report },
   mixins: [PreviewMixin],
   data() {
     return {
@@ -104,11 +118,11 @@ export default {
       });
     },
     handleClose() {
-      this.visible = false;
+      this.reportFlag = false;
       document.getElementById('interaction-preview-video').play();
-      setTimeout(() => {
-        this.first = '';
-      }, 1000);
+      // setTimeout(() => {
+      //   this.first = '';
+      // }, 1000);
     },
     submitAdd(id, answer, content) {
       this.visible = false;
@@ -121,6 +135,20 @@ export default {
     },
     lookReport() {
       document.getElementById('interaction-preview-video').pause();
+      let num = 0;
+      let total = this.data.file_info_list.length;
+      Object.keys(this.userAnswer).forEach((key) => {
+        if (this.userAnswer[key].is_right) {
+          num++;
+        }
+      });
+      this.reportResult = {
+        total: total,
+        right: num,
+        error: total - num,
+        rightRate: ((num / total) * 100).toFixed(0) + '%',
+      };
+      this.reportFlag = true;
     },
   },
 };