From 78c16c10168f8c16c19e36a0f313cdce4805e919 Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Sat, 5 Apr 2025 15:09:22 +0800 Subject: [PATCH] =?UTF-8?q?update:=20TinyMCE=E4=B8=8A=E4=BC=A0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=A7=BB=E9=99=A4=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/tinymce/src/editor.vue | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/web-antd/src/components/tinymce/src/editor.vue b/apps/web-antd/src/components/tinymce/src/editor.vue index b2c1f9ae..708a5416 100644 --- a/apps/web-antd/src/components/tinymce/src/editor.vue +++ b/apps/web-antd/src/components/tinymce/src/editor.vue @@ -2,7 +2,7 @@ import type { IPropTypes } from '@tinymce/tinymce-vue/lib/cjs/main/ts/components/EditorPropTypes'; import type { Editor as EditorType } from 'tinymce/tinymce'; -import type { UploadResult } from '#/api'; +import type { AxiosProgressEvent, UploadResult } from '#/api'; import { computed, nextTick, ref, shallowRef, useAttrs, watch } from 'vue'; @@ -121,6 +121,7 @@ const initOptions = computed((): InitOptions => { * images_upload_handler启用时为上传 */ paste_data_images: true, + images_file_types: 'jpeg,jpg,png,gif,bmp,webp', plugins, quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable', @@ -133,12 +134,18 @@ const initOptions = computed((): InitOptions => { * @param blobInfo * 大坑 不要调用这两个函数 success failure: * 使用resolve/reject代替 + * (PS: 新版已经没有success failure) */ - images_upload_handler: (blobInfo) => { + images_upload_handler: (blobInfo, progress) => { return new Promise((resolve, reject) => { const file = blobInfo.blob(); // const filename = blobInfo.filename(); - uploadApi(file) + // 进度条事件 + const progressEvent: AxiosProgressEvent = (e) => { + const percent = Math.trunc((e.loaded / e.total!) * 100); + progress(percent); + }; + uploadApi(file, { onUploadProgress: progressEvent }) .then((response) => { const { url } = response as unknown as UploadResult; console.log('tinymce上传图片:', url); @@ -146,7 +153,8 @@ const initOptions = computed((): InitOptions => { }) .catch((error) => { console.error('tinymce上传图片失败:', error); - reject(error.message); + // eslint-disable-next-line prefer-promise-reject-errors + reject({ message: error.message, remove: true }); }); }); },