解决事件泄漏问题
This commit is contained in:
@@ -155,6 +155,7 @@ const activeTabIndex = ref(-1)
|
||||
// 拖拽相关状态
|
||||
let isDragging = false
|
||||
let dragIndex = -1
|
||||
let currentDragId = null
|
||||
|
||||
// 计算属性:获取插槽项的props
|
||||
const slotItems = computed(() => {
|
||||
@@ -198,12 +199,18 @@ const onTabDragStart = (index, event) => {
|
||||
isDragging = true
|
||||
dragIndex = index
|
||||
|
||||
// 传递标签页索引和鼠标位置
|
||||
// 生成统一的 dragId
|
||||
currentDragId = `tabpage_${props.id}_${index}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`
|
||||
|
||||
// 传递标签页索引和鼠标位置,包含 dragId
|
||||
emitEvent(EVENT_TYPES.TAB_DRAG_START, {
|
||||
dragId: currentDragId,
|
||||
clientX: event.clientX,
|
||||
clientY: event.clientY,
|
||||
tabIndex: index,
|
||||
tabId: $slots.default()[index]?.props?.id
|
||||
}, {
|
||||
source: { component: 'TabPage', tabPageId: props.id, tabIndex: index, dragId: currentDragId }
|
||||
})
|
||||
|
||||
// 防止文本选择和默认行为
|
||||
@@ -219,11 +226,12 @@ const onTabDragStart = (index, event) => {
|
||||
|
||||
// 标签拖拽移动
|
||||
const onTabDragMove = (event) => {
|
||||
if (isDragging) {
|
||||
if (isDragging && currentDragId) {
|
||||
// 防止文本选择和默认行为
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
emitEvent(EVENT_TYPES.TAB_DRAG_MOVE, {
|
||||
dragId: currentDragId,
|
||||
clientX: event.clientX,
|
||||
clientY: event.clientY,
|
||||
tabIndex: dragIndex
|
||||
@@ -233,10 +241,14 @@ const onTabDragMove = (event) => {
|
||||
|
||||
// 标签拖拽结束
|
||||
const onTabDragEnd = () => {
|
||||
if (isDragging) {
|
||||
if (isDragging && currentDragId) {
|
||||
isDragging = false
|
||||
emitEvent(EVENT_TYPES.TAB_DRAG_END, { tabIndex: dragIndex })
|
||||
emitEvent(EVENT_TYPES.TAB_DRAG_END, {
|
||||
dragId: currentDragId,
|
||||
tabIndex: dragIndex
|
||||
})
|
||||
dragIndex = -1
|
||||
currentDragId = null
|
||||
|
||||
// 拖拽结束后移除事件监听器
|
||||
document.removeEventListener('mousemove', onTabDragMove)
|
||||
|
||||
Reference in New Issue
Block a user