Skip to content

Commit

Permalink
fix: 拖拽入图片导致生成 base64 字符图片 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
linfaxin committed Aug 11, 2024
1 parent 0c8a396 commit 9ef5a45
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions web/src/components/vditor/initVditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,33 +262,37 @@ export default function initVditor(div: HTMLElement, param: InitVditorOption) {
);

// 支持拖拽入图片/附件
vditor.vditor.wysiwyg?.element.addEventListener('drop', (e) => {
if (e.dataTransfer?.items?.length) {
const imgFiles: File[] = [];
const attachmentFiles: File[] = [];
vditor.vditor.wysiwyg?.element.addEventListener(
'drop',
(e) => {
if (e.dataTransfer?.items?.length) {
const imgFiles: File[] = [];
const attachmentFiles: File[] = [];

Array.from(e.dataTransfer.items).forEach((i) => {
const file = i.getAsFile();
if (!file) return;
if (/^image\//.test(i.type)) {
imgFiles.push(file);
} else {
attachmentFiles.push(file);
}
});
Array.from(e.dataTransfer.items).forEach((i) => {
const file = i.getAsFile();
if (!file) return;
if (/^image\//.test(i.type)) {
imgFiles.push(file);
} else {
attachmentFiles.push(file);
}
});

if (imgFiles.length && doUploadAndInsertImage) {
e.stopPropagation();
e.preventDefault();
doUploadAndInsertImage(imgFiles as File[]);
}
if (attachmentFiles.length && doUploadAndInsertFiles) {
e.stopPropagation();
e.preventDefault();
doUploadAndInsertFiles(attachmentFiles as File[]);
if (imgFiles.length && doUploadAndInsertImage) {
e.stopPropagation();
e.preventDefault();
doUploadAndInsertImage(imgFiles as File[]);
}
if (attachmentFiles.length && doUploadAndInsertFiles) {
e.stopPropagation();
e.preventDefault();
doUploadAndInsertFiles(attachmentFiles as File[]);
}
}
}
});
},
true,
);

if (vditor.vditor.wysiwyg) {
let afterRenderTimeoutId: number;
Expand Down

0 comments on commit 9ef5a45

Please sign in to comment.