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
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import Checkbox from '../checkbox';
import Radio from '../radio';
import { SelectionBoxProps } from './interface';
import BaseMixin from '../_util/BaseMixin';
import { getOptionProps } from '../_util/props-util';
export default {
name: 'SelectionBox',
mixins: [BaseMixin],
props: SelectionBoxProps,
data: function data() {
return {
checked: this.getCheckState(this.$props)
};
},
mounted: function mounted() {
this.subscribe();
},
beforeDestroy: function beforeDestroy() {
if (this.unsubscribe) {
this.unsubscribe();
}
},
methods: {
subscribe: function subscribe() {
var _this = this;
var store = this.store;
this.unsubscribe = store.subscribe(function () {
var checked = _this.getCheckState(_this.$props);
_this.setState({ checked: checked });
});
},
getCheckState: function getCheckState(props) {
var store = props.store,
defaultSelection = props.defaultSelection,
rowIndex = props.rowIndex;
var checked = false;
if (store.getState().selectionDirty) {
checked = store.getState().selectedRowKeys.indexOf(rowIndex) >= 0;
} else {
checked = store.getState().selectedRowKeys.indexOf(rowIndex) >= 0 || defaultSelection.indexOf(rowIndex) >= 0;
}
return checked;
}
},
render: function render() {
var h = arguments[0];
var _getOptionProps = getOptionProps(this),
type = _getOptionProps.type,
rowIndex = _getOptionProps.rowIndex,
rest = _objectWithoutProperties(_getOptionProps, ['type', 'rowIndex']);
var checked = this.checked,
$attrs = this.$attrs,
$listeners = this.$listeners;
var checkboxProps = {
props: _extends({
checked: checked
}, rest),
attrs: $attrs,
on: $listeners
};
if (type === 'radio') {
checkboxProps.props.value = rowIndex;
return h(Radio, checkboxProps);
} else {
return h(Checkbox, checkboxProps);
}
}
};