a5cb1c6ac57459b32ad742af90f86885ca90d87d6d40a0f866c4d24d1daa6b95dadab3d63cd93330d30788f98a0f8f3f024467c06c658c016ed21e5ad063b5 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var descriptionsRow = require('./descriptions-row2.js');
  5. var token = require('./token.js');
  6. var description = require('./description.js');
  7. var constants = require('./constants.js');
  8. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  9. var index = require('../../../hooks/use-namespace/index.js');
  10. var useFormCommonProps = require('../../form/src/hooks/use-form-common-props.js');
  11. var vnode = require('../../../utils/vue/vnode.js');
  12. const __default__ = vue.defineComponent({
  13. name: "ElDescriptions"
  14. });
  15. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  16. ...__default__,
  17. props: description.descriptionProps,
  18. setup(__props) {
  19. const props = __props;
  20. const ns = index.useNamespace("descriptions");
  21. const descriptionsSize = useFormCommonProps.useFormSize();
  22. const slots = vue.useSlots();
  23. vue.provide(token.descriptionsKey, props);
  24. const descriptionKls = vue.computed(() => [ns.b(), ns.m(descriptionsSize.value)]);
  25. const filledNode = (node, span, count, isLast = false) => {
  26. if (!node.props) {
  27. node.props = {};
  28. }
  29. if (span > count) {
  30. node.props.span = count;
  31. }
  32. if (isLast) {
  33. node.props.span = span;
  34. }
  35. return node;
  36. };
  37. const getRows = () => {
  38. if (!slots.default)
  39. return [];
  40. const children = vnode.flattedChildren(slots.default()).filter((node) => {
  41. var _a;
  42. return ((_a = node == null ? void 0 : node.type) == null ? void 0 : _a.name) === constants.COMPONENT_NAME;
  43. });
  44. const rows = [];
  45. let temp = [];
  46. let count = props.column;
  47. let totalSpan = 0;
  48. const rowspanTemp = [];
  49. children.forEach((node, index) => {
  50. var _a, _b, _c;
  51. const span = ((_a = node.props) == null ? void 0 : _a.span) || 1;
  52. const rowspan = ((_b = node.props) == null ? void 0 : _b.rowspan) || 1;
  53. const rowNo = rows.length;
  54. rowspanTemp[rowNo] || (rowspanTemp[rowNo] = 0);
  55. if (rowspan > 1) {
  56. for (let i = 1; i < rowspan; i++) {
  57. rowspanTemp[_c = rowNo + i] || (rowspanTemp[_c] = 0);
  58. rowspanTemp[rowNo + i]++;
  59. totalSpan++;
  60. }
  61. }
  62. if (rowspanTemp[rowNo] > 0) {
  63. count -= rowspanTemp[rowNo];
  64. rowspanTemp[rowNo] = 0;
  65. }
  66. if (index < children.length - 1) {
  67. totalSpan += span > count ? count : span;
  68. }
  69. if (index === children.length - 1) {
  70. const lastSpan = props.column - totalSpan % props.column;
  71. temp.push(filledNode(node, lastSpan, count, true));
  72. rows.push(temp);
  73. return;
  74. }
  75. if (span < count) {
  76. count -= span;
  77. temp.push(node);
  78. } else {
  79. temp.push(filledNode(node, span, count));
  80. rows.push(temp);
  81. count = props.column;
  82. temp = [];
  83. }
  84. });
  85. return rows;
  86. };
  87. return (_ctx, _cache) => {
  88. return vue.openBlock(), vue.createElementBlock("div", {
  89. class: vue.normalizeClass(vue.unref(descriptionKls))
  90. }, [
  91. _ctx.title || _ctx.extra || _ctx.$slots.title || _ctx.$slots.extra ? (vue.openBlock(), vue.createElementBlock("div", {
  92. key: 0,
  93. class: vue.normalizeClass(vue.unref(ns).e("header"))
  94. }, [
  95. vue.createElementVNode("div", {
  96. class: vue.normalizeClass(vue.unref(ns).e("title"))
  97. }, [
  98. vue.renderSlot(_ctx.$slots, "title", {}, () => [
  99. vue.createTextVNode(vue.toDisplayString(_ctx.title), 1)
  100. ])
  101. ], 2),
  102. vue.createElementVNode("div", {
  103. class: vue.normalizeClass(vue.unref(ns).e("extra"))
  104. }, [
  105. vue.renderSlot(_ctx.$slots, "extra", {}, () => [
  106. vue.createTextVNode(vue.toDisplayString(_ctx.extra), 1)
  107. ])
  108. ], 2)
  109. ], 2)) : vue.createCommentVNode("v-if", true),
  110. vue.createElementVNode("div", {
  111. class: vue.normalizeClass(vue.unref(ns).e("body"))
  112. }, [
  113. vue.createElementVNode("table", {
  114. class: vue.normalizeClass([vue.unref(ns).e("table"), vue.unref(ns).is("bordered", _ctx.border)])
  115. }, [
  116. vue.createElementVNode("tbody", null, [
  117. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(getRows(), (row, _index) => {
  118. return vue.openBlock(), vue.createBlock(descriptionsRow["default"], {
  119. key: _index,
  120. row
  121. }, null, 8, ["row"]);
  122. }), 128))
  123. ])
  124. ], 2)
  125. ], 2)
  126. ], 2);
  127. };
  128. }
  129. });
  130. var Descriptions = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "description.vue"]]);
  131. exports["default"] = Descriptions;
  132. //# sourceMappingURL=description2.js.map