Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/less/mixins.less
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
&.tree-selected {
background:#efefef;
}
&.tree-determined {
background:#efefef;
}
}

.tree-checkbox {
Expand All @@ -47,6 +50,12 @@
&:hover { background-position:-(@image-height * 7 + @correction) -(@image-height * 1 + @correction); }
}
}
&.tree-checkbox-selection .tree-determined, .tree-checked {
> .tree-checkbox {
background-position:-(@image-height * 6 + @correction) -@correction;
&:hover { background-position:-(@image-height * 6 + @correction) -(@image-height * 1 + @correction); }
}
}
.tree-anchor {
> .tree-undetermined {
background-position:-(@image-height * 6 + @correction) -@correction;
Expand Down
61 changes: 60 additions & 1 deletion src/tree-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
:whole-row="wholeRow"
:show-checkbox="showCheckbox"
:allow-transition="allowTransition"
:allow-batch="allowBatch"
:height= "height"
:parent-item="model[childrenFieldName]"
:draggable="draggable"
Expand All @@ -37,7 +38,10 @@
:on-item-drag-start="onItemDragStart"
:on-item-drag-end="onItemDragEnd"
:on-item-drop="onItemDrop"
:klass="index === model[childrenFieldName].length-1?'tree-last':''">
:klass="index === model[childrenFieldName].length-1?'tree-last':''"
@item-select-toggled="childItemSelectToggled"
@deselectItem="deselectItem"
@selectItem="selectItem">
<template slot-scope="_">
<slot :vm="_.vm" :model="_.model">
<i :class="_.vm.themeIconClasses" role="presentation" v-if="!model.loading"></i>
Expand All @@ -64,6 +68,8 @@
parentItem: {type: Array},
draggable: {type: Boolean, default: false},
dragOverBackgroundColor: {type: String},
allowBatch: {type: Boolean},
semiCheck: {type: Boolean, default: true},
onItemClick: {
type: Function, default: () => false
},
Expand Down Expand Up @@ -107,6 +113,18 @@
this.handleGroupMaxHeight()
},
deep: true
},
'model.selected': {
handler: function (val, oldVal) {
if (this.allowBatch) {
if (!val) {
this.$emit('deselectItem')
} else {
this.$emit('selectItem');
}
}
},
deep: true
}
},
computed: {
Expand All @@ -129,9 +147,14 @@
{'tree-anchor': true},
{'tree-disabled': this.model.disabled},
{'tree-selected': this.model.selected},
{'tree-determined': this.semiCheck && !this.model.selected && this.isDetermined},
{'tree-hovered': this.isHover}
]
},
isDetermined () {
if (!this.semiCheck) return false;
return this.isItemDetermined(this.data);
},
wholeRowClasses () {
return [
{'tree-wholerow': true},
Expand Down Expand Up @@ -169,6 +192,41 @@
}
},
methods: {
deselectItem () {
this.model.selected=false;
},
selectItem () {
if (this.allowBatch && this.model.children && this.model.children.length) {
let isAllChildrenSelected = true;
for (let child of this.model.children) {
if (!child.selected) {
isAllChildrenSelected = false;
break;
}
}
if (isAllChildrenSelected) this.model.selected = true;
}
},
childItemSelectToggled (item) {
if (this.allowBatch) {
if (!item.selected && this.model.selected) {
this.model.selected = false;
}
}
this.$emit('item-select-toggled', this.model);
},
isItemDetermined (item) {
if (item && item.children && item.children.length) {
for (let child of item.children) {
if (child.selected) return true;
if (child.children && child.children.length) {
let isChildDetermined = this.isItemDetermined(child);
if (isChildDetermined) return true;
}
}
}
return false;
},
handleItemToggle (e) {
if (this.isFolder) {
this.model.opened = !this.model.opened
Expand All @@ -195,6 +253,7 @@
if (this.model.disabled) return
this.model.selected = !this.model.selected
this.onItemClick(this, this.model, e)
this.$emit('item-select-toggled', this.model);
},
handleItemMouseOver () {
this.isHover = true
Expand Down
3 changes: 3 additions & 0 deletions src/tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
:whole-row="wholeRow"
:show-checkbox="showCheckbox"
:allow-transition="allowTransition"
:allow-batch="allowBatch"
:semiCheck="semiCheck"
:height="sizeHeight"
:parent-item="data"
:draggable="draggable"
Expand Down Expand Up @@ -54,6 +56,7 @@
textFieldName: {type: String, default: 'text'},
valueFieldName: {type: String, default: 'value'},
childrenFieldName: {type: String, default: 'children'},
semiCheck: {type: Boolean, default: true},
itemEvents: {
type: Object, default: function () {
return {}
Expand Down