富文本上传图片

master
yujialong 3 years ago
parent 257ddaccc8
commit ff23215c98
  1. 21
      src/components/quill/index.vue
  2. 25
      src/views/title/Addtitle.vue

@ -1,6 +1,16 @@
<template> <template>
<div class="quill" ref="quill" :class="classes"> <div class="quill" ref="quill" :class="classes">
<div ref="editor" :style="styles" v-loading="loading"></div> <div ref="editor" :style="styles" v-loading="loading"></div>
<el-upload
:headers="headers"
:action="joggle"
:before-upload="beforeUpload"
:on-success="editorUploadSuccess"
style="display: none"
>
<el-button class="editorUpload" type="primary">点击上传</el-button>
</el-upload>
</div> </div>
</template> </template>
@ -10,6 +20,7 @@ import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css"; import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css"; import "quill/dist/quill.bubble.css";
import toolbarOptions from "./options"; import toolbarOptions from "./options";
import { joggle } from "@/apis/request.js";
import { joggleFn } from "@/apis/request.js"; import { joggleFn } from "@/apis/request.js";
export default { export default {
name: "quill", name: "quill",
@ -46,6 +57,7 @@ export default {
}, },
data() { data() {
return { return {
joggle,
headers: { headers: {
token: sessionStorage.getItem('token') token: sessionStorage.getItem('token')
}, },
@ -62,9 +74,9 @@ export default {
"image": function(value) { "image": function(value) {
if (value) { if (value) {
// iview // iview
document.querySelector(".editorUpload").click(); document.querySelector(".editorUpload").click()
} else { } else {
this.Quill.format("image", false); this.Quill.format("image", false)
} }
} }
} }
@ -197,11 +209,12 @@ export default {
// //
let quill = this.Quill; let quill = this.Quill;
// //
if (res.data.filesResult.fileUrl) { const url = res.data.fileUrl
if (url) {
// //
let length = quill.getSelection().index; let length = quill.getSelection().index;
// res // res
quill.insertEmbed(length, "image", res.data.filesResult.fileUrl); quill.insertEmbed(length, "image", url);
// //
quill.setSelection(length + 1); quill.setSelection(length + 1);
} else { } else {

@ -291,31 +291,6 @@ export default {
linkArticleId: "", linkArticleId: "",
}, },
formLabelWidth: "90px", formLabelWidth: "90px",
editorOption: {
scrollingContainer: '#editorcontainer',
placeholder: '',
// or 'bubble'
theme: 'snow',
modules: {
imageResize: {
displayStyles: {
backgroundColor: 'black', border: 'none', color: 'white'
},
modules: ['Resize', 'DisplaySize', 'Toolbar']
},toolbar: {
//
container: 'toolbarOptions.toolbarOptions',
handlers: { 'image': function (value) { if (value) {
// upload
document.querySelector('.avatar-uploader input').click()
} else {
this.quill.format('image', false)
}
}
}
}
}
},
isClear: false, isClear: false,
headerObj:{} headerObj:{}
}; };

Loading…
Cancel
Save