You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/table/createBodyRow.jsx

60 lines
1.3 KiB

import PropTypes from '../_util/vue-types';
7 years ago
import { Store } from './createStore';
7 years ago
const BodyRowProps = {
store: Store,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
7 years ago
prefixCls: PropTypes.string,
};
7 years ago
export default function createTableRow(Component = 'tr') {
7 years ago
const BodyRow = {
name: 'BodyRow',
props: BodyRowProps,
data() {
const { selectedRowKeys } = this.store.getState();
7 years ago
return {
selected: selectedRowKeys.indexOf(this.rowKey) >= 0,
};
7 years ago
},
mounted() {
this.subscribe();
7 years ago
},
beforeDestroy() {
7 years ago
if (this.unsubscribe) {
this.unsubscribe();
7 years ago
}
},
methods: {
subscribe() {
const { store, rowKey } = this;
7 years ago
this.unsubscribe = store.subscribe(() => {
const { selectedRowKeys } = this.store.getState();
const selected = selectedRowKeys.indexOf(rowKey) >= 0;
7 years ago
if (selected !== this.selected) {
this.selected = selected;
7 years ago
}
});
7 years ago
},
},
render() {
7 years ago
const className = {
7 years ago
[`${this.prefixCls}-row-selected`]: this.selected,
};
7 years ago
return (
<Component class={className} {...{ on: this.$listeners }}>
7 years ago
{this.$slots.default}
</Component>
);
7 years ago
},
};
7 years ago
return BodyRow;
7 years ago
}