iview/src/components/tree/node.vue

115 lines
3.8 KiB
Vue
Raw Normal View History

2017-03-24 20:50:13 +08:00
<template>
2017-06-02 14:30:03 +08:00
<collapse-transition>
<ul :class="classes">
2017-03-24 20:50:13 +08:00
<li>
<span :class="arrowClasses" @click="handleExpand">
<Icon type="arrow-right-b"></Icon>
</span>
<Checkbox
2017-06-02 14:30:03 +08:00
v-if="showCheckbox"
:value="data.checked"
:indeterminate="data.indeterminate"
2017-06-02 14:30:03 +08:00
:disabled="data.disabled || data.disableCheckbox"
@click.native.prevent="handleCheck"></Checkbox>
<Render v-if="data.render" :render="data.render"></Render>
<span v-else :class="titleClasses" v-html="data.title" @click="handleSelect"></span>
2017-03-24 20:50:13 +08:00
<Tree-node
v-if="data.expand"
2017-06-02 14:30:03 +08:00
v-for="item in data.children"
2017-07-14 15:37:07 +08:00
:key="item.nodeKey"
2017-06-02 14:30:03 +08:00
:data="item"
:multiple="multiple"
:show-checkbox="showCheckbox">
2017-03-24 20:50:13 +08:00
</Tree-node>
</li>
</ul>
2017-06-02 14:30:03 +08:00
</collapse-transition>
2017-03-24 20:50:13 +08:00
</template>
<script>
import Checkbox from '../checkbox/checkbox.vue';
2017-04-07 11:29:31 +08:00
import Icon from '../icon/icon.vue';
import Render from '../base/render';
2017-06-02 14:30:03 +08:00
import CollapseTransition from '../base/collapse-transition';
2017-03-24 20:50:13 +08:00
import Emitter from '../../mixins/emitter';
const prefixCls = 'ivu-tree';
export default {
name: 'TreeNode',
mixins: [ Emitter ],
components: { Checkbox, Icon, CollapseTransition, Render },
2017-03-24 20:50:13 +08:00
props: {
data: {
type: Object,
default () {
return {};
}
},
multiple: {
type: Boolean,
default: false
},
showCheckbox: {
type: Boolean,
default: false
}
},
data () {
return {
prefixCls: prefixCls
2017-03-24 20:50:13 +08:00
};
},
computed: {
classes () {
return [
`${prefixCls}-children`
2017-03-24 21:06:49 +08:00
];
2017-03-24 20:50:13 +08:00
},
selectedCls () {
return [
{
[`${prefixCls}-node-selected`]: this.data.selected
}
];
},
arrowClasses () {
return [
`${prefixCls}-arrow`,
{
[`${prefixCls}-arrow-disabled`]: this.data.disabled,
[`${prefixCls}-arrow-open`]: this.data.expand,
[`${prefixCls}-arrow-hidden`]: !(this.data.children && this.data.children.length)
}
];
},
titleClasses () {
return [
`${prefixCls}-title`,
{
[`${prefixCls}-title-selected`]: this.data.selected
}
];
}
},
methods: {
handleExpand () {
if (this.data.disabled) return;
this.$set(this.data, 'expand', !this.data.expand);
2017-04-27 15:20:11 +08:00
this.dispatch('Tree', 'toggle-expand', this.data);
2017-03-24 20:50:13 +08:00
},
handleSelect () {
if (this.data.disabled) return;
this.dispatch('Tree', 'on-selected', this.data.nodeKey);
2017-03-24 20:50:13 +08:00
},
handleCheck () {
if (this.data.disabled) return;
const changes = {
checked: !this.data.checked && !this.data.indeterminate,
nodeKey: this.data.nodeKey
};
this.dispatch('Tree', 'on-check', changes);
2017-03-24 20:50:13 +08:00
}
}
};
</script>