1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| <script> import refs from './refs.js' export default { name: 'itemNode',
props: { option: { type: Object, default(){ return {} } },
name: string }
data(){ let cid = this.cid || ('item' + ++count) return { expand: false, level: (this.$parent.level || 0) + 1, indent: 1, checked: false, cid } },
computed: { hasChild(){ return !!this.option.children } },
methods: { handleClickExpand() { this.expand = !this.expand }, handleClickItem() { this.checked = !this.checked }, setDefault() { let tree = refs.get(this.cid) let _value = tree.value
if(_value.indexOf(this.option.value > -1)) { this.checked = true } } },
render(){ return ( <li class={[ 'tree-item', this.checked && 'is-checked' ]}> // 展开箭头 <div class={[ 'arrow', this.expand ? 'expand' : '' ]} style={{ display: this.hasChild ? 'block' : '' }} onClick={this.handleClickExpand} >+<div>
// 节点-标题 <div class={['v-tree__title']} style={{ paddingLeft: (this.level * this.indent) + 'px' }} onClick={this.handleClickItem} > {this.option.text} </div>
// 子节点 { this.hasChild && ( <ul class="v-tree__child" style={{ display: this.expand ? 'block' : 'node' }} > { this.option.children.map((itemData, index) => { return <item-node name={this.name} option={itemData} key={`${this.name}_${itemData.value}_${index}`} /> }) } </ul> ) } </li> ) } } </script>
|