ant-design-vue/components/vc-table/src/TableRow.jsx

296 lines
7.2 KiB
Vue
Raw Normal View History

2019-01-12 03:33:27 +00:00
import classNames from 'classnames';
import PropTypes from '../../_util/vue-types';
import { connect } from '../../_util/store';
import TableCell from './TableCell';
import { warningOnce } from './utils';
import { initDefaultProps, mergeProps, getStyle } from '../../_util/props-util';
import BaseMixin from '../../_util/BaseMixin';
function noop() {}
2018-03-25 10:07:04 +00:00
const TableRow = {
name: 'TableRow',
mixins: [BaseMixin],
2019-01-12 03:33:27 +00:00
props: initDefaultProps(
{
customRow: PropTypes.func,
// onRowClick: PropTypes.func,
// onRowDoubleClick: PropTypes.func,
// onRowContextMenu: PropTypes.func,
// onRowMouseEnter: PropTypes.func,
// onRowMouseLeave: PropTypes.func,
record: PropTypes.object,
prefixCls: PropTypes.string,
// onHover: PropTypes.func,
columns: PropTypes.array,
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
index: PropTypes.number,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
className: PropTypes.string,
indent: PropTypes.number,
indentSize: PropTypes.number,
hasExpandIcon: PropTypes.func,
hovered: PropTypes.bool.isRequired,
visible: PropTypes.bool.isRequired,
store: PropTypes.object.isRequired,
fixed: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
renderExpandIcon: PropTypes.func,
renderExpandIconCell: PropTypes.func,
components: PropTypes.any,
expandedRow: PropTypes.bool,
isAnyColumnsFixed: PropTypes.bool,
ancestorKeys: PropTypes.array.isRequired,
expandIconColumnIndex: PropTypes.number,
expandRowByClick: PropTypes.bool,
// visible: PropTypes.bool,
// hovered: PropTypes.bool,
// height: PropTypes.any,
},
{
// expandIconColumnIndex: 0,
// expandRowByClick: false,
hasExpandIcon() {},
renderExpandIcon() {},
renderExpandIconCell() {},
},
),
data() {
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
// this.shouldRender = this.visible
return {
shouldRender: this.visible,
2019-01-12 03:33:27 +00:00
};
2018-03-25 10:07:04 +00:00
},
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
mounted() {
2018-03-24 14:02:24 +00:00
if (this.shouldRender) {
2018-03-25 10:07:04 +00:00
this.$nextTick(() => {
2019-01-12 03:33:27 +00:00
this.saveRowRef();
});
2018-03-24 14:02:24 +00:00
}
2018-03-25 10:07:04 +00:00
},
watch: {
2019-01-12 03:33:27 +00:00
visible(val) {
2018-03-25 14:23:04 +00:00
if (val) {
2019-01-12 03:33:27 +00:00
this.shouldRender = true;
2018-03-25 14:23:04 +00:00
}
},
2018-03-25 10:07:04 +00:00
},
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
updated() {
2018-03-24 14:02:24 +00:00
if (this.shouldRender && !this.rowRef) {
2018-03-25 10:07:04 +00:00
this.$nextTick(() => {
2019-01-12 03:33:27 +00:00
this.saveRowRef();
});
2018-03-24 14:02:24 +00:00
}
2018-03-25 10:07:04 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
onRowClick(event) {
const { record, index } = this;
this.__emit('rowClick', record, index, event);
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
onRowDoubleClick(event) {
const { record, index } = this;
this.__emit('rowDoubleClick', record, index, event);
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
onContextMenu(event) {
const { record, index } = this;
this.__emit('rowContextmenu', record, index, event);
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
onMouseEnter(event) {
const { record, index, rowKey } = this;
this.__emit('hover', true, rowKey);
this.__emit('rowMouseenter', record, index, event);
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
onMouseLeave(event) {
const { record, index, rowKey } = this;
this.__emit('hover', false, rowKey);
this.__emit('rowMouseleave', record, index, event);
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
setExpanedRowHeight() {
const { store, rowKey } = this;
let { expandedRowsHeight } = store.getState();
const height = this.rowRef.getBoundingClientRect().height;
2018-03-25 10:07:04 +00:00
expandedRowsHeight = {
...expandedRowsHeight,
[rowKey]: height,
2019-01-12 03:33:27 +00:00
};
store.setState({ expandedRowsHeight });
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
setRowHeight() {
const { store, rowKey } = this;
const { fixedColumnsBodyRowsHeight } = store.getState();
const height = this.rowRef.getBoundingClientRect().height;
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
store.setState({
fixedColumnsBodyRowsHeight: {
...fixedColumnsBodyRowsHeight,
[rowKey]: height,
},
2019-01-12 03:33:27 +00:00
});
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
getStyle() {
const { height, visible } = this;
let style = getStyle(this);
2018-03-26 15:05:29 +00:00
if (height) {
2019-01-12 03:33:27 +00:00
style = { ...style, height };
2018-03-25 10:07:04 +00:00
}
2018-03-26 15:05:29 +00:00
if (!visible && !style.display) {
2019-01-12 03:33:27 +00:00
style = { ...style, display: 'none' };
2018-03-25 10:07:04 +00:00
}
2019-01-12 03:33:27 +00:00
return style;
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
saveRowRef() {
this.rowRef = this.$el;
2018-03-25 10:07:04 +00:00
2019-01-12 03:33:27 +00:00
const { isAnyColumnsFixed, fixed, expandedRow, ancestorKeys } = this;
2018-03-25 10:07:04 +00:00
if (!isAnyColumnsFixed) {
2019-01-12 03:33:27 +00:00
return;
2018-03-25 10:07:04 +00:00
}
if (!fixed && expandedRow) {
2019-01-12 03:33:27 +00:00
this.setExpanedRowHeight();
2018-03-25 10:07:04 +00:00
}
if (!fixed && ancestorKeys.length >= 0) {
2019-01-12 03:33:27 +00:00
this.setRowHeight();
2018-03-25 10:07:04 +00:00
}
},
},
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
render() {
2018-03-24 14:02:24 +00:00
if (!this.shouldRender) {
2019-01-12 03:33:27 +00:00
return null;
2018-03-24 14:02:24 +00:00
}
const {
prefixCls,
columns,
record,
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
rowKey,
2018-03-24 14:02:24 +00:00
index,
2018-03-31 09:46:35 +00:00
customRow = noop,
2018-03-24 14:02:24 +00:00
indent,
indentSize,
hovered,
height,
visible,
components,
hasExpandIcon,
renderExpandIcon,
renderExpandIconCell,
2019-01-12 03:33:27 +00:00
} = this;
const BodyRow = components.body.row;
const BodyCell = components.body.cell;
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
let className = '';
2018-03-24 14:02:24 +00:00
if (hovered) {
2019-01-12 03:33:27 +00:00
className += ` ${prefixCls}-hover`;
2018-03-24 14:02:24 +00:00
}
2019-01-12 03:33:27 +00:00
const cells = [];
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
renderExpandIconCell(cells);
2018-03-24 14:02:24 +00:00
for (let i = 0; i < columns.length; i++) {
2019-01-12 03:33:27 +00:00
const column = columns[i];
2018-03-24 14:02:24 +00:00
warningOnce(
column.onCellClick === undefined,
2018-04-04 02:29:42 +00:00
'column[onCellClick] is deprecated, please use column[customCell] instead.',
2019-01-12 03:33:27 +00:00
);
2018-03-24 14:02:24 +00:00
cells.push(
<TableCell
prefixCls={prefixCls}
record={record}
indentSize={indentSize}
indent={indent}
index={index}
column={column}
key={column.key || column.dataIndex}
expandIcon={hasExpandIcon(i) && renderExpandIcon()}
component={BodyCell}
2019-01-12 03:33:27 +00:00
/>,
);
2018-03-24 14:02:24 +00:00
}
2019-01-12 03:33:27 +00:00
const { class: customClass, className: customClassName, style: customStyle, ...rowProps } =
customRow(record, index) || {};
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
let style = { height: typeof height === 'number' ? `${height}px` : height };
2018-03-24 14:02:24 +00:00
if (!visible) {
2019-01-12 03:33:27 +00:00
style.display = 'none';
2018-03-24 14:02:24 +00:00
}
2019-01-12 03:33:27 +00:00
style = { ...style, ...customStyle };
2018-11-09 10:57:25 +00:00
const rowClassName = classNames(
prefixCls,
className,
`${prefixCls}-level-${indent}`,
customClassName,
2019-01-12 03:33:27 +00:00
customClass,
);
const bodyRowProps = mergeProps(
{
on: {
click: this.onRowClick,
dblclick: this.onRowDoubleClick,
mouseenter: this.onMouseEnter,
mouseleave: this.onMouseLeave,
contextmenu: this.onContextMenu,
},
class: rowClassName,
2018-03-25 14:23:04 +00:00
},
2019-01-12 03:33:27 +00:00
{ ...rowProps, style },
{
attrs: {
'data-row-key': rowKey,
},
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
},
2019-01-12 03:33:27 +00:00
);
return <BodyRow {...bodyRowProps}>{cells}</BodyRow>;
2018-03-25 10:07:04 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
function getRowHeight(state, props) {
const { expandedRowsHeight, fixedColumnsBodyRowsHeight } = state;
const { fixed, rowKey } = props;
2018-03-24 14:02:24 +00:00
if (!fixed) {
2019-01-12 03:33:27 +00:00
return null;
2018-03-24 14:02:24 +00:00
}
if (expandedRowsHeight[rowKey]) {
2019-01-12 03:33:27 +00:00
return expandedRowsHeight[rowKey];
2018-03-24 14:02:24 +00:00
}
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
if (fixedColumnsBodyRowsHeight[rowKey]) {
2019-01-12 03:33:27 +00:00
return fixedColumnsBodyRowsHeight[rowKey];
2018-03-24 14:02:24 +00:00
}
2019-01-12 03:33:27 +00:00
return null;
2018-03-24 14:02:24 +00:00
}
export default connect((state, props) => {
2019-01-12 03:33:27 +00:00
const { currentHoverKey, expandedRowKeys } = state;
const { rowKey, ancestorKeys } = props;
const visible = ancestorKeys.length === 0 || ancestorKeys.every(k => ~expandedRowKeys.indexOf(k));
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
return {
2018-03-24 14:02:24 +00:00
visible,
hovered: currentHoverKey === rowKey,
height: getRowHeight(state, props),
2019-01-12 03:33:27 +00:00
};
})(TableRow);