2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2021-02-27 14:50:21 +00:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2020-07-23 10:34:24 +00:00
|
|
|
import { getSlot } from '../_util/props-util';
|
2020-10-23 06:29:39 +00:00
|
|
|
import omit from 'omit.js';
|
2018-03-29 14:08:04 +00:00
|
|
|
|
|
|
|
const BodyRowProps = {
|
2021-02-27 14:50:21 +00:00
|
|
|
store: PropTypes.object,
|
2019-01-12 03:33:27 +00:00
|
|
|
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2018-03-29 14:08:04 +00:00
|
|
|
prefixCls: PropTypes.string,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-29 14:08:04 +00:00
|
|
|
|
2020-03-07 11:45:13 +00:00
|
|
|
export default function createBodyRow(Component = 'tr') {
|
2020-10-23 06:29:39 +00:00
|
|
|
const BodyRow = defineComponent({
|
2018-03-29 14:08:04 +00:00
|
|
|
name: 'BodyRow',
|
2020-07-23 10:34:24 +00:00
|
|
|
inheritAttrs: false,
|
2018-03-29 14:08:04 +00:00
|
|
|
props: BodyRowProps,
|
2021-02-27 14:50:21 +00:00
|
|
|
setup(props) {
|
2020-11-07 07:37:17 +00:00
|
|
|
return {
|
2021-02-27 14:50:21 +00:00
|
|
|
selected: computed(() => props.store?.selectedRowKeys.indexOf(props.rowKey) >= 0),
|
2020-11-07 07:37:17 +00:00
|
|
|
};
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2020-10-23 06:29:39 +00:00
|
|
|
const rowProps = omit({ ...this.$props, ...this.$attrs }, [
|
2020-07-23 10:34:24 +00:00
|
|
|
'prefixCls',
|
|
|
|
'rowKey',
|
|
|
|
'store',
|
|
|
|
'class',
|
|
|
|
]);
|
2018-03-29 14:08:04 +00:00
|
|
|
const className = {
|
2018-03-31 13:11:02 +00:00
|
|
|
[`${this.prefixCls}-row-selected`]: this.selected,
|
2020-10-23 06:29:39 +00:00
|
|
|
[this.$attrs.class as string]: !!this.$attrs.class,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-29 14:08:04 +00:00
|
|
|
|
|
|
|
return (
|
2020-07-23 10:34:24 +00:00
|
|
|
<Component class={className} {...rowProps}>
|
|
|
|
{getSlot(this)}
|
2018-03-29 14:08:04 +00:00
|
|
|
</Component>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-03-29 14:08:04 +00:00
|
|
|
},
|
2020-10-23 06:29:39 +00:00
|
|
|
});
|
2018-03-29 14:08:04 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
return BodyRow;
|
2018-03-29 14:08:04 +00:00
|
|
|
}
|