Commit ce03ac5278bd092b68bf1e70f58db2ed72d54472
1 parent
b566d106
update Tree
update Tree
Showing
4 changed files
with
23 additions
and
35 deletions
Show diff stats
src/components/tree/tree.vue
| @@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
| 17 | v-if="!item.isLeaf" | 17 | v-if="!item.isLeaf" |
| 18 | v-show="item.expand" | 18 | v-show="item.expand" |
| 19 | :class="expandCls(item)" | 19 | :class="expandCls(item)" |
| 20 | - :data.sync="item.node" | 20 | + :data.sync="item.children" |
| 21 | :key="this.key+'.'+$index" | 21 | :key="this.key+'.'+$index" |
| 22 | :multiple="multiple" | 22 | :multiple="multiple" |
| 23 | :show-checkbox="showCheckbox" | 23 | :show-checkbox="showCheckbox" |
| @@ -54,18 +54,6 @@ | @@ -54,18 +54,6 @@ | ||
| 54 | type: Boolean, | 54 | type: Boolean, |
| 55 | default: false | 55 | default: false |
| 56 | }, | 56 | }, |
| 57 | - onSelect: { | ||
| 58 | - type: Function, | ||
| 59 | - default () { | ||
| 60 | - return {}; | ||
| 61 | - } | ||
| 62 | - }, | ||
| 63 | - onCheck: { | ||
| 64 | - type: Function, | ||
| 65 | - default () { | ||
| 66 | - return {}; | ||
| 67 | - } | ||
| 68 | - }, | ||
| 69 | emptyText: { | 57 | emptyText: { |
| 70 | type: String, | 58 | type: String, |
| 71 | default () { | 59 | default () { |
| @@ -135,7 +123,7 @@ | @@ -135,7 +123,7 @@ | ||
| 135 | }, | 123 | }, |
| 136 | preHandle () { | 124 | preHandle () { |
| 137 | for (let [i,item] of this.data.entries()) { | 125 | for (let [i,item] of this.data.entries()) { |
| 138 | - if (!item.node || !item.node.length) { | 126 | + if (!item.children || !item.children.length) { |
| 139 | this.$set(`data[${i}].isLeaf`, true); | 127 | this.$set(`data[${i}].isLeaf`, true); |
| 140 | this.$set(`data[${i}].childrenCheckedStatus`, 2); | 128 | this.$set(`data[${i}].childrenCheckedStatus`, 2); |
| 141 | continue; | 129 | continue; |
| @@ -144,7 +132,7 @@ | @@ -144,7 +132,7 @@ | ||
| 144 | this.$set(`data[${i}].childrenCheckedStatus`, 2); | 132 | this.$set(`data[${i}].childrenCheckedStatus`, 2); |
| 145 | this.$broadcast('parentChecked', true, `${this.key}.${i}`); | 133 | this.$broadcast('parentChecked', true, `${this.key}.${i}`); |
| 146 | } else { | 134 | } else { |
| 147 | - let status = this.getChildrenCheckedStatus(item.node); | 135 | + let status = this.getChildrenCheckedStatus(item.children); |
| 148 | this.$set(`data[${i}].childrenCheckedStatus`, status); | 136 | this.$set(`data[${i}].childrenCheckedStatus`, status); |
| 149 | if (status !== 0) this.$set(`data[${i}].checked`, true); | 137 | if (status !== 0) this.$set(`data[${i}].checked`, true); |
| 150 | } | 138 | } |
| @@ -194,8 +182,8 @@ | @@ -194,8 +182,8 @@ | ||
| 194 | if (tmp) { | 182 | if (tmp) { |
| 195 | res.push(node); | 183 | res.push(node); |
| 196 | } | 184 | } |
| 197 | - if (node.node && node.node.length) { | ||
| 198 | - res = res.concat(this.getNodes(node.node, opt)); | 185 | + if (node.children && node.children.length) { |
| 186 | + res = res.concat(this.getNodes(node.children, opt)); | ||
| 199 | } | 187 | } |
| 200 | } | 188 | } |
| 201 | return res; | 189 | return res; |
| @@ -241,11 +229,9 @@ | @@ -241,11 +229,9 @@ | ||
| 241 | } | 229 | } |
| 242 | this.$broadcast('cancelSelected', ori); | 230 | this.$broadcast('cancelSelected', ori); |
| 243 | } | 231 | } |
| 244 | - if (this.onSelect) { | ||
| 245 | - this.$nextTick(() => { | ||
| 246 | - this.onSelect(this.getSelectedNodes()); | ||
| 247 | - }); | ||
| 248 | - } | 232 | + this.$nextTick(() => { |
| 233 | + this.$emit('on-select-change', this.getSelectedNodes()); | ||
| 234 | + }); | ||
| 249 | }); | 235 | }); |
| 250 | this.$on('cancelSelected', ori => { | 236 | this.$on('cancelSelected', ori => { |
| 251 | this.$broadcast('cancelSelected', ori); | 237 | this.$broadcast('cancelSelected', ori); |
| @@ -265,15 +251,15 @@ | @@ -265,15 +251,15 @@ | ||
| 265 | } | 251 | } |
| 266 | }); | 252 | }); |
| 267 | this.$on('childChecked', (ori, key) => { | 253 | this.$on('childChecked', (ori, key) => { |
| 268 | - if (this.key === '0' && this.onCheck) { | 254 | + if (this.key === '0') { |
| 269 | this.$nextTick(() => { | 255 | this.$nextTick(() => { |
| 270 | - this.onCheck(this.getCheckedNodes()); | 256 | + this.$emit('on-check-change', this.getCheckedNodes()); |
| 271 | }); | 257 | }); |
| 272 | } | 258 | } |
| 273 | if (this === ori) return; | 259 | if (this === ori) return; |
| 274 | for (let [i,item] of this.data.entries()) { | 260 | for (let [i,item] of this.data.entries()) { |
| 275 | if (this.key + '.' + i == key) { | 261 | if (this.key + '.' + i == key) { |
| 276 | - let temp = this.getChildrenCheckedStatus(item.node); | 262 | + let temp = this.getChildrenCheckedStatus(item.children); |
| 277 | if (temp != item.childrenCheckedStatus) { | 263 | if (temp != item.childrenCheckedStatus) { |
| 278 | this.$set(`data[${i}].checked`, !!temp); | 264 | this.$set(`data[${i}].checked`, !!temp); |
| 279 | this.$set(`data[${i}].childrenCheckedStatus`, temp); | 265 | this.$set(`data[${i}].childrenCheckedStatus`, temp); |
src/styles/components/checkbox.less
src/styles/components/tree.less
| @@ -61,10 +61,10 @@ | @@ -61,10 +61,10 @@ | ||
| 61 | background-color: tint(@primary-color, 80%); | 61 | background-color: tint(@primary-color, 80%); |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | + .@{checkbox-prefix-cls}-wrapper{ | ||
| 65 | + margin-right: 4px; | ||
| 66 | + } | ||
| 64 | span { | 67 | span { |
| 65 | - &.@{tree-prefix-cls}-checkbox { | ||
| 66 | - margin: 2px 4px 0 0; | ||
| 67 | - } | ||
| 68 | &.@{tree-prefix-cls}-switcher, | 68 | &.@{tree-prefix-cls}-switcher, |
| 69 | &.@{tree-prefix-cls}-iconEle { | 69 | &.@{tree-prefix-cls}-iconEle { |
| 70 | display: inline-block; | 70 | display: inline-block; |
test/routers/tree.vue
| @@ -3,21 +3,22 @@ | @@ -3,21 +3,22 @@ | ||
| 3 | :data.sync="treeData" | 3 | :data.sync="treeData" |
| 4 | :show-checkbox="true" | 4 | :show-checkbox="true" |
| 5 | :multiple="true" | 5 | :multiple="true" |
| 6 | - :on-select="selectFn" | ||
| 7 | - :on-check="checkFn"></Tree> | 6 | + @on-select-change="selectFn" |
| 7 | + @on-check-change="checkFn"></Tree> | ||
| 8 | </template> | 8 | </template> |
| 9 | <script> | 9 | <script> |
| 10 | export default { | 10 | export default { |
| 11 | data: function() { | 11 | data: function() { |
| 12 | return { | 12 | return { |
| 13 | treeData: [{ | 13 | treeData: [{ |
| 14 | + expand: true, | ||
| 14 | title: 'parent 1', | 15 | title: 'parent 1', |
| 15 | selected: false, | 16 | selected: false, |
| 16 | - node: [{ | 17 | + children: [{ |
| 17 | title: 'parent 1-0', | 18 | title: 'parent 1-0', |
| 18 | expand: true, | 19 | expand: true, |
| 19 | disabled: true, | 20 | disabled: true, |
| 20 | - node: [{ | 21 | + children: [{ |
| 21 | title: 'leaf', | 22 | title: 'leaf', |
| 22 | disableCheckbox: true | 23 | disableCheckbox: true |
| 23 | }, { | 24 | }, { |
| @@ -26,7 +27,7 @@ | @@ -26,7 +27,7 @@ | ||
| 26 | }, { | 27 | }, { |
| 27 | title: 'parent 1-1', | 28 | title: 'parent 1-1', |
| 28 | checked: true, | 29 | checked: true, |
| 29 | - node: [{ | 30 | + children: [{ |
| 30 | title: '<span style="color: red">sss</span>', | 31 | title: '<span style="color: red">sss</span>', |
| 31 | }] | 32 | }] |
| 32 | }] | 33 | }] |
| @@ -35,10 +36,10 @@ | @@ -35,10 +36,10 @@ | ||
| 35 | }, | 36 | }, |
| 36 | methods: { | 37 | methods: { |
| 37 | selectFn(data){ | 38 | selectFn(data){ |
| 38 | -// console.log(data); | 39 | + console.log(data); |
| 39 | }, | 40 | }, |
| 40 | checkFn(data){ | 41 | checkFn(data){ |
| 41 | -// console.log(data); | 42 | + console.log(data); |
| 42 | } | 43 | } |
| 43 | } | 44 | } |
| 44 | } | 45 | } |