瀏覽代碼

添加判断

asd123a20 2 年之前
父節點
當前提交
dd0ea2962f
共有 1 個文件被更改,包括 14 次插入30 次删除
  1. 14 30
      admin-frame/src/components/editoritem2.vue

+ 14 - 30
admin-frame/src/components/editoritem2.vue

@@ -48,36 +48,20 @@ export default {
           },
           customPaste: (editor, event) => {
             const text = event.clipboardData.getData('text/plain');
-            // if (text) {
-            //   let html = text.split(/\n/).map(line => {
-            //     line = line.replace(/\r/, '');
-            //     return `<p>${line}</p>`;
-            //   }).join('\n');
-            //   console.log(html, 'html');
-            //   html = html.replace(/>(\s{2,})[^\s]/g, (all, $1, $2) => {
-            //     if ($1.charAt(0) == '\n' || $1.charAt(0) == '\r' || $1.charAt(0) == '\x20') return all;
-            //     //  &nbsp; &nbsp
-            //     return all.replace($1, Array($1.length).fill('&nbsp;&nbsp;&nbsp;&nbsp;').join(''));
-            //   });
-            //   const gethtml = editor.getHtml();
-            //   // console.log(`${gethtml}${html}`);
-            //   editor.setHtml(`${gethtml}${html}`);
-            //   // 阻止默认的粘贴行为
-            //   event.preventDefault();
-            //   return false;
-            // }
-            const nodeList = [];
-            text.split(/\n/).map(line => {
-              line = line.replace(/\r/, '');
-              line = line.replace(/(\s{2})/, (all, $1) => {
-                if ($1.charAt(0) == '\n' || $1.charAt(0) == '\r' || $1.charAt(0) == '\x20') return all;
-                return all.replace($1, Array($1.length).fill('    ').join(''));
-              });
-              nodeList.push({ type: 'paragraph', children: [{ text: line }] });
-            }).join('\n');
-            SlateTransforms.insertNodes(editor, nodeList);
-            event.preventDefault();
-            return false;
+            if (text) {
+              const nodeList = [];
+              text.split(/\n/).map(line => {
+                line = line.replace(/\r/, '');
+                line = line.replace(/(\s{2})/, (all, $1) => {
+                  if ($1.charAt(0) == '\n' || $1.charAt(0) == '\r' || $1.charAt(0) == '\x20') return all;
+                  return all.replace($1, Array($1.length).fill('    ').join(''));
+                });
+                nodeList.push({ type: 'paragraph', children: [{ text: line }] });
+              }).join('\n');
+              SlateTransforms.insertNodes(editor, nodeList);
+              event.preventDefault();
+              return false;
+            }
           },
           MENU_CONF: {
             uploadImage: {