fix: prevent modal from closing when text selection extends beyond dialog boundary

This commit is contained in:
Andy Yang
2026-03-02 15:19:47 +08:00
committed by lyingbug
parent 51d23fca2c
commit c989c57812
+14 -1
View File
@@ -1,7 +1,7 @@
<template>
<Teleport to="body">
<Transition name="modal">
<div v-if="dialogVisible" class="model-editor-overlay" @click.self="handleCancel">
<div v-if="dialogVisible" class="model-editor-overlay" @mousedown.self="handleOverlayMouseDown" @mouseup.self="handleOverlayMouseUp">
<div class="model-editor-modal">
<!-- 关闭按钮 -->
<button class="close-btn" @click="handleCancel" :aria-label="$t('common.close')">
@@ -992,6 +992,19 @@ watch(() => formData.value.modelName, () => {
const handleCancel = () => {
dialogVisible.value = false
}
// 遮罩层点击关闭:只有 mousedown 和 mouseup 都发生在遮罩层上才关闭,
// 防止在输入框中拖选文字时鼠标滑出弹窗导致误关闭
let overlayMouseDownFired = false
const handleOverlayMouseDown = () => {
overlayMouseDownFired = true
}
const handleOverlayMouseUp = () => {
if (overlayMouseDownFired) {
handleCancel()
}
overlayMouseDownFired = false
}
</script>
<style lang="less" scoped>