STableToolbar.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. var x = Object.getOwnPropertySymbols;
  2. var O = Object.prototype.hasOwnProperty, P = Object.prototype.propertyIsEnumerable;
  3. var z = (o, u) => {
  4. var n = {};
  5. for (var r in o)
  6. O.call(o, r) && u.indexOf(r) < 0 && (n[r] = o[r]);
  7. if (o != null && x)
  8. for (var r of x(o))
  9. u.indexOf(r) < 0 && P.call(o, r) && (n[r] = o[r]);
  10. return n;
  11. };
  12. import { useAttrs as A, useSlots as B, ref as m, computed as k, onMounted as F, nextTick as w, onBeforeUnmount as H, resolveComponent as I, openBlock as y, createElementBlock as v, unref as V, createVNode as j, mergeProps as K, createSlots as X, withCtx as T, Fragment as R, renderSlot as C, createTextVNode as D, toDisplayString as L, createCommentVNode as M, renderList as U, normalizeProps as Y, guardReactiveProps as G } from "vue";
  13. import { n as J } from "./index2.js";
  14. const Q = ["id"], W = /* @__PURE__ */ Object.assign({ name: "STableToolbar" }, {
  15. __name: "STableToolbar",
  16. props: {
  17. // 列配置,原样透传给 s-table
  18. columns: {
  19. type: Array,
  20. default: () => []
  21. },
  22. // 数据加载函数,原样透传给 s-table
  23. data: {
  24. type: Function,
  25. required: !0
  26. },
  27. rowKey: {
  28. type: [String, Function],
  29. default: "id"
  30. },
  31. pageSize: {
  32. type: Number,
  33. default: 10
  34. },
  35. size: {
  36. type: String,
  37. default: "middle"
  38. },
  39. // 横向滚动,默认按容器宽度自适应
  40. scrollX: {
  41. type: [String, Number],
  42. default: "100%"
  43. },
  44. // 表体最小高度:空间足够时严格按可用高度算,空间不足时才退到这个下限内
  45. tableHeight: {
  46. type: Number,
  47. default: 300
  48. }
  49. },
  50. setup(o, { expose: u }) {
  51. const n = o, r = A(), d = B(), f = m(null), a = m(null), b = m(n.tableHeight), S = window.$utils.uuid(), N = k(() => z(r, [])), _ = k(() => ({ y: b.value - 8, x: n.scrollX }));
  52. function g(e) {
  53. return !!e && typeof d[e] == "function";
  54. }
  55. function $() {
  56. const e = {};
  57. return Object.keys(d).forEach((t) => {
  58. t === "bodyCell" || t === "default" || g(t) || (e[t] = d[t]);
  59. }), e;
  60. }
  61. function c() {
  62. const e = a.value && a.value.$el, t = e && e.querySelector(".ant-table-body"), i = t && t.clientHeight;
  63. i && (b.value = i);
  64. }
  65. function h(e = !0) {
  66. const t = a.value && a.value.refresh(e);
  67. return Promise.resolve(t).then(() => w(c)), t;
  68. }
  69. function q() {
  70. return h(!0);
  71. }
  72. let s = null;
  73. return F(() => {
  74. w(c), window.ResizeObserver && f.value && (s = new ResizeObserver(() => c()), s.observe(f.value)), setTimeout(() => {
  75. const e = document.querySelector(".ant-table-cell.ant-table-cell-scrollbar"), t = document.querySelector(`#${S.value} .ant-table-thead tr`);
  76. e && t && t.removeChild(e);
  77. }, 100);
  78. }), H(() => {
  79. s && (s.disconnect(), s = null);
  80. }), u({ resize: c, refresh: h, reload: q, tableRef: a, scrollY: b }), (e, t) => {
  81. const i = I("s-table");
  82. return y(), v("div", {
  83. class: "s-table-toolbar",
  84. id: V(S),
  85. ref_key: "rootRef",
  86. ref: f
  87. }, [
  88. j(i, K({
  89. ref_key: "tableRef",
  90. ref: a,
  91. "row-key": o.rowKey,
  92. columns: o.columns,
  93. data: o.data,
  94. "page-size": o.pageSize,
  95. size: o.size,
  96. scroll: _.value
  97. }, N.value), X({
  98. bodyCell: T((l) => [
  99. l.column ? (y(), v(R, { key: 0 }, [
  100. g(l.column.dataIndex) ? C(e.$slots, l.column.dataIndex, {
  101. text: l.text,
  102. record: l.record,
  103. index: l.index,
  104. column: l.column
  105. }, void 0, !0, 0) : (y(), v(R, { key: 1 }, [
  106. D(L(l.text), 1)
  107. ], 64))
  108. ], 64)) : M("", !0)
  109. ]),
  110. _: 2
  111. }, [
  112. U($(), (l, p) => ({
  113. name: p,
  114. fn: T((E) => [
  115. C(e.$slots, p, Y(G(E || {})), void 0, !0)
  116. ])
  117. }))
  118. ]), 1040, ["row-key", "columns", "data", "page-size", "size", "scroll"])
  119. ], 8, Q);
  120. };
  121. }
  122. }), oe = /* @__PURE__ */ J(W, [["__scopeId", "data-v-c0cb9030"]]);
  123. export {
  124. oe as default
  125. };