BodyRow.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _vue = require("vue");
  8. var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
  9. var _Cell = _interopRequireDefault(require("../Cell"));
  10. var _valueUtil = require("../utils/valueUtil");
  11. var _ExpandedRow = _interopRequireDefault(require("./ExpandedRow"));
  12. var _TableContext = require("../context/TableContext");
  13. var _BodyContext = require("../context/BodyContext");
  14. var _classNames = _interopRequireDefault(require("../../_util/classNames"));
  15. var _propsUtil = require("../../_util/props-util");
  16. var _default2 = (0, _vue.defineComponent)({
  17. name: 'BodyRow',
  18. inheritAttrs: false,
  19. props: ['record', 'index', 'renderIndex', 'recordKey', 'expandedKeys', 'rowComponent', 'cellComponent', 'customRow', 'rowExpandable', 'indent', 'rowKey', 'getRowKey', 'childrenColumnName'],
  20. setup: function setup(props, _ref) {
  21. var attrs = _ref.attrs;
  22. var tableContext = (0, _TableContext.useInjectTable)();
  23. var bodyContext = (0, _BodyContext.useInjectBody)();
  24. var expandRended = (0, _vue.ref)(false);
  25. var expanded = (0, _vue.computed)(function () {
  26. return props.expandedKeys && props.expandedKeys.has(props.recordKey);
  27. });
  28. (0, _vue.watchEffect)(function () {
  29. if (expanded.value) {
  30. expandRended.value = true;
  31. }
  32. });
  33. var rowSupportExpand = (0, _vue.computed)(function () {
  34. return bodyContext.expandableType === 'row' && (!props.rowExpandable || props.rowExpandable(props.record));
  35. });
  36. // Only when row is not expandable and `children` exist in record
  37. var nestExpandable = (0, _vue.computed)(function () {
  38. return bodyContext.expandableType === 'nest';
  39. });
  40. var hasNestChildren = (0, _vue.computed)(function () {
  41. return props.childrenColumnName && props.record && props.record[props.childrenColumnName];
  42. });
  43. var mergedExpandable = (0, _vue.computed)(function () {
  44. return rowSupportExpand.value || nestExpandable.value;
  45. });
  46. var onInternalTriggerExpand = function onInternalTriggerExpand(record, event) {
  47. bodyContext.onTriggerExpand(record, event);
  48. };
  49. // =========================== onRow ===========================
  50. var additionalProps = (0, _vue.computed)(function () {
  51. var _props$customRow;
  52. return ((_props$customRow = props.customRow) === null || _props$customRow === void 0 ? void 0 : _props$customRow.call(props, props.record, props.index)) || {};
  53. });
  54. var onClick = function onClick(event) {
  55. var _additionalProps$valu, _additionalProps$valu2;
  56. if (bodyContext.expandRowByClick && mergedExpandable.value) {
  57. onInternalTriggerExpand(props.record, event);
  58. }
  59. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  60. args[_key - 1] = arguments[_key];
  61. }
  62. (_additionalProps$valu = additionalProps.value) === null || _additionalProps$valu === void 0 ? void 0 : (_additionalProps$valu2 = _additionalProps$valu.onClick) === null || _additionalProps$valu2 === void 0 ? void 0 : _additionalProps$valu2.call.apply(_additionalProps$valu2, [_additionalProps$valu, event].concat(args));
  63. };
  64. var computeRowClassName = (0, _vue.computed)(function () {
  65. var record = props.record,
  66. index = props.index,
  67. indent = props.indent;
  68. var rowClassName = bodyContext.rowClassName;
  69. if (typeof rowClassName === 'string') {
  70. return rowClassName;
  71. } else if (typeof rowClassName === 'function') {
  72. return rowClassName(record, index, indent);
  73. }
  74. return '';
  75. });
  76. var columnsKey = (0, _vue.computed)(function () {
  77. return (0, _valueUtil.getColumnsKey)(bodyContext.flattenColumns);
  78. });
  79. return function () {
  80. var className = attrs.class,
  81. style = attrs.style;
  82. var record = props.record,
  83. index = props.index,
  84. rowKey = props.rowKey,
  85. _props$indent = props.indent,
  86. indent = _props$indent === void 0 ? 0 : _props$indent,
  87. RowComponent = props.rowComponent,
  88. cellComponent = props.cellComponent;
  89. var prefixCls = tableContext.prefixCls,
  90. fixedInfoList = tableContext.fixedInfoList,
  91. transformCellText = tableContext.transformCellText;
  92. var flattenColumns = bodyContext.flattenColumns,
  93. expandedRowClassName = bodyContext.expandedRowClassName,
  94. indentSize = bodyContext.indentSize,
  95. expandIcon = bodyContext.expandIcon,
  96. expandedRowRender = bodyContext.expandedRowRender,
  97. expandIconColumnIndex = bodyContext.expandIconColumnIndex;
  98. var baseRowNode = (0, _vue.createVNode)(RowComponent, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, additionalProps.value), {}, {
  99. "data-row-key": rowKey,
  100. "class": (0, _classNames.default)(className, "".concat(prefixCls, "-row"), "".concat(prefixCls, "-row-level-").concat(indent), computeRowClassName.value, additionalProps.value.class),
  101. "style": (0, _objectSpread2.default)((0, _objectSpread2.default)({}, style), (0, _propsUtil.parseStyleText)(additionalProps.value.style)),
  102. "onClick": onClick
  103. }), {
  104. default: function _default() {
  105. return [flattenColumns.map(function (column, colIndex) {
  106. var customRender = column.customRender,
  107. dataIndex = column.dataIndex,
  108. columnClassName = column.className;
  109. var key = columnsKey[colIndex];
  110. var fixedInfo = fixedInfoList[colIndex];
  111. var additionalCellProps;
  112. if (column.customCell) {
  113. additionalCellProps = column.customCell(record, index, column);
  114. }
  115. // not use slot to fix https://github.com/vueComponent/ant-design-vue/issues/5295
  116. var appendNode = colIndex === (expandIconColumnIndex || 0) && nestExpandable.value ? (0, _vue.createVNode)(_vue.Fragment, null, [(0, _vue.createVNode)("span", {
  117. "style": {
  118. paddingLeft: "".concat(indentSize * indent, "px")
  119. },
  120. "class": "".concat(prefixCls, "-row-indent indent-level-").concat(indent)
  121. }, null), expandIcon({
  122. prefixCls: prefixCls,
  123. expanded: expanded.value,
  124. expandable: hasNestChildren.value,
  125. record: record,
  126. onExpand: onInternalTriggerExpand
  127. })]) : null;
  128. return (0, _vue.createVNode)(_Cell.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({
  129. "cellType": "body",
  130. "class": columnClassName,
  131. "ellipsis": column.ellipsis,
  132. "align": column.align,
  133. "component": cellComponent,
  134. "prefixCls": prefixCls,
  135. "key": key,
  136. "record": record,
  137. "index": index,
  138. "renderIndex": props.renderIndex,
  139. "dataIndex": dataIndex,
  140. "customRender": customRender
  141. }, fixedInfo), {}, {
  142. "additionalProps": additionalCellProps,
  143. "column": column,
  144. "transformCellText": transformCellText,
  145. "appendNode": appendNode
  146. }), null);
  147. })];
  148. }
  149. });
  150. // ======================== Expand Row =========================
  151. var expandRowNode;
  152. if (rowSupportExpand.value && (expandRended.value || expanded.value)) {
  153. var expandContent = expandedRowRender({
  154. record: record,
  155. index: index,
  156. indent: indent + 1,
  157. expanded: expanded.value
  158. });
  159. var computedExpandedRowClassName = expandedRowClassName && expandedRowClassName(record, index, indent);
  160. expandRowNode = (0, _vue.createVNode)(_ExpandedRow.default, {
  161. "expanded": expanded.value,
  162. "class": (0, _classNames.default)("".concat(prefixCls, "-expanded-row"), "".concat(prefixCls, "-expanded-row-level-").concat(indent + 1), computedExpandedRowClassName),
  163. "prefixCls": prefixCls,
  164. "component": RowComponent,
  165. "cellComponent": cellComponent,
  166. "colSpan": flattenColumns.length,
  167. "isEmpty": false
  168. }, {
  169. default: function _default() {
  170. return [expandContent];
  171. }
  172. });
  173. }
  174. return (0, _vue.createVNode)(_vue.Fragment, null, [baseRowNode, expandRowNode]);
  175. };
  176. }
  177. });
  178. exports.default = _default2;