2021-02-27 14:50:21 +00:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import Checkbox from '../checkbox';
|
|
|
|
import Radio from '../radio';
|
|
|
|
import { SelectionBoxProps } from './interface';
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
2020-07-23 10:34:24 +00:00
|
|
|
import { getOptionProps } from '../_util/props-util';
|
2018-03-30 14:00:55 +00:00
|
|
|
|
2020-10-23 06:29:39 +00:00
|
|
|
export default defineComponent({
|
2018-03-30 14:00:55 +00:00
|
|
|
name: 'SelectionBox',
|
2019-02-01 09:23:00 +00:00
|
|
|
mixins: [BaseMixin],
|
2020-07-23 10:34:24 +00:00
|
|
|
inheritAttrs: false,
|
2018-03-30 14:00:55 +00:00
|
|
|
props: SelectionBoxProps,
|
|
|
|
|
2021-02-27 14:50:21 +00:00
|
|
|
setup(props) {
|
2020-10-23 06:29:39 +00:00
|
|
|
return {
|
2021-02-27 14:50:21 +00:00
|
|
|
checked: computed(() => {
|
|
|
|
const { store, defaultSelection, rowIndex } = props;
|
|
|
|
let checked = false;
|
|
|
|
if (store.selectionDirty) {
|
|
|
|
checked = store.selectedRowKeys.indexOf(rowIndex) >= 0;
|
|
|
|
} else {
|
|
|
|
checked =
|
|
|
|
store.selectedRowKeys.indexOf(rowIndex) >= 0 || defaultSelection.indexOf(rowIndex) >= 0;
|
|
|
|
}
|
|
|
|
return checked;
|
|
|
|
}),
|
2020-10-23 06:29:39 +00:00
|
|
|
};
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2020-10-23 06:29:39 +00:00
|
|
|
const { type, rowIndex, ...rest } = { ...getOptionProps(this), ...this.$attrs } as any;
|
2020-01-18 08:14:42 +00:00
|
|
|
const { checked } = this;
|
2018-03-30 14:00:55 +00:00
|
|
|
const checkboxProps = {
|
2020-07-23 10:34:24 +00:00
|
|
|
checked,
|
|
|
|
...rest,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-30 14:00:55 +00:00
|
|
|
if (type === 'radio') {
|
2020-07-23 10:34:24 +00:00
|
|
|
checkboxProps.value = rowIndex;
|
2019-01-12 03:33:27 +00:00
|
|
|
return <Radio {...checkboxProps} />;
|
2018-03-30 14:00:55 +00:00
|
|
|
}
|
2020-03-07 11:45:13 +00:00
|
|
|
return <Checkbox {...checkboxProps} />;
|
2018-03-30 14:00:55 +00:00
|
|
|
},
|
2020-10-23 06:29:39 +00:00
|
|
|
});
|