-
Notifications
You must be signed in to change notification settings - Fork 310
/
index.html
95 lines (86 loc) · 2.21 KB
/
index.html
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
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>OrgTree Example</title>
<style>
@import "dist/style.css";
.selected-node {
background: tomato;
}
.bg_node {
cursor: pointer;
}
</style>
</head>
<body>
<div id="app">
<div>
<vue2-org-tree :data="tree" collapsable :label-width="90" :label-class-name="labelClass"
:render-content="renderContent" @on-expand="onExpand" @on-node-click="onNodeClick"
@on-node-mouseover="onNodeMouseOver" @on-node-mouseout="onNodeMouseOut" @on-node-drop="onNodeDrop"
selected-class-name="selected-node" selected-key="selectedKey" />
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="dist/index.js"></script>
<script>
new Vue({
el: '#app',
data: () => ({
tree: {
label: 'Owner',
children: [{
label: 'Label 1'
}, {
label: 'Label 2'
}, {
label: 'Label 3'
}]
}
}),
methods: {
labelClass(data) {
return "bg_node";
},
renderContent(h, data) {
return data.label;
},
onExpand(e, data) {
if ('expand' in data) {
data.expand = !data.expand
if (!data.expand && data.children) {
this.collapse(data.children)
}
} else {
this.$set(data, 'expand', true)
}
},
collapse(nodes) {
nodes.forEach(node => {
if (node.expand) {
node.expand = false
}
node.children && this.collapse(node.children)
})
},
onNodeClick(e, data) {
console.log('CLICK', e);
this.$set(data, 'selectedKey', !data['selectedKey']);
},
onNodeMouseOver(e, data) {
console.log('MOUSE OVER', e, data);
},
onNodeMouseOut(e, data) {
console.log('MOUSE OUT', e);
},
onNodeDrop(e, drag, drop) {
console.log('DROP', e);
console.log('drag:', drag);
console.log('drop:', drop);
}
}
})
</script>
</body>
</html>