Commit b923c8187ceed0370ab40ce66c64d700e993fc7a

Authored by 梁灏
1 parent e81207a2

update Tree

update Tree
src/components/checkbox/checkbox.vue
@@ -36,6 +36,10 @@ @@ -36,6 +36,10 @@
36 checked: { 36 checked: {
37 type: Boolean, 37 type: Boolean,
38 default: false 38 default: false
  39 + },
  40 + indeterminate: {
  41 + type: Boolean,
  42 + default: false
39 } 43 }
40 }, 44 },
41 data () { 45 data () {
@@ -62,7 +66,8 @@ @@ -62,7 +66,8 @@
62 `${prefixCls}`, 66 `${prefixCls}`,
63 { 67 {
64 [`${prefixCls}-checked`]: this.selected, 68 [`${prefixCls}-checked`]: this.selected,
65 - [`${prefixCls}-disabled`]: this.disabled 69 + [`${prefixCls}-disabled`]: this.disabled,
  70 + [`${prefixCls}-indeterminate`]: this.indeterminate
66 } 71 }
67 ]; 72 ];
68 }, 73 },
src/components/collapse/panel.vue
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 </div> 10 </div>
11 </template> 11 </template>
12 <script> 12 <script>
13 - import Icon from '../icon'; 13 + import Icon from '../icon/icon.vue';
14 const prefixCls = 'ivu-collapse'; 14 const prefixCls = 'ivu-collapse';
15 15
16 export default { 16 export default {
src/components/tree/tree.vue
1 <template> 1 <template>
2 <ul :class="classes"> 2 <ul :class="classes">
3 <li v-for="item in data" :class="itemCls(item)"> 3 <li v-for="item in data" :class="itemCls(item)">
4 - <span :class="arrowCls(item)" @click="setExpand(item.disabled, $index)"></span>  
5 - <span v-if="showCheckbox" :class="checkboxCls(item)" @click="setCheck(item.disabled||item.disableCheckbox,$index)">  
6 - <span :class="[prefixCls + '-checkbox-inner']"></span> 4 + <span :class="arrowCls(item)" @click="setExpand(item.disabled, $index)">
  5 + <Icon type="arrow-right-b"></Icon>
7 </span> 6 </span>
  7 + <!--<span v-if="showCheckbox" :class="checkboxCls(item)" @click="setCheck(item.disabled||item.disableCheckbox,$index)">-->
  8 + <!--<span :class="[prefixCls + '-checkbox-inner']"></span>-->
  9 + <!--</span>-->
  10 + <Checkbox
  11 + :checked="item.checked && item.childrenCheckedStatus == 2"
  12 + :disabled="item.disabled || item.disableCheckbox"
  13 + @click.prevent="setCheck(item.disabled||item.disableCheckbox,$index)"></Checkbox>
8 <a :class="titleCls(item)" @click="setSelect(item.disabled, $index)"> 14 <a :class="titleCls(item)" @click="setSelect(item.disabled, $index)">
9 <span :class="[prefixCls + '-title']" v-html="item.title"></span> 15 <span :class="[prefixCls + '-title']" v-html="item.title"></span>
10 </a> 16 </a>
@@ -21,12 +27,15 @@ @@ -21,12 +27,15 @@
21 </ul> 27 </ul>
22 </template> 28 </template>
23 <script> 29 <script>
  30 + import Icon from '../icon/icon.vue';
  31 + import Checkbox from '../checkbox/checkbox.vue';
24 import { t } from '../../locale'; 32 import { t } from '../../locale';
25 33
26 const prefixCls = 'ivu-tree'; 34 const prefixCls = 'ivu-tree';
27 35
28 export default { 36 export default {
29 name: 'tree', 37 name: 'tree',
  38 + components: { Icon, Checkbox },
30 props: { 39 props: {
31 data: { 40 data: {
32 type: Array, 41 type: Array,
@@ -135,7 +144,7 @@ @@ -135,7 +144,7 @@
135 this.data[i].key = `${this.key}.${i}`; 144 this.data[i].key = `${this.key}.${i}`;
136 } 145 }
137 }, 146 },
138 - preHandle(){ 147 + preHandle () {
139 for (let [i,item] of this.data.entries()) { 148 for (let [i,item] of this.data.entries()) {
140 if (!item.node || !item.node.length) { 149 if (!item.node || !item.node.length) {
141 this.$set(`data[${i}].isLeaf`, true); 150 this.$set(`data[${i}].isLeaf`, true);
@@ -152,12 +161,12 @@ @@ -152,12 +161,12 @@
152 } 161 }
153 } 162 }
154 }, 163 },
155 - setExpand(disabled, index){ 164 + setExpand (disabled, index) {
156 if (!disabled) { 165 if (!disabled) {
157 this.$set(`data[${index}].expand`, !this.data[index].expand); 166 this.$set(`data[${index}].expand`, !this.data[index].expand);
158 } 167 }
159 }, 168 },
160 - setSelect(disabled, index){ 169 + setSelect (disabled, index) {
161 if (!disabled) { 170 if (!disabled) {
162 const selected = !this.data[index].selected; 171 const selected = !this.data[index].selected;
163 if (this.multiple || !selected) { 172 if (this.multiple || !selected) {
@@ -174,7 +183,7 @@ @@ -174,7 +183,7 @@
174 this.$dispatch('nodeSelected', this, selected); 183 this.$dispatch('nodeSelected', this, selected);
175 } 184 }
176 }, 185 },
177 - setCheck(disabled, index){ 186 + setCheck (disabled, index) {
178 if (disabled) return; 187 if (disabled) return;
179 const checked = !this.data[index].checked; 188 const checked = !this.data[index].checked;
180 this.$set(`data[${index}].checked`, checked); 189 this.$set(`data[${index}].checked`, checked);
@@ -182,7 +191,7 @@ @@ -182,7 +191,7 @@
182 this.$dispatch('childChecked', this, this.key); 191 this.$dispatch('childChecked', this, this.key);
183 this.$broadcast('parentChecked', checked, `${this.key}.${index}`); 192 this.$broadcast('parentChecked', checked, `${this.key}.${index}`);
184 }, 193 },
185 - getNodes(data, opt){ 194 + getNodes (data, opt) {
186 data = data || this.data; 195 data = data || this.data;
187 let res = []; 196 let res = [];
188 for (let node of data) { 197 for (let node of data) {
@@ -202,13 +211,13 @@ @@ -202,13 +211,13 @@
202 } 211 }
203 return res; 212 return res;
204 }, 213 },
205 - getSelectedNodes(){ 214 + getSelectedNodes () {
206 return this.getNodes(this.data, {selected: true}); 215 return this.getNodes(this.data, {selected: true});
207 }, 216 },
208 - getCheckedNodes(){ 217 + getCheckedNodes () {
209 return this.getNodes(this.data, {checked: true, childrenCheckedStatus: 2}); 218 return this.getNodes(this.data, {checked: true, childrenCheckedStatus: 2});
210 }, 219 },
211 - getChildrenCheckedStatus(children){ 220 + getChildrenCheckedStatus (children) {
212 let checkNum = 0, child_childrenAllChecked = true; 221 let checkNum = 0, child_childrenAllChecked = true;
213 for (let child of children) { 222 for (let child of children) {
214 if (child.checked) { 223 if (child.checked) {
src/styles/components/tree.less
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 .@{tree-prefix-cls} { 3 .@{tree-prefix-cls} {
4 margin: 0; 4 margin: 0;
5 padding: 5px; 5 padding: 5px;
6 - font-size: 12px; 6 + font-size: @font-size-small;
7 li { 7 li {
8 padding: 0; 8 padding: 0;
9 margin: 7px 0; 9 margin: 7px 0;
@@ -46,14 +46,14 @@ @@ -46,14 +46,14 @@
46 } 46 }
47 a { 47 a {
48 display: inline-block; 48 display: inline-block;
49 - padding: 1px 5px;  
50 - border-radius: 2px;  
51 margin: 0; 49 margin: 0;
  50 + padding: 1px 5px;
  51 + border-radius: @btn-border-radius-small;
52 cursor: pointer; 52 cursor: pointer;
53 text-decoration: none; 53 text-decoration: none;
54 vertical-align: top; 54 vertical-align: top;
55 - color: #666;  
56 - transition: all 0.3s ease; 55 + color: @text-color;
  56 + transition: all @transition-time @ease-in-out;
57 &:hover { 57 &:hover {
58 background-color: tint(@primary-color, 90%); 58 background-color: tint(@primary-color, 90%);
59 } 59 }
@@ -67,43 +67,47 @@ @@ -67,43 +67,47 @@
67 } 67 }
68 &.@{tree-prefix-cls}-switcher, 68 &.@{tree-prefix-cls}-switcher,
69 &.@{tree-prefix-cls}-iconEle { 69 &.@{tree-prefix-cls}-iconEle {
70 - margin: 0; 70 + display: inline-block;
71 width: 16px; 71 width: 16px;
72 height: 16px; 72 height: 16px;
73 line-height: 16px; 73 line-height: 16px;
74 - display: inline-block; 74 + margin: 0;
75 vertical-align: middle; 75 vertical-align: middle;
76 border: 0 none; 76 border: 0 none;
77 cursor: pointer; 77 cursor: pointer;
78 outline: none; 78 outline: none;
79 } 79 }
80 - &.@{tree-prefix-cls}-icon_loading {  
81 - &:after {  
82 - display: inline-block;  
83 - //.iconfont-font("\e6a1");  
84 - animation: loadingCircle 1s infinite linear;  
85 - color: @primary-color;  
86 - }  
87 - } 80 + //&.@{tree-prefix-cls}-icon_loading {
  81 + // &:after {
  82 + // display: inline-block;
  83 + // //.iconfont-font("\e6a1");
  84 + // animation: loadingCircle 1s infinite linear;
  85 + // color: @primary-color;
  86 + // }
  87 + //}
88 &.@{tree-prefix-cls}-switcher { 88 &.@{tree-prefix-cls}-switcher {
  89 + i{
  90 + transition: all @transition-time @ease-in-out;
  91 + }
89 &.@{tree-prefix-cls}-switcher-noop { 92 &.@{tree-prefix-cls}-switcher-noop {
90 cursor: auto; 93 cursor: auto;
  94 + i{
  95 + display: none;
  96 + }
91 } 97 }
92 &.@{tree-prefix-cls}-roots_open, 98 &.@{tree-prefix-cls}-roots_open,
93 &.@{tree-prefix-cls}-center_open, 99 &.@{tree-prefix-cls}-center_open,
94 &.@{tree-prefix-cls}-bottom_open, 100 &.@{tree-prefix-cls}-bottom_open,
95 &.@{tree-prefix-cls}-noline_open { 101 &.@{tree-prefix-cls}-noline_open {
96 - //.antTreeSwitcherIcon(); 102 + i {
  103 + transform: rotate(90deg);
  104 + }
97 } 105 }
98 &.@{tree-prefix-cls}-roots_close, 106 &.@{tree-prefix-cls}-roots_close,
99 &.@{tree-prefix-cls}-center_close, 107 &.@{tree-prefix-cls}-center_close,
100 &.@{tree-prefix-cls}-bottom_close, 108 &.@{tree-prefix-cls}-bottom_close,
101 &.@{tree-prefix-cls}-noline_close { 109 &.@{tree-prefix-cls}-noline_close {
102 - //.antTreeSwitcherIcon();  
103 - //.ie-rotate(3);  
104 - &:after {  
105 - transform: rotate(270deg) scale(0.5);  
106 - } 110 +
107 } 111 }
108 } 112 }
109 } 113 }
@@ -118,7 +122,7 @@ @@ -118,7 +122,7 @@
118 >span, 122 >span,
119 >a, 123 >a,
120 >a span { 124 >a span {
121 - color: #ccc; 125 + color: @input-disabled-bg;
122 cursor: not-allowed; 126 cursor: not-allowed;
123 } 127 }
124 } 128 }
test/routers/tree.vue
1 <template> 1 <template>
2 <Tree 2 <Tree
3 :data.sync="treeData" 3 :data.sync="treeData"
4 - :checkable="true" 4 + :show-checkbox="true"
5 :multiple="true" 5 :multiple="true"
6 :on-select="selectFn" 6 :on-select="selectFn"
7 :on-check="checkFn"></Tree> 7 :on-check="checkFn"></Tree>
@@ -35,10 +35,10 @@ @@ -35,10 +35,10 @@
35 }, 35 },
36 methods: { 36 methods: {
37 selectFn(data){ 37 selectFn(data){
38 - console.log(data); 38 +// console.log(data);
39 }, 39 },
40 checkFn(data){ 40 checkFn(data){
41 - console.log(data); 41 +// console.log(data);
42 } 42 }
43 } 43 }
44 } 44 }