4c75df9db5eb9f7098af5d221f623bb3ed1f362cf47f1d051aef65bb61a074379c4bf877af448b043be3ddd3e624500414d87c8747fc3b86f3b6dd3f73497d 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import { defineComponent, getCurrentInstance, ref, computed, onBeforeMount, onMounted, onBeforeUnmount, Fragment, h } from 'vue';
  2. import { ElCheckbox } from '../../../checkbox/index.mjs';
  3. import { cellStarts } from '../config.mjs';
  4. import { mergeOptions, compose } from '../util.mjs';
  5. import useWatcher from './watcher-helper.mjs';
  6. import useRender from './render-helper.mjs';
  7. import defaultProps from './defaults.mjs';
  8. import { isUndefined } from '../../../../utils/types.mjs';
  9. import { isArray, isString } from '@vue/shared';
  10. let columnIdSeed = 1;
  11. var ElTableColumn = defineComponent({
  12. name: "ElTableColumn",
  13. components: {
  14. ElCheckbox
  15. },
  16. props: defaultProps,
  17. setup(props, { slots }) {
  18. const instance = getCurrentInstance();
  19. const columnConfig = ref({});
  20. const owner = computed(() => {
  21. let parent2 = instance.parent;
  22. while (parent2 && !parent2.tableId) {
  23. parent2 = parent2.parent;
  24. }
  25. return parent2;
  26. });
  27. const { registerNormalWatchers, registerComplexWatchers } = useWatcher(owner, props);
  28. const {
  29. columnId,
  30. isSubColumn,
  31. realHeaderAlign,
  32. columnOrTableParent,
  33. setColumnWidth,
  34. setColumnForcedProps,
  35. setColumnRenders,
  36. getPropsData,
  37. getColumnElIndex,
  38. realAlign,
  39. updateColumnOrder
  40. } = useRender(props, slots, owner);
  41. const parent = columnOrTableParent.value;
  42. columnId.value = `${"tableId" in parent && parent.tableId || "columnId" in parent && parent.columnId}_column_${columnIdSeed++}`;
  43. onBeforeMount(() => {
  44. isSubColumn.value = owner.value !== parent;
  45. const type = props.type || "default";
  46. const sortable = props.sortable === "" ? true : props.sortable;
  47. const showOverflowTooltip = type === "selection" ? false : isUndefined(props.showOverflowTooltip) ? parent.props.showOverflowTooltip : props.showOverflowTooltip;
  48. const tooltipFormatter = isUndefined(props.tooltipFormatter) ? parent.props.tooltipFormatter : props.tooltipFormatter;
  49. const defaults = {
  50. ...cellStarts[type],
  51. id: columnId.value,
  52. type,
  53. property: props.prop || props.property,
  54. align: realAlign,
  55. headerAlign: realHeaderAlign,
  56. showOverflowTooltip,
  57. tooltipFormatter,
  58. filterable: props.filters || props.filterMethod,
  59. filteredValue: [],
  60. filterPlacement: "",
  61. filterClassName: "",
  62. isColumnGroup: false,
  63. isSubColumn: false,
  64. filterOpened: false,
  65. sortable,
  66. index: props.index,
  67. rawColumnKey: instance.vnode.key
  68. };
  69. const basicProps = [
  70. "columnKey",
  71. "label",
  72. "className",
  73. "labelClassName",
  74. "type",
  75. "renderHeader",
  76. "formatter",
  77. "fixed",
  78. "resizable"
  79. ];
  80. const sortProps = ["sortMethod", "sortBy", "sortOrders"];
  81. const selectProps = ["selectable", "reserveSelection"];
  82. const filterProps = [
  83. "filterMethod",
  84. "filters",
  85. "filterMultiple",
  86. "filterOpened",
  87. "filteredValue",
  88. "filterPlacement",
  89. "filterClassName"
  90. ];
  91. let column = getPropsData(basicProps, sortProps, selectProps, filterProps);
  92. column = mergeOptions(defaults, column);
  93. const chains = compose(setColumnRenders, setColumnWidth, setColumnForcedProps);
  94. column = chains(column);
  95. columnConfig.value = column;
  96. registerNormalWatchers();
  97. registerComplexWatchers();
  98. });
  99. onMounted(() => {
  100. var _a, _b;
  101. const parent2 = columnOrTableParent.value;
  102. const children = isSubColumn.value ? (_a = parent2.vnode.el) == null ? void 0 : _a.children : (_b = parent2.refs.hiddenColumns) == null ? void 0 : _b.children;
  103. const getColumnIndex = () => getColumnElIndex(children || [], instance.vnode.el);
  104. columnConfig.value.getColumnIndex = getColumnIndex;
  105. const columnIndex = getColumnIndex();
  106. columnIndex > -1 && owner.value.store.commit("insertColumn", columnConfig.value, isSubColumn.value ? "columnConfig" in parent2 && parent2.columnConfig.value : null, updateColumnOrder);
  107. });
  108. onBeforeUnmount(() => {
  109. const getColumnIndex = columnConfig.value.getColumnIndex;
  110. const columnIndex = getColumnIndex ? getColumnIndex() : -1;
  111. columnIndex > -1 && owner.value.store.commit("removeColumn", columnConfig.value, isSubColumn.value ? "columnConfig" in parent && parent.columnConfig.value : null, updateColumnOrder);
  112. });
  113. instance.columnId = columnId.value;
  114. instance.columnConfig = columnConfig;
  115. return;
  116. },
  117. render() {
  118. var _a, _b, _c;
  119. try {
  120. const renderDefault = (_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a, {
  121. row: {},
  122. column: {},
  123. $index: -1
  124. });
  125. const children = [];
  126. if (isArray(renderDefault)) {
  127. for (const childNode of renderDefault) {
  128. if (((_c = childNode.type) == null ? void 0 : _c.name) === "ElTableColumn" || childNode.shapeFlag & 2) {
  129. children.push(childNode);
  130. } else if (childNode.type === Fragment && isArray(childNode.children)) {
  131. childNode.children.forEach((vnode2) => {
  132. if ((vnode2 == null ? void 0 : vnode2.patchFlag) !== 1024 && !isString(vnode2 == null ? void 0 : vnode2.children)) {
  133. children.push(vnode2);
  134. }
  135. });
  136. }
  137. }
  138. }
  139. const vnode = h("div", children);
  140. return vnode;
  141. } catch (e) {
  142. return h("div", []);
  143. }
  144. }
  145. });
  146. export { ElTableColumn as default };
  147. //# sourceMappingURL=index.mjs.map