From 743e54d665a6a8970f47b1d558cb61041f7a2fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E5=BC=BA=E5=BC=BA?= <787203167@qq.com> Date: Fri, 16 Sep 2022 09:07:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E5=BA=93=E7=9A=84=E5=AF=8C=E6=96=87=E6=9C=AC=E7=B2=98?= =?UTF-8?q?=E8=B4=B4=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/problemKnowledgeBaseAdd.vue | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/jero-web/src/views/businessSupport/problemKnowledgeBase/components/problemKnowledgeBaseAdd.vue b/jero-web/src/views/businessSupport/problemKnowledgeBase/components/problemKnowledgeBaseAdd.vue index 43db4bdfb..19fc8f1ff 100644 --- a/jero-web/src/views/businessSupport/problemKnowledgeBase/components/problemKnowledgeBaseAdd.vue +++ b/jero-web/src/views/businessSupport/problemKnowledgeBase/components/problemKnowledgeBaseAdd.vue @@ -195,6 +195,7 @@ import { quillEditor } from 'vue-quill-editor' import Vue from 'vue' import { ACCESS_TOKEN } from '@/store/mutation-types' + import axios from 'axios' const toolbarOptions = [ ['bold', 'italic', 'underline', 'strike'], // toggled buttons @@ -236,7 +237,7 @@ modules: { clipboard: { // 粘贴版,处理粘贴时候带图片 - matchers: [[Node.ELEMENT_NODE, this.handleCustomMatcher]], + matchers: [[Node.ELEMENT_NODE, this.handleCustomMatcher]] }, toolbar: { container: toolbarOptions, // 工具栏 @@ -337,6 +338,49 @@ } else { document.title = this.$t('problemKnowledgeBase') + this.$t('newlyAdded') } + let quill = this.$refs.myQuillEditor.quill + this.$forceUpdate() + quill.root.addEventListener( + 'paste', + (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 + } + const formData = new FormData() + formData.append('file', file) + axios({ + url: this.uploadAction, + method: 'post', + data: formData, + headers: { + 'Content-Type': 'multipart/form-data', + 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN) + } + }) + .then((res) => { + if (res.data.success){ + let quill = this.$refs.myQuillEditor.quill + let length = quill.getSelection().index + let fileName = res.data.result.fileName + let index1 = fileName.lastIndexOf('.') + let index2 = fileName.length + let fileSuffix = fileName.substring(index1, index2) + quill.insertEmbed(length, 'image', window._CONFIG['domianPreviewURL'] + '/sys/common/download/' + res.data.result.id + fileSuffix) + quill.setSelection(length + 1) + } + }) + }) + } + }, + false + ) }, methods: { quilleditorBlur() { @@ -347,7 +391,7 @@ Delta.ops.forEach(op => { if (op.insert && typeof op.insert === 'string') {// 如果粘贴了图片,这里会是一个对象,如果是字符串则可以添加 ops.push({ - insert: op.insert, + insert: op.insert }) } }) @@ -461,7 +505,7 @@ let index1 = fileName.lastIndexOf('.') let index2 = fileName.length let fileSuffix = fileName.substring(index1, index2) - quill.insertEmbed(length, 'image', window._CONFIG['domianPreviewURL']+'/sys/common/download/'+file.response.result.id+fileSuffix) + quill.insertEmbed(length, 'image', window._CONFIG['domianPreviewURL'] + '/sys/common/download/' + file.response.result.id + fileSuffix) quill.setSelection(length + 1) this.quillUpdateImg = false } else if (status === 'uploading') {