Browse Source

修复图片黏贴上传时转换为了base64

xinfeng 5 years ago
parent
commit
cc8c0cc0d0
3 changed files with 20 additions and 5 deletions
  1. 18 3
      components/editor.vue
  2. 1 1
      components/topics/editor.vue
  3. 1 1
      plugins/nuxtAxios.js

+ 18 - 3
components/editor.vue

@@ -90,7 +90,7 @@ export default {
     // 为图片ICON绑定事件  getModule 为编辑器的内部属性
     this[this.quillName]
       .getModule("toolbar").addHandler("image", this.imgHandler);
-
+    this.changeParseEvent()
     this.addLinkEvent()
   },
   methods: {
@@ -109,6 +109,22 @@ export default {
       }
       this.uploadType = "image";
     },
+    //change parse
+    changeParseEvent() {
+      //  自定义粘贴图片功能
+      this[this.quillName].root.addEventListener('paste', evt => {
+        console.log("evt", evt)
+        if (evt.clipboardData && evt.clipboardData.files && evt.clipboardData.files.length) {
+          evt.preventDefault();
+          [].forEach.call(evt.clipboardData.files, file => {
+            if (!file.type.match(/^image\/(gif|jpe?g|a?png|bmp)/i)) {
+              return;
+            }
+            this.handleContentFileChange({target: {files:[file]}})
+          });
+        }
+      }, false);
+    },
 
     addLinkEvent() {
       let dom =  document.getElementsByClassName("ql-link")
@@ -158,8 +174,7 @@ export default {
       }
       // this.uploadType = "video";
     },
-    handleContentFileChange(e, name) {
-      console.log('name', name)
+    handleContentFileChange(e) {
       const file = e.target.files[0];
       if (file.size / 1024/1024 > 2) {
         this.$message.error("图片大小不得超过2M,请重新选择");

+ 1 - 1
components/topics/editor.vue

@@ -163,7 +163,7 @@ export default {
         cover_url: this.cover_url
       };
       if (this.topicId) {
-        data.topicId = this.topicId;
+        data.topic_id = this.topicId;
         this.$axios
           .$post(`/api/community/topic/update_topic`, data)
           .then(res => {

+ 1 - 1
plugins/nuxtAxios.js

@@ -84,7 +84,7 @@ export default function ({
     } else {
       console.log(JSON.stringify(data));
       Vue.prototype.$message.closeAll();
-      Vue.prototype.$message.error(data.info || "");
+      Vue.prototype.$message.error(data.info || data.error || "");
     }
     return res;
   });