Blame view

src/views/basic/askTestQuestion/components/analysisDialog.vue 2.28 KB
f3d1c4ce   liufangjia   feat: 查看解析
1
2
3
4
5
6
7
8
9
10
11
12
  <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()"
df2979bc   刘有才luck   wip: 细节修改
13
          style="width: 100%; border: none; max-height: 600px; /* 启用点击穿透 */"
f3d1c4ce   liufangjia   feat: 查看解析
14
15
16
17
18
19
        ></iframe>
      </div>
  
      <span slot="title" class="title"> 题目解析 </span>
    </el-dialog>
  </template>
0b9ef2ed   刘有才luck   feat: bug修复
20
  <script>
f3d1c4ce   liufangjia   feat: 查看解析
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
  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;
0b9ef2ed   刘有才luck   feat: bug修复
61
62
63
        // body.style.overflowX = "hidden"; // 不允许出现横向滚动条
        const height = body.offsetHeight; // 获取内容的高度
        iframeRef.style.height = `${height + 40}px`; // 设置 iframe 的高度
f3d1c4ce   liufangjia   feat: 查看解析
64
65
66
67
68
69
70
71
        // 获取第一个P标签
        const firstP = doc.getElementsByTagName("p")[0];
        // 或者修改第一个 < p > 标签的内容;
        if (firstP) {
          let a = this.processString(firstP.innerHTML);
          firstP.innerHTML = a;
        }
      },
2fd57d1f   liufangjia   wip: 代码提交
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
      processString(input) {
        // 正则表达式:匹配最多三位数字
        const regex = /^(\d{1,3})/;
  
        // 测试字符串是否以数字开头
        const match = input.match(regex);
  
        if (match) {
          // 如果匹配,去掉开头的数字并返回剩余部分
          return input.substring(match[0].length + 1).trim();
        }
  
        // 如果没有匹配,直接返回原字符串
        return input;
      },
f3d1c4ce   liufangjia   feat: 查看解析
87
88
89
    },
  };
  </script>
0b9ef2ed   刘有才luck   feat: bug修复
90
  <style lang="scss" scoped>
f3d1c4ce   liufangjia   feat: 查看解析
91
92
93
94
95
96
  .title {
    font-weight: 600;
  }
  .test-box {
    width: 100%;
    box-sizing: border-box;
df2979bc   刘有才luck   wip: 细节修改
97
    overflow: auto;
f3d1c4ce   liufangjia   feat: 查看解析
98
  }
0b9ef2ed   刘有才luck   feat: bug修复
99
  </style>