2016-07-27 06:15:02 +00:00
|
|
|
<template>
|
2016-10-17 16:31:37 +00:00
|
|
|
<div class="el-tree" :class="{ 'el-tree--highlight-current': highlightCurrent }">
|
|
|
|
<el-tree-node
|
|
|
|
v-for="child in tree.root.childNodes"
|
|
|
|
:node="child"
|
|
|
|
:props="props"
|
|
|
|
:render-content="renderContent">
|
|
|
|
</el-tree-node>
|
2016-11-16 07:35:46 +00:00
|
|
|
<div class="el-tree__empty-block" v-if="!tree.root.childNodes || tree.root.childNodes.length === 0">
|
|
|
|
<span class="el-tree__empty-text">{{ emptyText }}</span>
|
|
|
|
</div>
|
2016-07-27 06:15:02 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script type="text/ecmascript-6">
|
|
|
|
import Tree from './model/tree';
|
2016-11-16 07:35:46 +00:00
|
|
|
import { t } from 'element-ui/src/locale';
|
2016-07-27 06:15:02 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'el-tree',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
data: {
|
|
|
|
type: Array
|
|
|
|
},
|
2016-11-16 07:35:46 +00:00
|
|
|
emptyText: {
|
|
|
|
type: String,
|
2016-11-17 07:37:04 +00:00
|
|
|
default() {
|
|
|
|
return t('el.tree.emptyText');
|
|
|
|
}
|
2016-11-16 07:35:46 +00:00
|
|
|
},
|
|
|
|
nodeKey: String,
|
|
|
|
checkStrictly: Boolean,
|
|
|
|
defaultExpandAll: Boolean,
|
|
|
|
autoExpandParent: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
defaultCheckedKeys: Array,
|
|
|
|
defaultExpandedKeys: Array,
|
2016-10-17 16:31:37 +00:00
|
|
|
renderContent: Function,
|
2016-07-27 06:15:02 +00:00
|
|
|
showCheckbox: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
default() {
|
|
|
|
return {
|
|
|
|
children: 'children',
|
|
|
|
label: 'label',
|
|
|
|
icon: 'icon'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
lazy: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2016-10-17 16:31:37 +00:00
|
|
|
highlightCurrent: Boolean,
|
2016-11-21 16:08:22 +00:00
|
|
|
load: Function,
|
|
|
|
filterNodeMethod: Function
|
2016-07-27 06:15:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.$isTree = true;
|
|
|
|
|
|
|
|
this.tree = new Tree({
|
2016-11-16 07:35:46 +00:00
|
|
|
key: this.nodeKey,
|
2016-07-27 06:15:02 +00:00
|
|
|
data: this.data,
|
|
|
|
lazy: this.lazy,
|
|
|
|
props: this.props,
|
2016-11-16 07:35:46 +00:00
|
|
|
load: this.load,
|
|
|
|
checkStrictly: this.checkStrictly,
|
|
|
|
defaultCheckedKeys: this.defaultCheckedKeys,
|
|
|
|
defaultExpandedKeys: this.defaultExpandedKeys,
|
|
|
|
autoExpandParent: this.autoExpandParent,
|
2016-11-21 16:08:22 +00:00
|
|
|
defaultExpandAll: this.defaultExpandAll,
|
|
|
|
filterNodeMethod: this.filterNodeMethod
|
2016-07-27 06:15:02 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2016-10-17 16:31:37 +00:00
|
|
|
tree: {},
|
|
|
|
currentNode: null
|
2016-07-27 06:15:02 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
ElTreeNode: require('./tree-node.vue')
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
children: {
|
|
|
|
set(value) {
|
|
|
|
this.data = value;
|
|
|
|
},
|
|
|
|
get() {
|
|
|
|
return this.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-08 05:58:31 +00:00
|
|
|
watch: {
|
|
|
|
data(newVal) {
|
2016-11-16 07:35:46 +00:00
|
|
|
this.tree.setData(newVal);
|
|
|
|
},
|
|
|
|
defaultCheckedKeys(newVal) {
|
|
|
|
this.tree.setDefaultCheckedKey(newVal);
|
2016-10-08 05:58:31 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-27 06:15:02 +00:00
|
|
|
methods: {
|
2016-11-21 16:08:22 +00:00
|
|
|
filter(value) {
|
|
|
|
if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
|
|
|
|
this.tree.filter(value);
|
|
|
|
},
|
2016-07-27 06:15:02 +00:00
|
|
|
getCheckedNodes(leafOnly) {
|
|
|
|
return this.tree.getCheckedNodes(leafOnly);
|
2016-11-16 07:35:46 +00:00
|
|
|
},
|
2016-11-21 13:53:55 +00:00
|
|
|
getCheckedKeys(leafOnly) {
|
|
|
|
return this.tree.getCheckedKeys(leafOnly);
|
|
|
|
},
|
|
|
|
setCheckedNodes(nodes, leafOnly) {
|
|
|
|
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
|
|
|
|
this.tree.setCheckedNodes(nodes, leafOnly);
|
|
|
|
},
|
|
|
|
setCheckedKeys(keys, leafOnly) {
|
2016-11-16 07:35:46 +00:00
|
|
|
if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
|
2016-11-21 13:53:55 +00:00
|
|
|
this.tree.setCheckedKeys(keys, leafOnly);
|
2016-07-27 06:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|