富文本编辑器上传图片bug

This commit is contained in:
zhanglipeng 2021-01-27 15:34:05 +08:00
parent 2236b55dd1
commit fb5c2e5962
3 changed files with 52 additions and 11 deletions

View File

@ -2,6 +2,7 @@
<div>
<!-- 图片上传组件辅助 -->
<el-upload
:key="randomString(3)"
class="avatar-uploader quill-img"
:action="uploadImgUrl"
name="file"
@ -15,9 +16,10 @@
<!-- 富文本组件 -->
<quill-editor
:id="randomString(3)"
class="ql-editor"
v-model="content"
ref="quillEditor"
:ref="toref"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ -59,6 +61,14 @@ export default {
type: Number,
default: 4000, //kb
},
quillIndex: {
type: Number,
default: 0,
},
toref: {
type: String,
default: "quillEditor",
},
},
components: { quillEditor },
data() {
@ -66,17 +76,18 @@ export default {
content: this.value,
uploadImgUrl: "",
editorOption: {
placeholder: "",
theme: "snow", // or 'bubble'
placeholder: "请输入内容",
modules: {
toolbar: {
container: toolbarOptions,
handlers: {
image: function (value) {
image: (value) =>{
if (value) {
// input
document.querySelector(".quill-img input").click();
// document.querySelector(".quill-img input").click();
const index = this.quillIndex;
document.querySelectorAll(".quill-img input")[index].click();
} else {
this.quill.format("image", false);
}
@ -107,7 +118,17 @@ export default {
//
this.$emit("input", this.content);
},
//
randomString(len) {
//oOLl,9gq,Vv,Uu,I1
var chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
var tempLen = chars.length,
tempStr = "";
for (var i = 0; i < len; ++i) {
tempStr += chars.charAt(Math.floor(Math.random() * tempLen));
}
return tempStr;
},
//
quillImgBefore(file) {
let fileType = file.type;
@ -120,15 +141,35 @@ export default {
},
quillImgSuccess(res, file) {
// // res
// //
// let quill = this.$refs.quillEditor.quill;
// //
// if (res.code == 200) {
// //
// let length = quill.getSelection().index;
// // res.url
// quill.insertEmbed(length, "image", res.url);
// //
// quill.setSelection(length + 1);
// } else {
// this.$message.error("");
// }
// res
//
let quill = this.$refs.quillEditor.quill;
let toeval = "this.$refs." + this.toref + ".quill";
let quill = eval(toeval);
//
if (res.code == 200) {
//
let length = quill.getSelection().index;
let length = quill.selection.savedRange.index;
// res.url
quill.insertEmbed(length, "image", res.url);
quill.insertEmbed(
length,
"image",
risun.util.nginxServerUrl() + res.fileName
);
//
quill.setSelection(length + 1);
} else {

View File

@ -80,7 +80,7 @@ export default {
},
data() {
return {
title: "幼儿学习与发展档案(教师)",
title: "幼儿学习与发展档案(家长)",
classname: "",
childid: "",
xnxq:"",
@ -109,7 +109,7 @@ export default {
//
xnxqOptions: [],
//
title: "",
// title: "",
//
open: false,
//

View File

@ -383,7 +383,7 @@ export default {
const id = row.id || this.ids;
getActivity(id).then(response => {
this.form = response.data;
console.log(this.form);
// console.log(this.form);
this.typeOptions = response.types;
this.form.type = response.typeIds;