|
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)"> |
|
73 | 73 | :parent-data="parentData" |
74 | 74 | :data="data" |
75 | 75 | :current-key="currentKey"> |
76 | | - <span v-if="!Array.isArray(parentData)" class="vjs-key">{{ keyFormatter(currentKey) }}:</span> |
| 76 | + <span |
| 77 | + v-if="parentData && currentKey && !Array.isArray(parentData)" |
| 78 | + class="vjs-key" |
| 79 | + > |
| 80 | + {{ keyFormatter(currentKey) }}: |
| 81 | + </span> |
77 | 82 | </simple-text> |
78 | 83 | </div> |
79 | 84 | </template> |
|
237 | 242 | } |
238 | 243 | }, |
239 | 244 | 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'))) { |
| 245 | + handleValueChange (emitType) { |
| 246 | + if (this.isMultiple && (emitType === 'checkbox' || emitType === 'tree')) { |
254 | 247 | // handle multiple |
255 | 248 | const index = this.model.findIndex(item => item === this.path) |
256 | 249 | const oldVal = [...this.model] |
|
264 | 257 | this.currentCheckboxVal = !this.currentCheckboxVal |
265 | 258 | } |
266 | 259 | this.$emit('change', this.model, oldVal) |
267 | | - } else if (this.isSingle && (emitType === 'radio' || (this.selectOnClickNode && emitType === 'tree'))) { |
| 260 | + } else if (this.isSingle && (emitType === 'radio' || emitType === 'tree')) { |
268 | 261 | // handle single |
269 | 262 | if (this.model !== this.path) { |
270 | 263 | const oldVal = this.model |
|
275 | 268 | } |
276 | 269 | }, |
277 | 270 |
|
| 271 | + /** |
| 272 | + * emit click event |
| 273 | + * @param {string} emitType tree/checkbox/radio |
| 274 | + */ |
| 275 | + handleClick (e) { |
| 276 | + // Event can not be stopPropagation, because user may be listening the click event. |
| 277 | + // So use _uid to simulated. |
| 278 | + if (e._uid && e._uid !== this._uid) return |
| 279 | + e._uid = this._uid |
| 280 | +
|
| 281 | + this.$emit('click', this.path, this.data) |
| 282 | + if (this.selectable && this.selectOnClickNode) { |
| 283 | + this.handleValueChange('tree') |
| 284 | + } |
| 285 | + }, |
| 286 | +
|
278 | 287 | // handle children's click, and propagation |
279 | 288 | handleItemClick (path, data) { |
280 | 289 | this.$emit('click', path, data) |
|
0 commit comments