|
9 | 9 | 'is-highlight-selected': isSelected && highlightSelectedNode,
|
10 | 10 | 'is-mouseover': isMouseover
|
11 | 11 | }"
|
12 |
| - @click="handleClick($event, 'tree')" |
| 12 | + @click="handleClick" |
13 | 13 | @mouseover.stop="handleMouseover"
|
14 | 14 | @mouseout.stop="handleMouseout">
|
15 | 15 | <template v-if="showSelectController && selectable">
|
16 |
| - <vue-checkbox v-if="isMultiple" v-model="currentCheckboxVal" @change="handleClick($event, 'checkbox')"></vue-checkbox> |
17 |
| - <vue-radio v-else-if="isSingle" v-model="model" @change="handleClick($event, 'radio')" :path="path"></vue-radio> |
| 16 | + <vue-checkbox v-if="isMultiple" v-model="currentCheckboxVal" @change="handleValueChange('checkbox')"></vue-checkbox> |
| 17 | + <vue-radio v-else-if="isSingle" v-model="model" @change="handleValueChange('radio')" :path="path"></vue-radio> |
18 | 18 | </template>
|
19 | 19 |
|
20 | 20 | <template v-if="Array.isArray(data) || isObject(data)">
|
|
237 | 237 | }
|
238 | 238 | },
|
239 | 239 | methods: {
|
240 |
| - /** |
241 |
| - * emit click event |
242 |
| - * @param {string} emitType tree/checkbox/radio |
243 |
| - */ |
244 |
| - handleClick (e, emitType = '') { |
245 |
| - // Event can not be stopPropagation, because user may be listening the click event. |
246 |
| - // So use _uid to simulated. |
247 |
| - if (e._uid && e._uid !== this._uid) return |
248 |
| - e._uid = this._uid |
249 |
| -
|
250 |
| - this.$emit('click', this.path, this.data) |
251 |
| - if (!this.selectable) return |
252 |
| -
|
253 |
| - if (this.isMultiple && (emitType === 'checkbox' || (this.selectOnClickNode && emitType === 'tree'))) { |
| 240 | + handleValueChange (emitType) { |
| 241 | + if (this.isMultiple && (emitType === 'checkbox' || emitType === 'tree')) { |
254 | 242 | // handle multiple
|
255 | 243 | const index = this.model.findIndex(item => item === this.path)
|
256 | 244 | const oldVal = [...this.model]
|
|
264 | 252 | this.currentCheckboxVal = !this.currentCheckboxVal
|
265 | 253 | }
|
266 | 254 | this.$emit('change', this.model, oldVal)
|
267 |
| - } else if (this.isSingle && (emitType === 'radio' || (this.selectOnClickNode && emitType === 'tree'))) { |
| 255 | + } else if (this.isSingle && (emitType === 'radio' || emitType === 'tree')) { |
268 | 256 | // handle single
|
269 | 257 | if (this.model !== this.path) {
|
270 | 258 | const oldVal = this.model
|
|
275 | 263 | }
|
276 | 264 | },
|
277 | 265 |
|
| 266 | + /** |
| 267 | + * emit click event |
| 268 | + * @param {string} emitType tree/checkbox/radio |
| 269 | + */ |
| 270 | + handleClick (e) { |
| 271 | + // Event can not be stopPropagation, because user may be listening the click event. |
| 272 | + // So use _uid to simulated. |
| 273 | + if (e._uid && e._uid !== this._uid) return |
| 274 | + e._uid = this._uid |
| 275 | +
|
| 276 | + this.$emit('click', this.path, this.data) |
| 277 | + if (this.selectable && this.selectOnClickNode) { |
| 278 | + this.handleValueChange('tree') |
| 279 | + } |
| 280 | + }, |
| 281 | +
|
278 | 282 | // handle children's click, and propagation
|
279 | 283 | handleItemClick (path, data) {
|
280 | 284 | this.$emit('click', path, data)
|
|
0 commit comments