-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnected-tree-node.vue
83 lines (80 loc) · 1.76 KB
/
connected-tree-node.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
<tree-node
:name="name"
:data="data"
:depth="depth"
:expanded="expanded"
:shouldShowArrow="nodeHasChildNodes"
:shouldShowPlaceholder="depth > 0"
:nodeRenderer="nodeRenderer"
@click="onClick"
>
<span v-if="expanded">
<connected-tree-node
v-for="(child, index) of children"
:key="index"
:isNonenumerable="child.isNonenumerable"
:name="child.name"
:data="child.data"
:depth="depth + 1"
:path="`${path}.${child.name}`"
:dataIterator="dataIterator"
:nodeRenderer="nodeRenderer"
:expandedPaths="expandedPaths"
v-on="$listeners"
/>
</span>
<span v-else>null</span>
</tree-node>
</template>
<script>
import TreeNode from './tree-node'
import {
DEFAULT_ROOT_PATH,
hasChildNodes,
getExpandedPaths,
} from '@/libs/pathUtils'
export default {
name: 'connected-tree-node',
components: {
TreeNode,
},
props: {
name: { type: String },
data: { type: null },
dataIterator: { type: Function },
path: { type: String },
depth: { type: Number },
nodeRenderer: { type: Function },
isNonenumerable: { type: Boolean },
expandedPaths: { type: Object },
},
data() {
return {
xx: 11,
}
},
computed: {
nodeHasChildNodes() {
return hasChildNodes(this.data, this.dataIterator)
},
expanded() {
return !!this.expandedPaths[this.path]
},
children() {
return [...this.dataIterator(this.data)]
},
},
methods: {
onClick() {
if (this.nodeHasChildNodes) {
this.$emit('expandedPathsChange', {
path: this.path,
val: !this.expandedPaths[this.path],
})
}
},
},
}
</script>
<style lang="less"></style>