feat: Emit events for node operations
This commit is contained in:
@@ -164,13 +164,18 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateName (e) {
|
updateName (e) {
|
||||||
|
var oldName = this.model.name;
|
||||||
this.model.changeName(e.target.value)
|
this.model.changeName(e.target.value)
|
||||||
|
var node = this.getRootNode();
|
||||||
|
node.$emit('change-name', {'id': this.model.id, 'oldName': oldName, 'newName': e.target.value})
|
||||||
},
|
},
|
||||||
|
|
||||||
delNode () {
|
delNode () {
|
||||||
const vm = this
|
const vm = this
|
||||||
const confirm = () => vm.model.remove()
|
const confirm = () => vm.model.remove()
|
||||||
this.onDeleteNode(confirm)
|
this.onDeleteNode(confirm)
|
||||||
|
var node = this.getRootNode()
|
||||||
|
node.$emit('delete-node', this.model)
|
||||||
},
|
},
|
||||||
|
|
||||||
setEditable () {
|
setEditable () {
|
||||||
@@ -201,12 +206,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
click() {
|
click() {
|
||||||
var node = this.$parent
|
var node = this.getRootNode()
|
||||||
var clickModel = this.model
|
node.$emit('click', this.model);
|
||||||
while (node._props.model.name !== 'root') {
|
|
||||||
node = node.$parent
|
|
||||||
}
|
|
||||||
node.$emit('click', clickModel)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
addChild(isLeaf) {
|
addChild(isLeaf) {
|
||||||
@@ -214,6 +215,8 @@
|
|||||||
this.expanded = true
|
this.expanded = true
|
||||||
var node = new TreeNode({ name, isLeaf })
|
var node = new TreeNode({ name, isLeaf })
|
||||||
this.model.addChildren(node, true)
|
this.model.addChildren(node, true)
|
||||||
|
var root = this.getRootNode();
|
||||||
|
root.$emit('new-node', node)
|
||||||
},
|
},
|
||||||
|
|
||||||
dragStart(e) {
|
dragStart(e) {
|
||||||
@@ -281,6 +284,13 @@
|
|||||||
if (!fromComp) return
|
if (!fromComp) return
|
||||||
fromComp.model.insertAfter(this.model)
|
fromComp.model.insertAfter(this.model)
|
||||||
this.isDragEnterBottom = false
|
this.isDragEnterBottom = false
|
||||||
|
},
|
||||||
|
getRootNode() {
|
||||||
|
var node = this.$parent
|
||||||
|
while (node._props.model.name !== 'root') {
|
||||||
|
node = node.$parent
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeCreate () {
|
beforeCreate () {
|
||||||
|
Reference in New Issue
Block a user