8bce3d2e00bfff402b8f158e87a59fc5302da0c0d8bb99ce088c33f7f2c784fbe470be56e3ec0d8ae27a758945ccceae0f967e1650c393295f6dcb7973e84a 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var config = require('../config.js');
  5. var util = require('../util.js');
  6. var index = require('../../../../hooks/use-namespace/index.js');
  7. var types = require('../../../../utils/types.js');
  8. var shared = require('@vue/shared');
  9. function useRender(props, slots, owner) {
  10. const instance = vue.getCurrentInstance();
  11. const columnId = vue.ref("");
  12. const isSubColumn = vue.ref(false);
  13. const realAlign = vue.ref();
  14. const realHeaderAlign = vue.ref();
  15. const ns = index.useNamespace("table");
  16. vue.watchEffect(() => {
  17. realAlign.value = props.align ? `is-${props.align}` : null;
  18. realAlign.value;
  19. });
  20. vue.watchEffect(() => {
  21. realHeaderAlign.value = props.headerAlign ? `is-${props.headerAlign}` : realAlign.value;
  22. realHeaderAlign.value;
  23. });
  24. const columnOrTableParent = vue.computed(() => {
  25. let parent = instance.vnode.vParent || instance.parent;
  26. while (parent && !parent.tableId && !parent.columnId) {
  27. parent = parent.vnode.vParent || parent.parent;
  28. }
  29. return parent;
  30. });
  31. const hasTreeColumn = vue.computed(() => {
  32. const { store } = instance.parent;
  33. if (!store)
  34. return false;
  35. const { treeData } = store.states;
  36. const treeDataValue = treeData.value;
  37. return treeDataValue && Object.keys(treeDataValue).length > 0;
  38. });
  39. const realWidth = vue.ref(util.parseWidth(props.width));
  40. const realMinWidth = vue.ref(util.parseMinWidth(props.minWidth));
  41. const setColumnWidth = (column) => {
  42. if (realWidth.value)
  43. column.width = realWidth.value;
  44. if (realMinWidth.value) {
  45. column.minWidth = realMinWidth.value;
  46. }
  47. if (!realWidth.value && realMinWidth.value) {
  48. column.width = void 0;
  49. }
  50. if (!column.minWidth) {
  51. column.minWidth = 80;
  52. }
  53. column.realWidth = Number(types.isUndefined(column.width) ? column.minWidth : column.width);
  54. return column;
  55. };
  56. const setColumnForcedProps = (column) => {
  57. const type = column.type;
  58. const source = config.cellForced[type] || {};
  59. Object.keys(source).forEach((prop) => {
  60. const value = source[prop];
  61. if (prop !== "className" && !types.isUndefined(value)) {
  62. column[prop] = value;
  63. }
  64. });
  65. const className = config.getDefaultClassName(type);
  66. if (className) {
  67. const forceClass = `${vue.unref(ns.namespace)}-${className}`;
  68. column.className = column.className ? `${column.className} ${forceClass}` : forceClass;
  69. }
  70. return column;
  71. };
  72. const checkSubColumn = (children) => {
  73. if (shared.isArray(children)) {
  74. children.forEach((child) => check(child));
  75. } else {
  76. check(children);
  77. }
  78. function check(item) {
  79. var _a;
  80. if (((_a = item == null ? void 0 : item.type) == null ? void 0 : _a.name) === "ElTableColumn") {
  81. item.vParent = instance;
  82. }
  83. }
  84. };
  85. const setColumnRenders = (column) => {
  86. if (props.renderHeader) ; else if (column.type !== "selection") {
  87. column.renderHeader = (scope) => {
  88. instance.columnConfig.value["label"];
  89. return vue.renderSlot(slots, "header", scope, () => [column.label]);
  90. };
  91. }
  92. if (slots["filter-icon"]) {
  93. column.renderFilterIcon = (scope) => {
  94. return vue.renderSlot(slots, "filter-icon", scope);
  95. };
  96. }
  97. if (slots.expand) {
  98. column.renderExpand = (scope) => {
  99. return vue.renderSlot(slots, "expand", scope);
  100. };
  101. }
  102. let originRenderCell = column.renderCell;
  103. if (column.type === "expand") {
  104. column.renderCell = (data) => vue.h("div", {
  105. class: "cell"
  106. }, [originRenderCell(data)]);
  107. owner.value.renderExpanded = (row) => {
  108. return slots.default ? slots.default(row) : slots.default;
  109. };
  110. } else {
  111. originRenderCell = originRenderCell || config.defaultRenderCell;
  112. column.renderCell = (data) => {
  113. let children = null;
  114. if (slots.default) {
  115. const vnodes = slots.default(data);
  116. children = vnodes.some((v) => v.type !== vue.Comment) ? vnodes : originRenderCell(data);
  117. } else {
  118. children = originRenderCell(data);
  119. }
  120. const { columns } = owner.value.store.states;
  121. const firstUserColumnIndex = columns.value.findIndex((item) => item.type === "default");
  122. const shouldCreatePlaceholder = hasTreeColumn.value && data.cellIndex === firstUserColumnIndex;
  123. const prefix = config.treeCellPrefix(data, shouldCreatePlaceholder);
  124. const props2 = {
  125. class: "cell",
  126. style: {}
  127. };
  128. if (column.showOverflowTooltip) {
  129. props2.class = `${props2.class} ${vue.unref(ns.namespace)}-tooltip`;
  130. props2.style = {
  131. width: `${(data.column.realWidth || Number(data.column.width)) - 1}px`
  132. };
  133. }
  134. checkSubColumn(children);
  135. return vue.h("div", props2, [prefix, children]);
  136. };
  137. }
  138. return column;
  139. };
  140. const getPropsData = (...propsKey) => {
  141. return propsKey.reduce((prev, cur) => {
  142. if (shared.isArray(cur)) {
  143. cur.forEach((key) => {
  144. prev[key] = props[key];
  145. });
  146. }
  147. return prev;
  148. }, {});
  149. };
  150. const getColumnElIndex = (children, child) => {
  151. return Array.prototype.indexOf.call(children, child);
  152. };
  153. const updateColumnOrder = () => {
  154. owner.value.store.commit("updateColumnOrder", instance.columnConfig.value);
  155. };
  156. return {
  157. columnId,
  158. realAlign,
  159. isSubColumn,
  160. realHeaderAlign,
  161. columnOrTableParent,
  162. setColumnWidth,
  163. setColumnForcedProps,
  164. setColumnRenders,
  165. getPropsData,
  166. getColumnElIndex,
  167. updateColumnOrder
  168. };
  169. }
  170. exports["default"] = useRender;
  171. //# sourceMappingURL=render-helper.js.map