From 920e079727285c5b7ce67641adcee1b2545b9ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 9 Oct 2023 12:00:15 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E5=AF=8C?= =?UTF-8?q?=E6=96=87=E6=9C=ACEditor=E7=BB=84=E4=BB=B6=E6=A3=80=E9=AA=8C?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Editor/index.vue | 40 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/components/Editor/index.vue b/src/components/Editor/index.vue index 6aef16b..b5299b4 100644 --- a/src/components/Editor/index.vue +++ b/src/components/Editor/index.vue @@ -9,13 +9,13 @@ name="file" :show-file-list="false" :headers="upload.headers" - style="display: none" + ref="uploadRef" v-if="type === 'url'" >
({ headers: globalHeaders(), url: import.meta.env.VITE_APP_BASE_API + '/resource/oss/upload' }) -const myQuillEditor = ref(); +const quillEditorRef = ref(); const options = ref({ theme: "snow", @@ -86,7 +86,7 @@ const options = ref({ }, } }, - placeholder: '请输入内容', + placeholder: "请输入内容", readOnly: props.readOnly, }); @@ -110,10 +110,10 @@ watch(() => props.modelValue, (v) => { // 图片上传成功返回图片地址 const handleUploadSuccess = (res: any) => { - // 获取富文本实例 - let quill = toRaw(myQuillEditor.value).getQuill(); // 如果上传成功 if (res.code === 200) { + // 获取富文本实例 + let quill = toRaw(quillEditorRef.value).getQuill(); // 获取光标位置 let length = quill.selection.savedRange.index; // 插入图片,res为服务器返回的图片链接地址 @@ -129,6 +129,13 @@ const handleUploadSuccess = (res: any) => { // 图片上传前拦截 const handleBeforeUpload = (file: any) => { + const type = ["image/jpeg", "image/jpg", "image/png", "image/svg"]; + const isJPG = type.includes(file.type); + //检验文件格式 + if (!isJPG) { + proxy?.$modal.msgError(`图片格式错误!`); + return false; + } // 校检文件大小 if (props.fileSize) { const isLt = file.size / 1024 / 1024 < props.fileSize; @@ -149,95 +156,80 @@ const handleUploadError = (err: any) => {