Skip to content

Commit 9077e18

Browse files
committed
feat: update table
1 parent 292e2bc commit 9077e18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1229
-817
lines changed

build/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
dev: {
3-
componentName: 'transfer', // dev components
3+
componentName: 'table', // dev components
44
},
55
};

components/table/FilterDropdownMenuWrapper.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
name: 'FilterDropdownMenuWrapper',
23
methods: {
34
handelClick(e) {
45
e.stopPropagation();

components/table/SelectionBox.jsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ export default {
2424
}
2525
},
2626
methods: {
27-
subscribe() {
28-
const { store } = this;
29-
this.unsubscribe = store.subscribe(() => {
30-
const checked = this.getCheckState(this.$props);
31-
this.setState({ checked });
32-
});
33-
},
34-
3527
getCheckState(props) {
3628
const { store, defaultSelection, rowIndex } = props;
3729
let checked = false;
@@ -44,6 +36,13 @@ export default {
4436
}
4537
return checked;
4638
},
39+
subscribe() {
40+
const { store } = this;
41+
this.unsubscribe = store.subscribe(() => {
42+
const checked = this.getCheckState(this.$props);
43+
this.setState({ checked });
44+
});
45+
},
4746
},
4847

4948
render() {
@@ -59,8 +58,7 @@ export default {
5958
if (type === 'radio') {
6059
checkboxProps.props.value = rowIndex;
6160
return <Radio {...checkboxProps} />;
62-
} else {
63-
return <Checkbox {...checkboxProps} />;
6461
}
62+
return <Checkbox {...checkboxProps} />;
6563
},
6664
};

components/table/SelectionCheckboxAll.jsx

Lines changed: 93 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,87 @@ import classNames from 'classnames';
66
import { SelectionCheckboxAllProps } from './interface';
77
import BaseMixin from '../_util/BaseMixin';
88

9+
function checkSelection({
10+
store,
11+
getCheckboxPropsByItem,
12+
getRecordKey,
13+
data,
14+
type,
15+
byDefaultChecked,
16+
}) {
17+
return byDefaultChecked
18+
? data[type]((item, i) => getCheckboxPropsByItem(item, i).defaultChecked)
19+
: data[type]((item, i) => store.getState().selectedRowKeys.indexOf(getRecordKey(item, i)) >= 0);
20+
}
21+
22+
function getIndeterminateState(props) {
23+
const { store, data } = props;
24+
if (!data.length) {
25+
return false;
26+
}
27+
28+
const someCheckedNotByDefaultChecked =
29+
checkSelection({
30+
...props,
31+
data,
32+
type: 'some',
33+
byDefaultChecked: false,
34+
}) &&
35+
!checkSelection({
36+
...props,
37+
data,
38+
type: 'every',
39+
byDefaultChecked: false,
40+
});
41+
const someCheckedByDefaultChecked =
42+
checkSelection({
43+
...props,
44+
data,
45+
type: 'some',
46+
byDefaultChecked: true,
47+
}) &&
48+
!checkSelection({
49+
...props,
50+
data,
51+
type: 'every',
52+
byDefaultChecked: true,
53+
});
54+
55+
if (store.getState().selectionDirty) {
56+
return someCheckedNotByDefaultChecked;
57+
}
58+
return someCheckedNotByDefaultChecked || someCheckedByDefaultChecked;
59+
}
60+
61+
function getCheckState(props) {
62+
const { store, data } = props;
63+
if (!data.length) {
64+
return false;
65+
}
66+
if (store.getState().selectionDirty) {
67+
return checkSelection({
68+
...props,
69+
data,
70+
type: 'every',
71+
byDefaultChecked: false,
72+
});
73+
}
74+
return (
75+
checkSelection({
76+
...props,
77+
data,
78+
type: 'every',
79+
byDefaultChecked: false,
80+
}) ||
81+
checkSelection({
82+
...props,
83+
data,
84+
type: 'every',
85+
byDefaultChecked: true,
86+
})
87+
);
88+
}
89+
990
export default {
1091
name: 'SelectionCheckboxAll',
1192
mixins: [BaseMixin],
@@ -18,25 +99,23 @@ export default {
1899
{
19100
key: 'all',
20101
text: props.locale.selectAll,
21-
onSelect: () => {},
22102
},
23103
{
24104
key: 'invert',
25105
text: props.locale.selectInvert,
26-
onSelect: () => {},
27106
},
28107
];
29108

30109
return {
31-
checked: this.getCheckState(props),
32-
indeterminate: this.getIndeterminateState(props),
110+
checked: getCheckState(props),
111+
indeterminate: getIndeterminateState(props),
33112
};
34113
},
35114

36115
watch: {
37116
$props: {
38117
handler: function() {
39-
this.setCheckState();
118+
this.setCheckState(this.$props);
40119
},
41120
deep: true,
42121
},
@@ -52,13 +131,6 @@ export default {
52131
}
53132
},
54133
methods: {
55-
subscribe() {
56-
const { store } = this;
57-
this.unsubscribe = store.subscribe(() => {
58-
this.setCheckState(this.$props);
59-
});
60-
},
61-
62134
checkSelection(props, data, type, byDefaultChecked) {
63135
const { store, getCheckboxPropsByItem, getRecordKey } = props || this.$props;
64136
// type should be 'every' | 'some'
@@ -73,8 +145,8 @@ export default {
73145
},
74146

75147
setCheckState(props) {
76-
const checked = this.getCheckState(props);
77-
const indeterminate = this.getIndeterminateState(props);
148+
const checked = getCheckState(props);
149+
const indeterminate = getIndeterminateState(props);
78150
this.setState(prevState => {
79151
const newState = {};
80152
if (indeterminate !== prevState.indeterminate) {
@@ -87,41 +159,16 @@ export default {
87159
});
88160
},
89161

90-
getCheckState(props) {
91-
const { store, data } = this;
92-
let checked;
93-
if (!data.length) {
94-
checked = false;
95-
} else {
96-
checked = store.getState().selectionDirty
97-
? this.checkSelection(props, data, 'every', false)
98-
: this.checkSelection(props, data, 'every', false) ||
99-
this.checkSelection(props, data, 'every', true);
100-
}
101-
return checked;
102-
},
103-
104-
getIndeterminateState(props) {
105-
const { store, data } = this;
106-
let indeterminate;
107-
if (!data.length) {
108-
indeterminate = false;
109-
} else {
110-
indeterminate = store.getState().selectionDirty
111-
? this.checkSelection(props, data, 'some', false) &&
112-
!this.checkSelection(props, data, 'every', false)
113-
: (this.checkSelection(props, data, 'some', false) &&
114-
!this.checkSelection(props, data, 'every', false)) ||
115-
(this.checkSelection(props, data, 'some', true) &&
116-
!this.checkSelection(props, data, 'every', true));
117-
}
118-
return indeterminate;
119-
},
120-
121162
handleSelectAllChange(e) {
122-
const checked = e.target.checked;
163+
const { checked } = e.target;
123164
this.$emit('select', checked ? 'all' : 'removeAll', 0, null);
124165
},
166+
subscribe() {
167+
const { store } = this;
168+
this.unsubscribe = store.subscribe(() => {
169+
this.setCheckState(this.$props);
170+
});
171+
},
125172

126173
renderMenus(selections) {
127174
return selections.map((selection, index) => {

0 commit comments

Comments
 (0)