富文本粘贴图片上传到服务器

master
jialong.yu 3 years ago
parent 708a6e5252
commit 9a9218cd10
  1. 15380
      package-lock.json
  2. 32
      src/components/quill/index.vue
  3. 2
      src/utils/api.js
  4. 2
      src/utils/http.js

15380
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -75,7 +75,6 @@
readOnly: this.readonly
},
loading: false,
quillArr: [],
qu: null
}
},
@ -125,8 +124,7 @@
const editor = eval(toeval)
//
this.Quill = new Quill(editor, this.options);
this.quillArr.push(this.Quill)
const ins = this.Quill
//
this.Quill.pasteHTML(this.currentValue);
if(this.toTop){
@ -156,9 +154,35 @@
this.Quill.on('editor-change', (eventName, ...args) => {
this.$emit('on-editor-change', eventName, ...args);
});
//
ins.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 param = new FormData()
param.append('file', file)
// base64
this.$post(this.api.fileupload, param, {
headers: { "Content-Type": "multipart/form-data" }
}).then(res => {
var range = ins.getSelection()
console.log(333, range)
if (range) {
//
ins.insertEmbed(range.index, 'image', res.data.filesResult.fileUrl)
//
ins.setSelection(range.index + 1)
}
}).catch(res => {})
});
}
}, false)
},
beforeUpload(file){
console.log('上传前:',this.qu,this.toref,this.Quill,this.quillArr)
this.loading = true
},
editorUploadSuccess (res) {

@ -27,7 +27,7 @@ if(isKd){
// host = 'http://192.168.31.137:9000' // 坤
}
let host1 = 'http://39.108.250.202:8080';
let uploadURL = 'http://8.134.8.197:8001';
let uploadURL = `${location.origin}:9000`
export default {
fileupload: `${uploadURL}/oss/manage/fileupload`,

@ -225,6 +225,8 @@ export function post(url, params) {
);
break;
}
} else {
resolve(res.data)
}
})
.catch(err => {

Loading…
Cancel
Save