Blame view

src/views/basic/askTestQuestion/components/analysisDialog.vue 1.83 KB
f3d1c4ce   liufangjia   feat: 查看解析
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
84
  <template>
    <el-dialog
      :visible.sync="visible"
      width="50%"
      :before-close="handleClose"
      :modal-append-to-body="false"
    >
      <div class="test-box" v-if="analysisUrl">
        <iframe
          :src="analysisUrl"
          ref="iframe"
          @load="onIFrameLoad()"
          style="width: 100%; border: none; /* 启用点击穿透 */"
        ></iframe>
      </div>
  
      <span slot="title" class="title"> 题目解析 </span>
    </el-dialog>
  </template>
    <script>
  export default {
    name: "analysisDialog",
    props: {
      visible: {
        type: Boolean,
        default() {
          return false;
        },
      },
      analysisUrl: {
        // 科目
        type: String,
        default() {
          return null;
        },
      },
    },
    data() {
      return {};
    },
  
    watch: {
      visible(val) {
        if (val) {
          console.log(val);
        } else {
          this.handleClose();
        }
      },
    },
    methods: {
      /** 按钮 - 取消 */
      handleClose() {
        this.$emit("update:visible", false);
      },
  
      onIFrameLoad() {
        const iframeRef = this.$refs.iframe; // 获取对应的 iframe
        const doc = iframeRef.contentDocument || iframeRef.contentWindow.document;
        const body = iframeRef.contentWindow.document.body;
        body.style.overflowX = "hidden"; // 不允许出现横向滚动条
        const height = body.scrollHeight; // 获取内容的高度
        iframeRef.style.height = `${height + 20}px`; // 设置 iframe 的高度
        // 获取第一个P标签
        const firstP = doc.getElementsByTagName("p")[0];
        // 或者修改第一个 < p > 标签的内容;
        if (firstP) {
          let a = this.processString(firstP.innerHTML);
          firstP.innerHTML = a;
        }
      },
    },
  };
  </script>
    <style lang="scss" scoped>
  .title {
    font-weight: 600;
  }
  .test-box {
    width: 100%;
    box-sizing: border-box;
    padding: 20px;
  }
  </style>