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
96
97
| <template>
| <div>
| <ul :id="id" class="ztree" />
| </div>
| </template>
|
| <script>
| import $ from 'jquery'
| import '@/plugins/ztree/js/jquery-1.4.4.min.js'
| import '@/plugins/ztree/js/jquery.ztree.core.min.js'
| import '@/plugins/ztree/js/jquery.ztree.excheck.js'
|
| export default {
| props: {
| // 数据源
| nodes: {
| type: Array,
| default: function() {
| return []
| }
| },
| // 是否全部展开
| expandAll: {
| type: Boolean,
| default: true
| }
| },
| data() {
| return {
| id: 'treeDemo',
| setting: {
| check: {
| enable: true,
| chkboxType: { 'Y': 'ps', 'N': 's' }
| },
| data: {
| simpleData: {
| enable: true,
| idKey: 'id',
| pIdKey: 'pid',
| rootPId: 0
| }
| },
| view: {
| showIcon: false,
| showLine: false
| }
| },
| zNodes: []
| }
| },
| watch: {
| nodes(v) {
| this.init(v)
| }
| },
| mounted() {
| this.id = 'treeDemo' + new Date().getTime()
| // console.log(this.id)
| this.$nextTick(() => {
| this.init(this.nodes)
| })
| },
| methods: {
| /*
| * @Author : liu.q [916000612@qq.com]
| * @Date : 2019-07-01 17:11
| * @Description : 初始化树
| */
| init(v) {
| this.zNodes = v
| window.$.fn.zTree.init($('#' + this.id), this.setting, this.zNodes)
|
| if (this.expandAll) {
| this.$nextTick(() => {
| const treeObj = window.$.fn.zTree.getZTreeObj(this.id)
| treeObj.expandAll(true)
| })
| }
| },
| /*
| * @Author : liu.q [916000612@qq.com]
| * @Date : 2019-07-01 15:12
| * @Description : 获取选中节点
| */
| getCheckedNodes() {
| const treeObj = window.$.fn.zTree.getZTreeObj(this.id)
| const nodes = treeObj.getCheckedNodes(true)
| return nodes
| }
| }
| }
| </script>
|
| <style scoped>
| @import "../../../plugins/ztree/css/zTreeStyle/zTreeStyle.css";
| </style>
|
|