Commit f3d1c4cebd62666118ef0777a88e3eb020a2c9a8

Authored by liufangjia
1 parent 7f592639

feat: 查看解析

src/views/basic/askTestQuestion/components/analysisDialog.vue 0 → 100644
  1 +<template>
  2 + <el-dialog
  3 + :visible.sync="visible"
  4 + width="50%"
  5 + :before-close="handleClose"
  6 + :modal-append-to-body="false"
  7 + >
  8 + <div class="test-box" v-if="analysisUrl">
  9 + <iframe
  10 + :src="analysisUrl"
  11 + ref="iframe"
  12 + @load="onIFrameLoad()"
  13 + style="width: 100%; border: none; /* 启用点击穿透 */"
  14 + ></iframe>
  15 + </div>
  16 +
  17 + <span slot="title" class="title"> 题目解析 </span>
  18 + </el-dialog>
  19 +</template>
  20 + <script>
  21 +export default {
  22 + name: "analysisDialog",
  23 + props: {
  24 + visible: {
  25 + type: Boolean,
  26 + default() {
  27 + return false;
  28 + },
  29 + },
  30 + analysisUrl: {
  31 + // 科目
  32 + type: String,
  33 + default() {
  34 + return null;
  35 + },
  36 + },
  37 + },
  38 + data() {
  39 + return {};
  40 + },
  41 +
  42 + watch: {
  43 + visible(val) {
  44 + if (val) {
  45 + console.log(val);
  46 + } else {
  47 + this.handleClose();
  48 + }
  49 + },
  50 + },
  51 + methods: {
  52 + /** 按钮 - 取消 */
  53 + handleClose() {
  54 + this.$emit("update:visible", false);
  55 + },
  56 +
  57 + onIFrameLoad() {
  58 + const iframeRef = this.$refs.iframe; // 获取对应的 iframe
  59 + const doc = iframeRef.contentDocument || iframeRef.contentWindow.document;
  60 + const body = iframeRef.contentWindow.document.body;
  61 + body.style.overflowX = "hidden"; // 不允许出现横向滚动条
  62 + const height = body.scrollHeight; // 获取内容的高度
  63 + iframeRef.style.height = `${height + 20}px`; // 设置 iframe 的高度
  64 + // 获取第一个P标签
  65 + const firstP = doc.getElementsByTagName("p")[0];
  66 + // 或者修改第一个 < p > 标签的内容;
  67 + if (firstP) {
  68 + let a = this.processString(firstP.innerHTML);
  69 + firstP.innerHTML = a;
  70 + }
  71 + },
  72 + },
  73 +};
  74 +</script>
  75 + <style lang="scss" scoped>
  76 +.title {
  77 + font-weight: 600;
  78 +}
  79 +.test-box {
  80 + width: 100%;
  81 + box-sizing: border-box;
  82 + padding: 20px;
  83 +}
  84 +</style>
0 85 \ No newline at end of file
... ...
src/views/basic/askTestQuestion/wrongQuestion.vue
... ... @@ -168,7 +168,10 @@
168 168 <!-- <div class="topic-info" v-html="item.modifiedHtml"></div> -->
169 169 <div class="topic-bottom">
170 170 <div>
171   - <span v-if="item.answerScreenshot" class="knowledge size"
  171 + <span
  172 + v-if="item.answerScreenshot"
  173 + class="knowledge size"
  174 + @click="handleAnalysis(item.answerScreenshot)"
172 175 ><i class="el-icon-key"></i>查看解析</span
173 176 >
174 177 <span class="color size">知识点:</span>
... ... @@ -242,15 +245,21 @@
242 245 :gradeId="formData.grade"
243 246 @setQuestions="setQuestions"
244 247 />
  248 + <analysisDialog
  249 + :visible.sync="analysisVisible"
  250 + :analysisUrl="analysisUrl"
  251 + />
245 252 </div>
246 253 </template>
247 254  
248 255 <script>
249 256 import { setDateRules } from "@/utils";
250 257 import wrongQuestionDialog from "./components/wrongQuestionDialog.vue";
  258 +import analysisDialog from "./components/analysisDialog.vue";
251 259 export default {
252 260 components: {
253 261 wrongQuestionDialog,
  262 + analysisDialog,
254 263 },
255 264 data() {
256 265 return {
... ... @@ -259,6 +268,8 @@ export default {
259 268 maxValue: 100, // 最大值
260 269 visible: false, // 购物车弹框控制
261 270 queryLoading: false, //loading
  271 + analysisUrl: null, // 解析url
  272 + analysisVisible: false, // 解析弹框
262 273 // 分页
263 274 listPage: {
264 275 page: 1,
... ... @@ -597,6 +608,12 @@ export default {
597 608 setQuestions() {
598 609 this.questions = JSON.parse(localStorage.getItem("testlist")) || [];
599 610 },
  611 +
  612 + // 查看解析
  613 + handleAnalysis(url) {
  614 + this.analysisUrl = url;
  615 + this.analysisVisible = true;
  616 + },
600 617 },
601 618 };
602 619 </script>
... ...