Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复富文本编辑器上传图片 #410

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export default defineComponent({

watch(status, (v) => {
if (v === 'edit') {
document.addEventListener('click', handleDocumentClick)
document.addEventListener('click', handleDocumentClick, {capture: true})
} else {
document.removeEventListener('click', handleDocumentClick)
document.removeEventListener('click', handleDocumentClick, {capture: true})
}
})

Expand Down Expand Up @@ -96,7 +96,8 @@ export default defineComponent({

function handleDocumentClick(e) {
const richEditorDOM = moduleTitleRef.value.querySelector('.rich-editor')
const isClickRichEditor = richEditorDOM?.contains(e.target)
const isUploadImage = e.target.type === 'file' && e.target.tagName.toLowerCase() === 'input' // 富文本上传图片点击事件触发到input file 元素上了, 该元素插入到body了
const isClickRichEditor = richEditorDOM?.contains(e.target) || isUploadImage

if (status.value === 'edit' && richEditorDOM && !isClickRichEditor) {
// 监听编辑状态时点击非编辑区域
Expand Down