f42e919e96cc3805e3452d1078447e30bd0ef2cb09fae571197e7fd4f4b18fe091cc9ad98b59203bcc53ce671b28e5ed97c372f616a7e905ead3fe42bd2c41 14 KB

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