<template>
<el-tree
:props="props"
:load="loadNode"
:node-key="nodeKey"
@node-click="nodeClick"
:expand-on-click-node="false"
ref="refCom"
lazy>
</el-tree>
</template>
<script>
export default {
props: {
treeName: {
type: String,
default: 'name'
},
nodeKey: {
type: String,
default: 'id'
},
nodeLeaf: {
type: String,
default: 'leaf'
},
},
data() {
return {
props: {
label: this.treeName,
isLeaf: this.nodeLeaf
},
currentKey: '',
}
},
methods: {
loadNode (node, resolve) {
this.$emit('treeBack', node, resolve)
},
nodeClick(data, node) {
if (this.currentKey === this.$refs.refCom.getCurrentKey()) {
this.$refs.refCom.setCurrentKey(data[this.nodeKey])
this.currentKey = ''
} else {
this.currentKey = data[this.nodeKey]
}
this.$emit('nodeClick', data, node)
},
refreshNode(type='childNode', data) {
let currentData = this.$refs.refCom.getCurrentNode()
if(!currentData) currentData = data
let node = this.$refs.refCom.getNode(currentData[this.nodeKey])
if(type === 'childNode') {
node.loaded = false
node.expand()
} else {
node.parent.loaded = false
node.parent.expand()
}
}
}
};
</script>
<style lang="scss" scoped>
// 树样式
.el-tree{
.el-tree-node__content{
background-color: #fff;
padding-left: 0 !important;
}
.el-tree-node__content:hover{
background-color: lightpink;
}
.el-tree-node.is-current>.el-tree-node__content {
background-color: lightpink !important;
}
.el-tree-node__children{
padding: 0;
margin: 0;
width: 100%;
overflow: inherit;
.el-tree-node{
height: auto !important;
padding-left: 15px;
border-left: 1px dashed #d7d7d7;
margin-left: 12px;
position: relative;
background-color: #fff;
&__label {
overflow: hidden;
text-overflow: ellipsis;
}
&::before{
content: '';
position: absolute;
width: 15px;
height: 15px;
left: 0px;
top: -3px;
border-bottom: 1px dashed #d7d7d7;
z-index: inherit;
}
&:last-child{
border-left: 0px;
position: relative;
&::before{
content: '';
position: absolute;
width: 15px;
height: 15px;
left: 0px;
top: -3px;
border-left: 1px dashed #d7d7d7;
border-bottom: 1px dashed #d7d7d7;
z-index: inherit;
}
}
}
}
/deep/ .el-tree-node__expand-icon {
content: url("../Assets/noleaf.png") !important;
font-size: 16px;
}
/deep/ .el-tree-node__expand-icon.is-leaf {
content: url("../Assets/leaf.png") !important;
font-size: 16px;
}
/deep/ .el-tree-node__expand-icon.expanded {
content: url("../Assets/leaf.png") !important;
font-size: 16px;
transform: rotate(0deg) !important;
}
}
</style>