Jelajahi Sumber

调整了粘贴内容校验规则,仅允许图表外链iframe

cxmo 1 tahun lalu
induk
melakukan
9f2761587e

+ 17 - 1
src/views/report_manage/mixins/reportMixin.js

@@ -167,7 +167,13 @@ export default {
           },
           "paste.before":function(e,editor){
             let content = e.clipboardData.getData('text/html');
-            if(content.includes('<iframe')){
+           // console.log(content)
+            var tempDiv = document.createElement('div');
+            tempDiv.innerHTML = content;
+            var iframes = tempDiv.querySelectorAll('iframe');
+            const srcArr = Array.from(iframes).map(i=>i.src)
+            //console.log(srcArr);
+            if(srcArr.filter(i=>!i.includes(that.$setting.dynamicOutLinks.ChartViewUrl)).length){
                 that.$message.warning("粘贴内容含有外链,请核对内容或粘贴纯文本")
                 return false
             }
@@ -217,6 +223,16 @@ export default {
   },
 
   methods: {
+    containsOtherIframe(text, chartshowURL, tableshowURL) {
+        console.log('url',chartshowURL)
+        // 使用正则表达式匹配除了指定的两个 <iframe> 之外的其他 <iframe>
+        var pattern = new RegExp('<iframe\\s+src="' + chartshowURL.replace(/\//g, "\\/") + '"|' +
+                                 chartshowURL.replace(/\//g, "\\/") + '"', 'g');
+        var pattern2 = new RegExp('<iframe\\s+src="' + tableshowURL.replace(/\//g, "\\/") + '"|' +
+                                 tableshowURL.replace(/\//g, "\\/") + '"', 'g');
+        console.log('pattern',pattern.test(text))
+        return !(pattern.test(text) || pattern2.test(text));
+    },
     insertHtml(item, type = "chart") {
       //设置编辑器获取焦点
       this.editor.events.focus();

+ 12 - 6
src/views/report_manage/reportEn/reportEditor.vue

@@ -501,12 +501,18 @@ export default {
         pasteAllowedStyleProps: ['font-family', 'font-size', 'color'],
         events:{
             "paste.before":function(e,editor){
-            let content = e.clipboardData.getData('text/html');
-            if(content.includes('<iframe')){
-                that.$message.warning("粘贴内容含有外链,请核对内容或粘贴纯文本")
-                return false
-            }
-          }
+                let content = e.clipboardData.getData('text/html');
+                // console.log(content)
+                var tempDiv = document.createElement('div');
+                tempDiv.innerHTML = content;
+                var iframes = tempDiv.querySelectorAll('iframe');
+                const srcArr = Array.from(iframes).map(i=>i.src)
+                //console.log(srcArr);
+                if(srcArr.filter(i=>!i.includes(that.$setting.dynamicOutLinks.ChartViewUrl)).length){
+                    that.$message.warning("粘贴内容含有外链,请核对内容或粘贴纯文本")
+                    return false
+                }
+            },
         }
       },
 

+ 8 - 2
src/views/smartReport/components/TextEdit.vue

@@ -108,11 +108,17 @@ export default {
                     },
                     "paste.before":function(e,editor){
                         let content = e.clipboardData.getData('text/html');
-                        if(content.includes('<iframe')){
+                        // console.log(content)
+                        var tempDiv = document.createElement('div');
+                        tempDiv.innerHTML = content;
+                        var iframes = tempDiv.querySelectorAll('iframe');
+                        const srcArr = Array.from(iframes).map(i=>i.src)
+                        //console.log(srcArr);
+                        if(srcArr.filter(i=>!i.includes(that.$setting.dynamicOutLinks.ChartViewUrl)).length){
                             that.$message.warning("粘贴内容含有外链,请核对内容或粘贴纯文本")
                             return false
                         }
-                    }
+                    },
                 },
             }
         }