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
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _checkbox = require('../checkbox');
var _checkbox2 = _interopRequireDefault(_checkbox);
var _radio = require('../radio');
var _radio2 = _interopRequireDefault(_radio);
var _interface = require('./interface');
var _BaseMixin = require('../_util/BaseMixin');
var _BaseMixin2 = _interopRequireDefault(_BaseMixin);
var _propsUtil = require('../_util/props-util');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
exports['default'] = {
name: 'SelectionBox',
mixins: [_BaseMixin2['default']],
props: _interface.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 = (0, _propsUtil.getOptionProps)(this),
type = _getOptionProps.type,
rowIndex = _getOptionProps.rowIndex,
rest = (0, _objectWithoutProperties3['default'])(_getOptionProps, ['type', 'rowIndex']);
var checked = this.checked,
$attrs = this.$attrs,
$listeners = this.$listeners;
var checkboxProps = {
props: (0, _extends3['default'])({
checked: checked
}, rest),
attrs: $attrs,
on: $listeners
};
if (type === 'radio') {
checkboxProps.props.value = rowIndex;
return h(_radio2['default'], checkboxProps);
} else {
return h(_checkbox2['default'], checkboxProps);
}
}
};