HeaderRow.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(props) {
  13. const tableContext = useInjectTable();
  14. return () => {
  15. const {
  16. prefixCls,
  17. direction
  18. } = tableContext;
  19. const {
  20. cells,
  21. stickyOffsets,
  22. flattenColumns,
  23. rowComponent: RowComponent,
  24. cellComponent: CellComponent,
  25. customHeaderRow,
  26. index
  27. } = props;
  28. let rowProps;
  29. if (customHeaderRow) {
  30. rowProps = customHeaderRow(cells.map(cell => cell.column), index);
  31. }
  32. const columnsKey = getColumnsKey(cells.map(cell => cell.column));
  33. return _createVNode(RowComponent, rowProps, {
  34. default: () => [cells.map((cell, cellIndex) => {
  35. const {
  36. column
  37. } = cell;
  38. const fixedInfo = getCellFixedInfo(cell.colStart, cell.colEnd, flattenColumns, stickyOffsets, direction);
  39. let additionalProps;
  40. if (column && column.customHeaderCell) {
  41. additionalProps = cell.column.customHeaderCell(column);
  42. }
  43. const col = column;
  44. return _createVNode(Cell, _objectSpread(_objectSpread(_objectSpread({}, cell), {}, {
  45. "cellType": "header",
  46. "ellipsis": column.ellipsis,
  47. "align": column.align,
  48. "component": CellComponent,
  49. "prefixCls": prefixCls,
  50. "key": columnsKey[cellIndex]
  51. }, fixedInfo), {}, {
  52. "additionalProps": additionalProps,
  53. "rowType": "header",
  54. "column": column
  55. }), {
  56. default: () => column.title,
  57. dragHandle: () => col.resizable ? _createVNode(DragHandleVue, {
  58. "prefixCls": prefixCls,
  59. "width": col.width,
  60. "minWidth": col.minWidth,
  61. "maxWidth": col.maxWidth,
  62. "column": col
  63. }, null) : null
  64. });
  65. })]
  66. });
  67. };
  68. }
  69. });