From 51615626731e61857c072e259f42b2bb09a82486 Mon Sep 17 00:00:00 2001 From: joey fan Date: Tue, 13 Jun 2023 15:18:45 +0800 Subject: [PATCH] fix: resolve the wrong actual dragging item which drag from outside --- .../components/Example10DragFromOutside.vue | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/website/docs/.vuepress/components/Example10DragFromOutside.vue b/website/docs/.vuepress/components/Example10DragFromOutside.vue index 3fe1f2f2..ecd6f178 100644 --- a/website/docs/.vuepress/components/Example10DragFromOutside.vue +++ b/website/docs/.vuepress/components/Example10DragFromOutside.vue @@ -88,21 +88,20 @@ export default { i: 'drop', }); } - let index = this.layout.findIndex(item => item.i === 'drop'); - if (index !== -1) { + if (this.$refs.gridlayout?.$children.some(el => el.i === 'drop' && !el.$el.classList.contains('vue-grid-placeholder'))) { + let el = this.$refs.gridlayout.$children.find(el => el.i === 'drop' && !el.$el.classList.contains('vue-grid-placeholder')) try { - this.$refs.gridlayout.$children[this.layout.length].$refs.item.style.display = "none"; + el.$refs.item.style.display = "none"; } catch { } - let el = this.$refs.gridlayout.$children[index]; el.dragging = {"top": mouseXY.y - parentRect.top, "left": mouseXY.x - parentRect.left}; let new_pos = el.calcXY(mouseXY.y - parentRect.top, mouseXY.x - parentRect.left); if (mouseInGrid === true) { this.$refs.gridlayout.dragEvent('dragstart', 'drop', new_pos.x, new_pos.y, 1, 1); - DragPos.i = String(index); - DragPos.x = this.layout[index].x; - DragPos.y = this.layout[index].y; + DragPos.i = String(this.layout.length - 1); + DragPos.x = new_pos.x; + DragPos.y = new_pos.y; } if (mouseInGrid === false) { this.$refs.gridlayout.dragEvent('dragend', 'drop', new_pos.x, new_pos.y, 1, 1);