24
24
25
25
ul .ztree {border :1px solid #ddd ;background : #ffffff ;width :100% ;height :auto ;overflow-y :scroll ;overflow-x :auto ;}
26
26
27
- .ztree * {padding :0 ; margin :0 ; font-size :14 px ; font-family : Verdana , Arial , Helvetica , AppleGothic, sans-serif }
27
+ .ztree * {padding :0 ; margin :0 ; font-size :15 px ; font-family : Verdana , Arial , Helvetica , AppleGothic, sans-serif }
28
28
.ztree {margin :0 ; padding :5px ; color :#333 ;}
29
29
.ztree li {position : relative ; padding :0 ; margin :0 ; list-style :none ; line-height :24px ; text-align :left ; white-space :nowrap ; outline :0 }
30
30
.ztree li ul { margin :0 ; padding :0 0 0 18px }
110
110
<template >
111
111
<!-- (ztree-🌲)-->
112
112
<div class =" ztree_content_wrap" >
113
- <div class =" zTreeDemoBackground left" v-if = ' list ' >
113
+ <div class =" zTreeDemoBackground left" >
114
114
<ul class =" ztree" >
115
- <ztree-item v-for =' (i,m) in list ' :model.sync =" m" :num.sync =' i' root =' 0' :nodes.sync =' list .length' :callback =' func' :trees.sync =' list ' ></ztree-item >
115
+ <ztree-item v-for =' (i,m) in treeDataSource ' :model.sync =" m" :num.sync =' i' root =' 0' :nodes.sync =' treeDataSource .length' :callback =' func' :trees.sync =' treeDataSource ' ></ztree-item >
116
116
</ul >
117
117
</div >
118
118
</div >
119
119
</template >
120
120
121
121
<script >
122
+ import Vue from ' vue'
122
123
export default {
124
+ data () {
125
+ return {
126
+ treeDataSource: []
127
+ }
128
+ },
123
129
props: {
124
130
// 树数据
125
131
list: {
@@ -128,24 +134,14 @@ export default{
128
134
},
129
135
// 点击回调
130
136
func: {
131
- type: Function ,
132
- twoWay: true
137
+ type: Function
133
138
},
134
139
// 是否展开
135
140
isOpen: {
136
141
type: Boolean ,
137
- twoWay: true ,
138
142
default: false
139
143
}
140
144
},
141
- watch: {
142
- ' list' : {
143
- handler : function (){
144
- this .initTreeData ();
145
- },
146
- deep: true
147
- }
148
- },
149
145
methods: {
150
146
initTreeData (){
151
147
var vm = this ;
@@ -170,7 +166,7 @@ export default{
170
166
171
167
recurrenceFunc (tempList);
172
168
173
- this .list = tempList;
169
+ this .treeDataSource = tempList;
174
170
}
175
171
},
176
172
components: {
@@ -201,17 +197,12 @@ export default{
201
197
twoWay: true
202
198
},
203
199
callback: {
204
- type: Function ,
205
- twoWay: true
200
+ type: Function
206
201
}
207
202
},
208
203
methods: {
209
204
Func (m ){
210
- if (m .path ){
211
- window .location .href = m .path ;
212
- }else {
213
- this .callback .call (null ,m);
214
- }
205
+ this .callback .call (null ,m);
215
206
216
207
// 查找点击的子节点
217
208
var recurFunc = function (data ){
@@ -258,36 +249,47 @@ export default{
258
249
},
259
250
// 是否有儿子节点
260
251
isChildren : function (){
261
- return this .model . children . length > 0 && this . num + 1 != this .nodes ;
252
+ return this .num + 1 != this .nodes ;
262
253
},
263
254
// 展开/收起
264
255
prefixClass : function (){
265
256
var returnChar = " " ;
266
-
267
257
if (this .rootClass .indexOf (" docu" )== - 1 ){
268
258
if (this .model .isFolder ){
269
- returnChar = " open" ;
259
+ returnChar = " open" ;
270
260
}else {
271
- returnChar = ' close' ;
272
- }
261
+ returnChar = ' close'
262
+ }
273
263
}
274
-
264
+
275
265
if (! this .model .children && this .rootClass .indexOf (" docu" )== - 1 ){
276
- returnChar = ' docu' ;
266
+ returnChar = ' docu'
277
267
}
278
-
268
+
279
269
return returnChar;
270
+ },
271
+ liClassVal : function (){
272
+ return " level" + this .num ;
273
+ },
274
+ spanClassVal : function (){
275
+ return " button level" + this .num + " switch " + this .rootClass + this .prefixClass ;
276
+ },
277
+ aClassVal : function (){
278
+ return this .model .clickNode ? " level" + this .num + ' curSelectedNode' : " level" + this .num ;
279
+ },
280
+ ulClassVal : function (){
281
+ return this .isChildren && this .model .children ? " level" + this .num + ' line' : " level" + this .num ;
280
282
}
281
283
},
282
284
template:
283
- ` <li class="level{{num}} ">
284
- <span class="button level{{num}} switch {{rootClass}}{{prefixClass}} " @click='open(model)'></span>
285
- <a class="level{{num}} {{model.clickNode?'curSelectedNode':''}} " @click='Func(model)'>
286
- <span><img v-if='model.iconPath' :src='model.iconPath' :style='model.iconStyle'></span>
285
+ ` <li : class="liClassVal ">
286
+ <span : class="spanClassVal " @click='open(model)'></span>
287
+ <a : class="aClassVal " @click='Func(model)'>
288
+ <span v-if='model.iconPath'><img :src='model.iconPath' :style='model.iconStyle'></span>
287
289
<span class="node_name">{{model.name}}</span>
288
290
</a>
289
- <ul class="level{{num}} {{isChildren?'line':''}} " v-show='model.isFolder'>
290
- <ztree-item v-for="(i,item) in model.children" :callback.sync ='callback' :model.sync="item" :num.sync='i' root='1' :nodes.sync='model.children.length' :trees.sync='trees'></ztree-item>
291
+ <ul : class="ulClassVal " v-show='model.isFolder'>
292
+ <ztree-item v-for="(i,item) in model.children" :callback='callback' :model.sync="item" :num.sync='i' root='1' :nodes.sync='model.children.length' :trees.sync='trees'></ztree-item>
291
293
</ul>
292
294
</li>`
293
295
}
0 commit comments