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