Commit c7315098532c3d79c98dfb1d5eded3f71ea3a54a

Authored by leonine
1 parent 87379c82

修复两个问题:

1.如果某行禁用_disabled=true,则这行的_checked,无论如何都是false,因为禁用的目的就是不能选择
2.修复某行设置_disabled=true时,全选状态判断有误的bug
src/components/table/table-head.vue
... ... @@ -84,16 +84,23 @@
84 84 },
85 85 isSelectAll () {
86 86 let isSelectAll = true;
  87 + let isAllDisabled = true;
87 88 if (!this.data.length) isSelectAll = false;
88 89  
89 90 for (let i = 0; i < this.data.length; i++) {
90   - if (!this.objData[this.data[i]._index]._isChecked) {
  91 + if(this.objData[this.data[i]._index]._isDisabled){
  92 + isAllDisabled = isAllDisabled && true;
  93 + continue;
  94 + }else{
  95 + isAllDisabled = isAllDisabled && false;
  96 + }
  97 + if (!this.objData[this.data[i]._index]._isChecked ) {
91 98 isSelectAll = false;
92 99 break;
93 100 }
94 101 }
95 102  
96   - return isSelectAll;
  103 + return isAllDisabled ? false : isSelectAll;
97 104 }
98 105 },
99 106 methods: {
... ...
src/components/table/table.vue
... ... @@ -553,8 +553,17 @@
553 553 this.data.forEach((row, index) => {
554 554 const newRow = deepCopy(row);// todo 直接替换
555 555 newRow._isHover = false;
  556 + if(newRow._disabled){
  557 + newRow._isDisabled = newRow._disabled;
  558 + }else{
  559 + newRow._isDisabled = false;
  560 + }
556 561 if (newRow._checked) {
557   - newRow._isChecked = newRow._checked;
  562 + if(newRow._isDisabled){
  563 + newRow._isChecked = false;
  564 + }else{
  565 + newRow._isChecked = newRow._checked;
  566 + }
558 567 } else {
559 568 newRow._isChecked = false;
560 569 }
... ... @@ -563,12 +572,6 @@
563 572 } else {
564 573 newRow._isHighlight = false;
565 574 }
566   -
567   - if(newRow._disabled){
568   - newRow._isDisabled = newRow._disabled;
569   - }else{
570   - newRow._isDisabled = false;
571   - }
572 575 data[index] = newRow;
573 576 });
574 577 return data;
... ...
test/routers/table.vue
... ... @@ -54,26 +54,29 @@
54 54 age: 18,
55 55 address: '北京市朝阳区芍药居',
56 56 _highlight: true,
57   - _checked: true
  57 + _checked: true,
  58 + _disabled: false
58 59 },
59 60 {
60 61 name: '张小刚',
61 62 age: 25,
62 63 address: '北京市海淀区西二旗',
63   - _checked: true
  64 + _checked: false,
  65 + _disabled: true
64 66 },
65 67 {
66 68 name: '李小红',
67 69 age: 30,
68 70 address: '上海市浦东新区世纪大道',
69   - _checked: false,
  71 + _checked: true,
70 72 _disabled: true
71 73 },
72 74 {
73 75 name: '周小伟',
74 76 age: 26,
75 77 address: '深圳市南山区深南大道',
76   - _checked: true
  78 + _checked: true,
  79 + _disabled: false
77 80 }
78 81 ]
79 82 }
... ...