HeaderRow.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
  3. import { defineComponent } from 'vue';
  4. import Cell from '../Cell';
  5. import { useInjectTable } from '../context/TableContext';
  6. import { getCellFixedInfo } from '../utils/fixUtil';
  7. import { getColumnsKey } from '../utils/valueUtil';
  8. import DragHandleVue from './DragHandle';
  9. export default defineComponent({
  10. name: 'HeaderRow',
  11. props: ['cells', 'stickyOffsets', 'flattenColumns', 'rowComponent', 'cellComponent', 'index', 'customHeaderRow'],
  12. setup: function setup(props) {
  13. var tableContext = useInjectTable();
  14. return function () {
  15. var prefixCls = tableContext.prefixCls,
  16. direction = tableContext.direction;
  17. var cells = props.cells,
  18. stickyOffsets = props.stickyOffsets,
  19. flattenColumns = props.flattenColumns,
  20. RowComponent = props.rowComponent,
  21. CellComponent = props.cellComponent,
  22. customHeaderRow = props.customHeaderRow,
  23. index = props.index;
  24. var rowProps;
  25. if (customHeaderRow) {
  26. rowProps = customHeaderRow(cells.map(function (cell) {
  27. return cell.column;
  28. }), index);
  29. }
  30. var columnsKey = getColumnsKey(cells.map(function (cell) {
  31. return cell.column;
  32. }));
  33. return _createVNode(RowComponent, rowProps, {
  34. default: function _default() {
  35. return [cells.map(function (cell, cellIndex) {
  36. var column = cell.column;
  37. var fixedInfo = getCellFixedInfo(cell.colStart, cell.colEnd, flattenColumns, stickyOffsets, direction);
  38. var additionalProps;
  39. if (column && column.customHeaderCell) {
  40. additionalProps = cell.column.customHeaderCell(column);
  41. }
  42. var col = column;
  43. return _createVNode(Cell, _objectSpread(_objectSpread(_objectSpread({}, cell), {}, {
  44. "cellType": "header",
  45. "ellipsis": column.ellipsis,
  46. "align": column.align,
  47. "component": CellComponent,
  48. "prefixCls": prefixCls,
  49. "key": columnsKey[cellIndex]
  50. }, fixedInfo), {}, {
  51. "additionalProps": additionalProps,
  52. "rowType": "header",
  53. "column": column
  54. }), {
  55. default: function _default() {
  56. return column.title;
  57. },
  58. dragHandle: function dragHandle() {
  59. return col.resizable ? _createVNode(DragHandleVue, {
  60. "prefixCls": prefixCls,
  61. "width": col.width,
  62. "minWidth": col.minWidth,
  63. "maxWidth": col.maxWidth,
  64. "column": col
  65. }, null) : null;
  66. }
  67. });
  68. })];
  69. }
  70. });
  71. };
  72. }
  73. });