update Tree

update Tree
This commit is contained in:
梁灏 2017-02-07 15:29:53 +08:00
parent b566d106c5
commit ce03ac5278
4 changed files with 23 additions and 35 deletions

View file

@ -17,7 +17,7 @@
v-if="!item.isLeaf" v-if="!item.isLeaf"
v-show="item.expand" v-show="item.expand"
:class="expandCls(item)" :class="expandCls(item)"
:data.sync="item.node" :data.sync="item.children"
:key="this.key+'.'+$index" :key="this.key+'.'+$index"
:multiple="multiple" :multiple="multiple"
:show-checkbox="showCheckbox" :show-checkbox="showCheckbox"
@ -54,18 +54,6 @@
type: Boolean, type: Boolean,
default: false default: false
}, },
onSelect: {
type: Function,
default () {
return {};
}
},
onCheck: {
type: Function,
default () {
return {};
}
},
emptyText: { emptyText: {
type: String, type: String,
default () { default () {
@ -135,7 +123,7 @@
}, },
preHandle () { preHandle () {
for (let [i,item] of this.data.entries()) { for (let [i,item] of this.data.entries()) {
if (!item.node || !item.node.length) { if (!item.children || !item.children.length) {
this.$set(`data[${i}].isLeaf`, true); this.$set(`data[${i}].isLeaf`, true);
this.$set(`data[${i}].childrenCheckedStatus`, 2); this.$set(`data[${i}].childrenCheckedStatus`, 2);
continue; continue;
@ -144,7 +132,7 @@
this.$set(`data[${i}].childrenCheckedStatus`, 2); this.$set(`data[${i}].childrenCheckedStatus`, 2);
this.$broadcast('parentChecked', true, `${this.key}.${i}`); this.$broadcast('parentChecked', true, `${this.key}.${i}`);
} else { } else {
let status = this.getChildrenCheckedStatus(item.node); let status = this.getChildrenCheckedStatus(item.children);
this.$set(`data[${i}].childrenCheckedStatus`, status); this.$set(`data[${i}].childrenCheckedStatus`, status);
if (status !== 0) this.$set(`data[${i}].checked`, true); if (status !== 0) this.$set(`data[${i}].checked`, true);
} }
@ -194,8 +182,8 @@
if (tmp) { if (tmp) {
res.push(node); res.push(node);
} }
if (node.node && node.node.length) { if (node.children && node.children.length) {
res = res.concat(this.getNodes(node.node, opt)); res = res.concat(this.getNodes(node.children, opt));
} }
} }
return res; return res;
@ -241,11 +229,9 @@
} }
this.$broadcast('cancelSelected', ori); this.$broadcast('cancelSelected', ori);
} }
if (this.onSelect) { this.$nextTick(() => {
this.$nextTick(() => { this.$emit('on-select-change', this.getSelectedNodes());
this.onSelect(this.getSelectedNodes()); });
});
}
}); });
this.$on('cancelSelected', ori => { this.$on('cancelSelected', ori => {
this.$broadcast('cancelSelected', ori); this.$broadcast('cancelSelected', ori);
@ -265,15 +251,15 @@
} }
}); });
this.$on('childChecked', (ori, key) => { this.$on('childChecked', (ori, key) => {
if (this.key === '0' && this.onCheck) { if (this.key === '0') {
this.$nextTick(() => { this.$nextTick(() => {
this.onCheck(this.getCheckedNodes()); this.$emit('on-check-change', this.getCheckedNodes());
}); });
} }
if (this === ori) return; if (this === ori) return;
for (let [i,item] of this.data.entries()) { for (let [i,item] of this.data.entries()) {
if (this.key + '.' + i == key) { if (this.key + '.' + i == key) {
let temp = this.getChildrenCheckedStatus(item.node); let temp = this.getChildrenCheckedStatus(item.children);
if (temp != item.childrenCheckedStatus) { if (temp != item.childrenCheckedStatus) {
this.$set(`data[${i}].checked`, !!temp); this.$set(`data[${i}].checked`, !!temp);
this.$set(`data[${i}].childrenCheckedStatus`, temp); this.$set(`data[${i}].childrenCheckedStatus`, temp);

View file

@ -1 +1,2 @@
@checkbox-prefix-cls: ~"@{css-prefix}checkbox";
.checkboxFn(); .checkboxFn();

View file

@ -61,10 +61,10 @@
background-color: tint(@primary-color, 80%); background-color: tint(@primary-color, 80%);
} }
} }
.@{checkbox-prefix-cls}-wrapper{
margin-right: 4px;
}
span { span {
&.@{tree-prefix-cls}-checkbox {
margin: 2px 4px 0 0;
}
&.@{tree-prefix-cls}-switcher, &.@{tree-prefix-cls}-switcher,
&.@{tree-prefix-cls}-iconEle { &.@{tree-prefix-cls}-iconEle {
display: inline-block; display: inline-block;

View file

@ -3,21 +3,22 @@
:data.sync="treeData" :data.sync="treeData"
:show-checkbox="true" :show-checkbox="true"
:multiple="true" :multiple="true"
:on-select="selectFn" @on-select-change="selectFn"
:on-check="checkFn"></Tree> @on-check-change="checkFn"></Tree>
</template> </template>
<script> <script>
export default { export default {
data: function() { data: function() {
return { return {
treeData: [{ treeData: [{
expand: true,
title: 'parent 1', title: 'parent 1',
selected: false, selected: false,
node: [{ children: [{
title: 'parent 1-0', title: 'parent 1-0',
expand: true, expand: true,
disabled: true, disabled: true,
node: [{ children: [{
title: 'leaf', title: 'leaf',
disableCheckbox: true disableCheckbox: true
}, { }, {
@ -26,7 +27,7 @@
}, { }, {
title: 'parent 1-1', title: 'parent 1-1',
checked: true, checked: true,
node: [{ children: [{
title: '<span style="color: red">sss</span>', title: '<span style="color: red">sss</span>',
}] }]
}] }]
@ -35,10 +36,10 @@
}, },
methods: { methods: {
selectFn(data){ selectFn(data){
// console.log(data); console.log(data);
}, },
checkFn(data){ checkFn(data){
// console.log(data); console.log(data);
} }
} }
} }