table.mjs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. import { defineComponent, getCurrentInstance, provide, computed, resolveComponent, resolveDirective, openBlock, createElementBlock, normalizeClass, normalizeStyle, createElementVNode, renderSlot, withDirectives, createVNode, createCommentVNode, withCtx, createBlock, createTextVNode, toDisplayString, vShow } from 'vue';
  2. import { debounce } from 'lodash-unified';
  3. import '../../../directives/index.mjs';
  4. import '../../../hooks/index.mjs';
  5. import { ElScrollbar } from '../../scrollbar/index.mjs';
  6. import { createStore } from './store/helper.mjs';
  7. import TableLayout from './table-layout.mjs';
  8. import TableHeader from './table-header/index.mjs';
  9. import TableBody from './table-body/index.mjs';
  10. import TableFooter from './table-footer/index.mjs';
  11. import useUtils from './table/utils-helper.mjs';
  12. import useStyle from './table/style-helper.mjs';
  13. import useKeyRender from './table/key-render-helper.mjs';
  14. import defaultProps from './table/defaults.mjs';
  15. import { TABLE_INJECTION_KEY } from './tokens.mjs';
  16. import { hColgroup } from './h-helper.mjs';
  17. import { useScrollbar } from './composables/use-scrollbar.mjs';
  18. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  19. import Mousewheel from '../../../directives/mousewheel/index.mjs';
  20. import { useLocale } from '../../../hooks/use-locale/index.mjs';
  21. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  22. let tableIdSeed = 1;
  23. const _sfc_main = defineComponent({
  24. name: "ElTable",
  25. directives: {
  26. Mousewheel
  27. },
  28. components: {
  29. TableHeader,
  30. TableBody,
  31. TableFooter,
  32. ElScrollbar,
  33. hColgroup
  34. },
  35. props: defaultProps,
  36. emits: [
  37. "select",
  38. "select-all",
  39. "selection-change",
  40. "cell-mouse-enter",
  41. "cell-mouse-leave",
  42. "cell-contextmenu",
  43. "cell-click",
  44. "cell-dblclick",
  45. "row-click",
  46. "row-contextmenu",
  47. "row-dblclick",
  48. "header-click",
  49. "header-contextmenu",
  50. "sort-change",
  51. "filter-change",
  52. "current-change",
  53. "header-dragend",
  54. "expand-change"
  55. ],
  56. setup(props) {
  57. const { t } = useLocale();
  58. const ns = useNamespace("table");
  59. const table = getCurrentInstance();
  60. provide(TABLE_INJECTION_KEY, table);
  61. const store = createStore(table, props);
  62. table.store = store;
  63. const layout = new TableLayout({
  64. store: table.store,
  65. table,
  66. fit: props.fit,
  67. showHeader: props.showHeader
  68. });
  69. table.layout = layout;
  70. const isEmpty = computed(() => (store.states.data.value || []).length === 0);
  71. const {
  72. setCurrentRow,
  73. getSelectionRows,
  74. toggleRowSelection,
  75. clearSelection,
  76. clearFilter,
  77. toggleAllSelection,
  78. toggleRowExpansion,
  79. clearSort,
  80. sort
  81. } = useUtils(store);
  82. const {
  83. isHidden,
  84. renderExpanded,
  85. setDragVisible,
  86. isGroup,
  87. handleMouseLeave,
  88. handleHeaderFooterMousewheel,
  89. tableSize,
  90. emptyBlockStyle,
  91. handleFixedMousewheel,
  92. resizeProxyVisible,
  93. bodyWidth,
  94. resizeState,
  95. doLayout,
  96. tableBodyStyles,
  97. tableLayout,
  98. scrollbarViewStyle,
  99. tableInnerStyle,
  100. scrollbarStyle
  101. } = useStyle(props, layout, store, table);
  102. const { scrollBarRef, scrollTo, setScrollLeft, setScrollTop } = useScrollbar();
  103. const debouncedUpdateLayout = debounce(doLayout, 50);
  104. const tableId = `${ns.namespace.value}-table_${tableIdSeed++}`;
  105. table.tableId = tableId;
  106. table.state = {
  107. isGroup,
  108. resizeState,
  109. doLayout,
  110. debouncedUpdateLayout
  111. };
  112. const computedSumText = computed(() => props.sumText || t("el.table.sumText"));
  113. const computedEmptyText = computed(() => {
  114. return props.emptyText || t("el.table.emptyText");
  115. });
  116. useKeyRender(table);
  117. return {
  118. ns,
  119. layout,
  120. store,
  121. handleHeaderFooterMousewheel,
  122. handleMouseLeave,
  123. tableId,
  124. tableSize,
  125. isHidden,
  126. isEmpty,
  127. renderExpanded,
  128. resizeProxyVisible,
  129. resizeState,
  130. isGroup,
  131. bodyWidth,
  132. tableBodyStyles,
  133. emptyBlockStyle,
  134. debouncedUpdateLayout,
  135. handleFixedMousewheel,
  136. setCurrentRow,
  137. getSelectionRows,
  138. toggleRowSelection,
  139. clearSelection,
  140. clearFilter,
  141. toggleAllSelection,
  142. toggleRowExpansion,
  143. clearSort,
  144. doLayout,
  145. sort,
  146. t,
  147. setDragVisible,
  148. context: table,
  149. computedSumText,
  150. computedEmptyText,
  151. tableLayout,
  152. scrollbarViewStyle,
  153. tableInnerStyle,
  154. scrollbarStyle,
  155. scrollBarRef,
  156. scrollTo,
  157. setScrollLeft,
  158. setScrollTop
  159. };
  160. }
  161. });
  162. const _hoisted_1 = ["data-prefix"];
  163. const _hoisted_2 = {
  164. ref: "hiddenColumns",
  165. class: "hidden-columns"
  166. };
  167. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  168. const _component_hColgroup = resolveComponent("hColgroup");
  169. const _component_table_header = resolveComponent("table-header");
  170. const _component_table_body = resolveComponent("table-body");
  171. const _component_table_footer = resolveComponent("table-footer");
  172. const _component_el_scrollbar = resolveComponent("el-scrollbar");
  173. const _directive_mousewheel = resolveDirective("mousewheel");
  174. return openBlock(), createElementBlock("div", {
  175. ref: "tableWrapper",
  176. class: normalizeClass([
  177. {
  178. [_ctx.ns.m("fit")]: _ctx.fit,
  179. [_ctx.ns.m("striped")]: _ctx.stripe,
  180. [_ctx.ns.m("border")]: _ctx.border || _ctx.isGroup,
  181. [_ctx.ns.m("hidden")]: _ctx.isHidden,
  182. [_ctx.ns.m("group")]: _ctx.isGroup,
  183. [_ctx.ns.m("fluid-height")]: _ctx.maxHeight,
  184. [_ctx.ns.m("scrollable-x")]: _ctx.layout.scrollX.value,
  185. [_ctx.ns.m("scrollable-y")]: _ctx.layout.scrollY.value,
  186. [_ctx.ns.m("enable-row-hover")]: !_ctx.store.states.isComplex.value,
  187. [_ctx.ns.m("enable-row-transition")]: (_ctx.store.states.data.value || []).length !== 0 && (_ctx.store.states.data.value || []).length < 100,
  188. "has-footer": _ctx.showSummary
  189. },
  190. _ctx.ns.m(_ctx.tableSize),
  191. _ctx.className,
  192. _ctx.ns.b(),
  193. _ctx.ns.m(`layout-${_ctx.tableLayout}`)
  194. ]),
  195. style: normalizeStyle(_ctx.style),
  196. "data-prefix": _ctx.ns.namespace.value,
  197. onMouseleave: _cache[0] || (_cache[0] = (...args) => _ctx.handleMouseLeave && _ctx.handleMouseLeave(...args))
  198. }, [
  199. createElementVNode("div", {
  200. class: normalizeClass(_ctx.ns.e("inner-wrapper")),
  201. style: normalizeStyle(_ctx.tableInnerStyle)
  202. }, [
  203. createElementVNode("div", _hoisted_2, [
  204. renderSlot(_ctx.$slots, "default")
  205. ], 512),
  206. _ctx.showHeader && _ctx.tableLayout === "fixed" ? withDirectives((openBlock(), createElementBlock("div", {
  207. key: 0,
  208. ref: "headerWrapper",
  209. class: normalizeClass(_ctx.ns.e("header-wrapper"))
  210. }, [
  211. createElementVNode("table", {
  212. ref: "tableHeader",
  213. class: normalizeClass(_ctx.ns.e("header")),
  214. style: normalizeStyle(_ctx.tableBodyStyles),
  215. border: "0",
  216. cellpadding: "0",
  217. cellspacing: "0"
  218. }, [
  219. createVNode(_component_hColgroup, {
  220. columns: _ctx.store.states.columns.value,
  221. "table-layout": _ctx.tableLayout
  222. }, null, 8, ["columns", "table-layout"]),
  223. createVNode(_component_table_header, {
  224. ref: "tableHeaderRef",
  225. border: _ctx.border,
  226. "default-sort": _ctx.defaultSort,
  227. store: _ctx.store,
  228. onSetDragVisible: _ctx.setDragVisible
  229. }, null, 8, ["border", "default-sort", "store", "onSetDragVisible"])
  230. ], 6)
  231. ], 2)), [
  232. [_directive_mousewheel, _ctx.handleHeaderFooterMousewheel]
  233. ]) : createCommentVNode("v-if", true),
  234. createElementVNode("div", {
  235. ref: "bodyWrapper",
  236. class: normalizeClass(_ctx.ns.e("body-wrapper"))
  237. }, [
  238. createVNode(_component_el_scrollbar, {
  239. ref: "scrollBarRef",
  240. "view-style": _ctx.scrollbarViewStyle,
  241. "wrap-style": _ctx.scrollbarStyle,
  242. always: _ctx.scrollbarAlwaysOn
  243. }, {
  244. default: withCtx(() => [
  245. createElementVNode("table", {
  246. ref: "tableBody",
  247. class: normalizeClass(_ctx.ns.e("body")),
  248. cellspacing: "0",
  249. cellpadding: "0",
  250. border: "0",
  251. style: normalizeStyle({
  252. width: _ctx.bodyWidth,
  253. tableLayout: _ctx.tableLayout
  254. })
  255. }, [
  256. createVNode(_component_hColgroup, {
  257. columns: _ctx.store.states.columns.value,
  258. "table-layout": _ctx.tableLayout
  259. }, null, 8, ["columns", "table-layout"]),
  260. _ctx.showHeader && _ctx.tableLayout === "auto" ? (openBlock(), createBlock(_component_table_header, {
  261. key: 0,
  262. ref: "tableHeaderRef",
  263. class: normalizeClass(_ctx.ns.e("body-header")),
  264. border: _ctx.border,
  265. "default-sort": _ctx.defaultSort,
  266. store: _ctx.store,
  267. onSetDragVisible: _ctx.setDragVisible
  268. }, null, 8, ["class", "border", "default-sort", "store", "onSetDragVisible"])) : createCommentVNode("v-if", true),
  269. createVNode(_component_table_body, {
  270. context: _ctx.context,
  271. highlight: _ctx.highlightCurrentRow,
  272. "row-class-name": _ctx.rowClassName,
  273. "tooltip-effect": _ctx.tooltipEffect,
  274. "tooltip-options": _ctx.tooltipOptions,
  275. "row-style": _ctx.rowStyle,
  276. store: _ctx.store,
  277. stripe: _ctx.stripe
  278. }, null, 8, ["context", "highlight", "row-class-name", "tooltip-effect", "tooltip-options", "row-style", "store", "stripe"]),
  279. _ctx.showSummary && _ctx.tableLayout === "auto" ? (openBlock(), createBlock(_component_table_footer, {
  280. key: 1,
  281. class: normalizeClass(_ctx.ns.e("body-footer")),
  282. border: _ctx.border,
  283. "default-sort": _ctx.defaultSort,
  284. store: _ctx.store,
  285. "sum-text": _ctx.computedSumText,
  286. "summary-method": _ctx.summaryMethod
  287. }, null, 8, ["class", "border", "default-sort", "store", "sum-text", "summary-method"])) : createCommentVNode("v-if", true)
  288. ], 6),
  289. _ctx.isEmpty ? (openBlock(), createElementBlock("div", {
  290. key: 0,
  291. ref: "emptyBlock",
  292. style: normalizeStyle(_ctx.emptyBlockStyle),
  293. class: normalizeClass(_ctx.ns.e("empty-block"))
  294. }, [
  295. createElementVNode("span", {
  296. class: normalizeClass(_ctx.ns.e("empty-text"))
  297. }, [
  298. renderSlot(_ctx.$slots, "empty", {}, () => [
  299. createTextVNode(toDisplayString(_ctx.computedEmptyText), 1)
  300. ])
  301. ], 2)
  302. ], 6)) : createCommentVNode("v-if", true),
  303. _ctx.$slots.append ? (openBlock(), createElementBlock("div", {
  304. key: 1,
  305. ref: "appendWrapper",
  306. class: normalizeClass(_ctx.ns.e("append-wrapper"))
  307. }, [
  308. renderSlot(_ctx.$slots, "append")
  309. ], 2)) : createCommentVNode("v-if", true)
  310. ]),
  311. _: 3
  312. }, 8, ["view-style", "wrap-style", "always"])
  313. ], 2),
  314. _ctx.showSummary && _ctx.tableLayout === "fixed" ? withDirectives((openBlock(), createElementBlock("div", {
  315. key: 1,
  316. ref: "footerWrapper",
  317. class: normalizeClass(_ctx.ns.e("footer-wrapper"))
  318. }, [
  319. createElementVNode("table", {
  320. class: normalizeClass(_ctx.ns.e("footer")),
  321. cellspacing: "0",
  322. cellpadding: "0",
  323. border: "0",
  324. style: normalizeStyle(_ctx.tableBodyStyles)
  325. }, [
  326. createVNode(_component_hColgroup, {
  327. columns: _ctx.store.states.columns.value,
  328. "table-layout": _ctx.tableLayout
  329. }, null, 8, ["columns", "table-layout"]),
  330. createVNode(_component_table_footer, {
  331. border: _ctx.border,
  332. "default-sort": _ctx.defaultSort,
  333. store: _ctx.store,
  334. "sum-text": _ctx.computedSumText,
  335. "summary-method": _ctx.summaryMethod
  336. }, null, 8, ["border", "default-sort", "store", "sum-text", "summary-method"])
  337. ], 6)
  338. ], 2)), [
  339. [vShow, !_ctx.isEmpty],
  340. [_directive_mousewheel, _ctx.handleHeaderFooterMousewheel]
  341. ]) : createCommentVNode("v-if", true),
  342. _ctx.border || _ctx.isGroup ? (openBlock(), createElementBlock("div", {
  343. key: 2,
  344. class: normalizeClass(_ctx.ns.e("border-left-patch"))
  345. }, null, 2)) : createCommentVNode("v-if", true)
  346. ], 6),
  347. withDirectives(createElementVNode("div", {
  348. ref: "resizeProxy",
  349. class: normalizeClass(_ctx.ns.e("column-resize-proxy"))
  350. }, null, 2), [
  351. [vShow, _ctx.resizeProxyVisible]
  352. ])
  353. ], 46, _hoisted_1);
  354. }
  355. var Table = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "table.vue"]]);
  356. export { Table as default };
  357. //# sourceMappingURL=table.mjs.map