Skip to content

Commit 6832f85

Browse files
committed
disable nodeback when drag
1 parent 782e330 commit 6832f85

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/examples/NodeBack.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import Tree from '@/components/Tree.vue'
2121
import fold from '@/plugins/fold.js'
2222
import check from '@/plugins/check.js'
2323
import NodeBack from '@/plugins/NodeBack.vue'
24+
import Draggable from '@/plugins/draggable/Draggable.vue'
2425
25-
const MixedTree = Tree.mixPlugins([fold, check, NodeBack])
26+
const MixedTree = Tree.mixPlugins([fold, check, NodeBack, Draggable])
2627
2728
export default {
2829
components: {Tree: MixedTree},

src/plugins/NodeBack.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<script>
22
import * as hp from 'helper-js'
33
export default {
4+
data() {
5+
return {
6+
nodeBackEnabled: true,
7+
}
8+
},
49
methods: {
510
showNodeBack(path, opt = {}) {
611
/*
712
opt
813
persistent
914
*/
15+
if (!this.nodeBackEnabled) {
16+
// disabled
17+
return
18+
}
1019
let nodeEl = opt.nodeEl
1120
if (!nodeEl) {
1221
// get by path
@@ -63,6 +72,15 @@ export default {
6372
}
6473
}
6574
},
75+
enableNodeBack() {
76+
this.nodeBackEnabled = true
77+
},
78+
disableNodeBack() {
79+
for (const {value: el} of hp.iterateALL(this.$el.querySelectorAll(`.node-back`))) {
80+
hp.removeEl(el)
81+
}
82+
this.nodeBackEnabled = false
83+
},
6684
},
6785
mounted() {
6886
const onmouseover = (e) => {
@@ -88,6 +106,19 @@ export default {
88106
hp.offDOM(this.$el, 'mouseover', onmouseover)
89107
}
90108
this.$on('hook:beforeDestroy', destroy)
109+
//
110+
const ondrag = () => {
111+
this.disableNodeBack()
112+
}
113+
const ondrop = () => {
114+
this.enableNodeBack()
115+
}
116+
this.$root.$on('he-tree-drag', ondrag)
117+
this.$root.$on('he-tree-drop', ondrop)
118+
this.$on('hook:beforeDestroy', () => {
119+
this.$root.$off('he-tree-drag', ondrag)
120+
this.$root.$off('he-tree-drop', ondrop)
121+
})
91122
},
92123
}
93124
</script>

src/plugins/draggable/Draggable.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export default {
184184
return false
185185
}
186186
store.startTree.$emit('drag', store)
187+
this.$root.$emit('he-tree-drag', store)
187188
},
188189
filterTargetTree: (targetTreeEl, store) => {
189190
const targetTree = this.getTreeVmByTreeEl(targetTreeEl)
@@ -206,6 +207,7 @@ export default {
206207
return false
207208
}
208209
targetTree.$emit('drop', store)
210+
this.$root.$emit('he-tree-drop', store)
209211
},
210212
ondrop: (store, t) => {
211213
if (store.pathChanged) {

0 commit comments

Comments
 (0)