Skip to content

Commit 266b60a

Browse files
authored
Merge pull request #4 from halower/master
merge
2 parents 8eb559e + 9dccf65 commit 266b60a

File tree

6 files changed

+133
-123
lines changed

6 files changed

+133
-123
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77
`
88
The document is poorly written and you are welcome to refine your documentation in the process of using it to better help others.
99
`
10-
## Last Version Update Log
11-
  adjusted some style problems, perfected the demo
12-
### (Version 1.5.4)
13-
1. fix bugs that are not selected by some nodes in the radio mode caused by the previous version (1.5.3)
14-
2. perfect Domo Example
15-
### (Version 1.5.3)
16-
1. add  ```canDeleteRoot``` option to support the removal of root nodes
17-
2. fix the ```async``` Invalid bug of the first level node
18-
### (Version 1.5.2)
19-
add a ```node-check``` event, ande remove ```nodeChecked``` event, because the ```nodeChecked``` event may be bubbling
2010
# Version: 2.x  ([中文文档](https://github.com/halower/vue2-tree/blob/master/README_CN.md))
2111
```QQ Group: 255965810``` <br/>
2212
`we guess you may also see` [version 1.0](https://github.com/halower/vue2-tree/tree/1.x)

README_CN.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212
[https://halower.github.io/vue-tree](http://120.77.84.4/)
1313

1414

15-
## Last Version Update Log
16-
1. 修复上一个版本(1.5.3)造成的单选模式下某些节点不能选中的bug
17-
2. 完善domo 示例
18-
### (Version 1.5.3)
19-
1. 新增 ```canDeleteRoot```选项,用以支持是否可以删除根节点
20-
2. 修复一级节点的```async```无效的bug
21-
### (Version 1.5.2)
22-
添加了一个 ```node-check``` 事件, 并移除了原有的```nodeChecked``` 事件,因为```nodeChecked``` 可能存在冒泡出发效果
23-
2415
# SelectTree API (2018-4-15 )
2516
最新的发布版本已经支持下拉树功能, 在基本属性和事件(与 [Tree API](https://github.com/halower/vue-tree/blob/master/README_CN.md#tree-api-%E6%96%87%E6%A1%A3)一致)不变的前提下扩展了如下
2617

dist/v2-tree.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/v2-tree.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-tree-halower",
33
"description": "This tree and treeSelect component is based on the Vue.js 2.0",
4-
"version": "1.7.7",
4+
"version": "1.7.8",
55
"author": "halower (youzisoft@qq.com)",
66
"license": "MIT",
77
"private": false,

src/components/treeLi.vue

Lines changed: 130 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,73 @@
11
<template>
2-
<li
3-
v-if="itemVisible"
4-
:class='liClass'
5-
>
2+
<li v-if="itemVisible" :class="liClass">
63
<div class="tree-node-el" :draggable="draggable" @dragstart="drag(item, $event)">
7-
<span @click="expandNode(item)" v-if="showExpand" class='tree-expand'
4+
<span
5+
@click="expandNode(item)"
6+
v-if="showExpand"
7+
class="tree-expand"
88
:class="item.expanded ? 'tree-open' : 'tree-close'"
9+
></span>
10+
<span
11+
v-if="multiple && !item.nocheck"
12+
:class="[item.checked ? (item.halfcheck ? 'box-halfchecked' : 'box-checked') : 'box-unchecked', 'inputCheck']"
913
>
10-
</span>
11-
<span v-if='multiple && !item.nocheck' :class="[item.checked ? (item.halfcheck ? 'box-halfchecked' : 'box-checked') : 'box-unchecked', 'inputCheck']">
12-
<input :disabled="item.chkDisabled"
14+
<input
15+
:disabled="item.chkDisabled"
1316
:class="['check', item.chkDisabled ? 'chkDisabled' : '']"
14-
v-if='multiple' type="checkbox" @change="changeNodeCheckStatus(item, $event)" :checked="item.checked"/>
17+
v-if="multiple"
18+
type="checkbox"
19+
@change="changeNodeCheckStatus(item, $event)"
20+
:checked="item.checked"
21+
>
1522
</span>
1623
<loading v-if="item.loading && item.expanded"/>
17-
<Render :node="item" :parent='parent' :index='index' :tpl ='tpl' :nodeMouseOver='nodeMouseOver' :level='level'/>
24+
<Render
25+
:node="item"
26+
:parent="parent"
27+
:index="index"
28+
:tpl="tpl"
29+
:nodeMouseOver="nodeMouseOver"
30+
:level="level"
31+
/>
1832
</div>
1933
<template v-if="showNextUl">
2034
<collapse-transition>
2135
<TreeUl
2236
v-show="item.expanded"
2337
:dragAfterExpanded="dragAfterExpanded"
2438
:draggable="draggable"
25-
:tpl ="tpl"
39+
:tpl="tpl"
2640
:data="item.children"
27-
:halfcheck='halfcheck'
28-
:scoped ='scoped'
29-
:parent ='item'
30-
:canDeleteRoot ='canDeleteRoot'
41+
:halfcheck="halfcheck"
42+
:scoped="scoped"
43+
:parent="item"
44+
:canDeleteRoot="canDeleteRoot"
3145
:multiple="multiple"
32-
:level='level'
33-
:maxLevel='maxLevel'
34-
:topMustExpand='topMustExpand'
35-
:allowGetParentNode='allowGetParentNode'
46+
:level="level"
47+
:maxLevel="maxLevel"
48+
:topMustExpand="topMustExpand"
49+
:allowGetParentNode="allowGetParentNode"
3650
/>
3751
</collapse-transition>
3852
</template>
3953
</li>
4054
</template>
4155
<script>
42-
import mixins from './mixins'
43-
import Render from './render'
44-
import Loading from './loading'
45-
import CollapseTransition from './collapse-transition'
56+
import mixins from "./mixins";
57+
import Render from "./render";
58+
import Loading from "./loading";
59+
import CollapseTransition from "./collapse-transition";
4660
export default {
47-
name: 'TreeLi',
61+
name: "TreeLi",
4862
mixins: [mixins],
49-
components: {Render, Loading, CollapseTransition,
63+
components: {
64+
Render,
65+
Loading,
66+
CollapseTransition
5067
// TreeUl: () => import('./treeUl.vue') // 解决循环引用的问题
5168
},
5269
beforeCreate() {
53-
this.$options.components.TreeUl = require('./treeUl.vue').default
70+
this.$options.components.TreeUl = require("./treeUl.vue").default;
5471
},
5572
props: {
5673
item: {
@@ -94,60 +111,73 @@ export default {
94111
maxLevel: Number,
95112
level: Number,
96113
topMustExpand: Boolean,
97-
allowGetParentNode: Boolean,
114+
allowGetParentNode: Boolean
98115
},
99-
inject:['isLeaf', 'childChecked', 'parentChecked', 'nodeSelected', 'emitEventToTree', 'setAttr'],
116+
inject: [
117+
"isLeaf",
118+
"childChecked",
119+
"parentChecked",
120+
"nodeSelected",
121+
"emitEventToTree",
122+
"setAttr"
123+
],
100124
computed: {
101125
itemVisible() {
102-
const {visible = true} = this.item
103-
return visible
126+
const { visible = true } = this.item;
127+
return visible;
104128
},
105-
hasExpended() { // 已经展开过
106-
let {hasExpended = false, expanded = false} = this.item
107-
return this.itemVisible && (expanded || hasExpended)
129+
hasExpended() {
130+
// 已经展开过
131+
let { hasExpended = false, expanded = false } = this.item;
132+
return this.itemVisible && (expanded || hasExpended);
108133
},
109-
liClass (){
110-
const index = this.index
111-
let res
134+
liClass() {
135+
const index = this.index;
136+
let res;
112137
if (this.parent) {
113138
res = {
114-
leaf: this.isLeaf(this.item),
115-
}
116-
} else { // top node
139+
leaf: this.isLeaf(this.item)
140+
};
141+
} else {
142+
// top node
117143
res = {
118-
'first-node': index === 0,
119-
'only-node': this.dataLength === 1,
120-
'second-node': index === 1
121-
}
144+
"first-node": index === 0,
145+
"only-node": this.dataLength === 1,
146+
"second-node": index === 1
147+
};
122148
}
123-
return res
124-
},
125-
hasChildren () {
126-
const item = this.item
127-
return item.children && item.children.length > 0
128-
},
129-
showExpand () {
130-
const item = this.item
131-
const isShow = !this.parent ? this.topMustExpand : false
132-
return isShow || this.hasChildren || item.async
133-
},
134-
showNextUl () {
135-
return !this.isLeaf(this.item) && this.maxLevel > this.level && this.hasExpended
136-
},
137-
position () {
138-
return {level: this.level, index: this.index}
149+
return res;
150+
},
151+
hasChildren() {
152+
const item = this.item;
153+
return item.children && item.children.length > 0;
154+
},
155+
showExpand() {
156+
const item = this.item;
157+
const isShow = !this.parent ? this.topMustExpand : false;
158+
return isShow || this.hasChildren || item.async;
159+
},
160+
showNextUl() {
161+
return (
162+
!this.isLeaf(this.item) &&
163+
this.maxLevel > this.level &&
164+
this.hasExpended
165+
);
166+
},
167+
position() {
168+
return { level: this.level, index: this.index };
139169
}
140170
},
141171
watch: {
142-
'item.checked': {
143-
handler () {
144-
this.checkedChange()
172+
"item.checked": {
173+
handler() {
174+
this.checkedChange();
145175
},
146176
immediate: true
147177
},
148-
'item.halfcheck': {
149-
handler () {
150-
this.checkedChange()
178+
"item.halfcheck": {
179+
handler() {
180+
this.checkedChange();
151181
},
152182
immediate: true
153183
}
@@ -156,66 +186,65 @@ export default {
156186
/* @method drag node
157187
* @param node draged node
158188
* @param ev $event
159-
*/
160-
drag (node, ev) {
161-
let guid = this.guid()
162-
this.setDragNode(guid, node, this.parent)
163-
ev.dataTransfer.setData('guid', guid)
189+
*/
190+
drag(node, ev) {
191+
let guid = this.guid();
192+
this.setDragNode(guid, node, this.parent);
193+
ev.dataTransfer.setData("guid", guid);
164194
},
165195
/* @method expand or close node
166196
* @param node current node
167-
*/
168-
expandNode (node) {
169-
const expended = !node.expanded
170-
this.setAttr(node, 'expanded', expended)
171-
this.setAttr(node, 'hasExpended', true)
197+
*/
198+
expandNode(node) {
199+
const expended = !node.expanded;
200+
this.setAttr(node, "expanded", expended);
201+
this.setAttr(node, "hasExpended", true);
172202
if (node.async && !node.children) {
173-
this.emitEventToTree('async-load-nodes', node)
203+
this.emitEventToTree("async-load-nodes", node);
174204
}
175-
this.emitEventToTree('node-expand', node, expended, this.position)
205+
this.emitEventToTree("node-expand", node, expended, this.position);
176206
},
177207
/* @event passing the node-check event to the parent component
178208
* @param node clicked node
179209
*/
180-
nodeCheck (node, checked) {
181-
this.$set(node, 'checked', checked)
182-
const halfcheck = this.halfcheck
183-
if (halfcheck) {
184-
this.$set(node, 'halfcheck', false)
185-
}
210+
nodeCheck(node, checked) {
211+
this.$set(node, "checked", checked);
186212
if (!this.scoped) {
187-
this.childChecked(node, checked, halfcheck)
188-
// this.theParentChecked(checked, halfcheck)
213+
const halfcheck = this.halfcheck;
214+
if (halfcheck) {
215+
this.$set(node, "halfcheck", false);
216+
}
217+
this.childChecked(node, checked, halfcheck);
189218
}
190219
},
191220
/* @event passing the node-mouse-over event to the parent component
192221
* @param node overed node
193222
*/
194-
nodeMouseOver (node, index, parent) {
195-
this.emitEventToTree('node-mouse-over', node, index, parent)
223+
nodeMouseOver(node, index, parent) {
224+
this.emitEventToTree("node-mouse-over", node, index, parent);
196225
// this.$emit('node-mouse-over', node)
197226
},
198227
/*
199228
*@method change the check box status method
200229
*@param node current node
201230
*@param $event event object
202231
*/
203-
changeNodeCheckStatus (node, $event) {
204-
const checked = $event.target.checked
205-
this.nodeCheck(node, checked)
206-
this.emitEventToTree('node-check', node, checked, this.position)
207-
},
208-
theParentChecked(checked, halfcheck){
209-
const parentNode = this.parent
210-
this.parentChecked(parentNode, checked, halfcheck)
211-
},
212-
checkedChange () {
213-
const {checked = false} = this.item
214-
this.theParentChecked(checked, this.halfcheck)
232+
changeNodeCheckStatus(node, $event) {
233+
const checked = $event.target.checked;
234+
this.nodeCheck(node, checked);
235+
this.emitEventToTree("node-check", node, checked, this.position);
236+
},
237+
theParentChecked(checked, halfcheck) {
238+
const parentNode = this.parent;
239+
this.parentChecked(parentNode, checked, halfcheck);
240+
},
241+
checkedChange() {
242+
const { checked = false } = this.item;
243+
this.theParentChecked(checked, this.halfcheck);
215244
// if (!checked) {
216245
// this.$set(this.item, 'selected', checked)
217246
// }
218-
},
247+
}
219248
}
220-
}
249+
};
221250
</script>

0 commit comments

Comments
 (0)