stk-table-vue 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,25 @@
1
1
  import { onMounted, onBeforeUnmount, watch, ref, computed, defineComponent, shallowRef, toRaw, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, withDirectives, createElementVNode, vShow, Fragment, renderList, createCommentVNode, createBlock, resolveDynamicComponent, renderSlot, toDisplayString, createTextVNode } from "vue";
2
2
  import { interpolateRgb } from "d3-interpolate";
3
+ const Default_Col_Width = "100";
4
+ const Default_Table_Height = 100;
5
+ const Default_Table_Width = 200;
6
+ const Default_Row_Height = 28;
7
+ const Highlight_Color = {
8
+ light: { from: "#71a2fd", to: "#fff" },
9
+ dark: { from: "#1e4c99", to: "#181c21" }
10
+ };
11
+ const Highlight_Duration = 2e3;
12
+ const Highlight_Color_Change_Freq = 100;
13
+ let _chromeVersion = 0;
14
+ try {
15
+ const userAgent = navigator.userAgent.match(/chrome\/\d+/i);
16
+ if (userAgent) {
17
+ _chromeVersion = +userAgent[0].split("/")[1];
18
+ }
19
+ } catch (e) {
20
+ console.error("Cannot get Chrome version", e);
21
+ }
22
+ const Is_Legacy_Mode = _chromeVersion < 56;
3
23
  function useAutoResize({ tableContainer, initVirtualScroll, scrollTo, props, debounceMs }) {
4
24
  let resizeObserver = null;
5
25
  onMounted(() => {
@@ -50,25 +70,6 @@ function useAutoResize({ tableContainer, initVirtualScroll, scrollTo, props, deb
50
70
  }, debounceMs);
51
71
  }
52
72
  }
53
- const Default_Col_Width = "100";
54
- const Default_Table_Height = 100;
55
- const Default_Table_Width = 200;
56
- const Highlight_Color = {
57
- light: { from: "#71a2fd", to: "#fff" },
58
- dark: { from: "#1e4c99", to: "#181c21" }
59
- };
60
- const Highlight_Duration = 2e3;
61
- const Highlight_Color_Change_Freq = 100;
62
- let _chromeVersion = 0;
63
- try {
64
- const userAgent = navigator.userAgent.match(/chrome\/\d+/i);
65
- if (userAgent) {
66
- _chromeVersion = +userAgent[0].split("/")[1];
67
- }
68
- } catch (e) {
69
- console.error("Cannot get Chrome version", e);
70
- }
71
- const Is_Legacy_Mode = _chromeVersion < 56;
72
73
  function useColResize({
73
74
  tableContainer,
74
75
  tableHeaderLast,
@@ -360,8 +361,8 @@ function useHighlight({ props, tableContainer, rowKeyGen }) {
360
361
  setHighlightDimCell
361
362
  };
362
363
  }
363
- const ARROW_CODES = ["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft"];
364
- function useKeyboardArrowScroll(targetElement, { scrollTo, virtualScroll, virtualScrollX }) {
364
+ const SCROLL_CODES = ["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft", "PageUp", "PageDown"];
365
+ function useKeyboardArrowScroll(targetElement, { props, scrollTo, virtualScroll, virtualScrollX, tableHeaders }) {
365
366
  let isMouseOver = false;
366
367
  onMounted(() => {
367
368
  var _a, _b, _c;
@@ -378,21 +379,27 @@ function useKeyboardArrowScroll(targetElement, { scrollTo, virtualScroll, virtua
378
379
  (_c = targetElement.value) == null ? void 0 : _c.removeEventListener("mousedown", handleMouseDown);
379
380
  });
380
381
  function handleKeydown(e) {
381
- if (!ARROW_CODES.includes(e.code))
382
+ if (!SCROLL_CODES.includes(e.code))
382
383
  return;
383
384
  if (!isMouseOver)
384
385
  return;
385
386
  e.preventDefault();
386
- const { scrollTop, rowHeight } = virtualScroll.value;
387
+ const { scrollTop, rowHeight, pageSize } = virtualScroll.value;
387
388
  const { scrollLeft } = virtualScrollX.value;
388
- if (e.code === ARROW_CODES[0]) {
389
+ const { headless, headerRowHeight } = props;
390
+ const headerHeight = headless ? 0 : tableHeaders.value.length * (headerRowHeight || rowHeight);
391
+ if (e.code === SCROLL_CODES[0]) {
389
392
  scrollTo(scrollTop - rowHeight, null);
390
- } else if (e.code === ARROW_CODES[1]) {
393
+ } else if (e.code === SCROLL_CODES[1]) {
391
394
  scrollTo(null, scrollLeft + rowHeight);
392
- } else if (e.code === ARROW_CODES[2]) {
395
+ } else if (e.code === SCROLL_CODES[2]) {
393
396
  scrollTo(scrollTop + rowHeight, null);
394
- } else if (e.code === ARROW_CODES[3]) {
397
+ } else if (e.code === SCROLL_CODES[3]) {
395
398
  scrollTo(null, scrollLeft - rowHeight);
399
+ } else if (e.code === SCROLL_CODES[4]) {
400
+ scrollTo(scrollTop - rowHeight * pageSize - headerHeight, null);
401
+ } else if (e.code === SCROLL_CODES[5]) {
402
+ scrollTo(scrollTop + rowHeight * pageSize - headerHeight, null);
396
403
  }
397
404
  }
398
405
  function handleMouseEnter() {
@@ -469,7 +476,7 @@ function useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLa
469
476
  return (dataSourceCopy.value.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
470
477
  });
471
478
  const virtualX_on = computed(() => {
472
- return props.virtualX && tableHeaderLast.value.reduce((sum, col) => sum += getCalcWidth(col), 0) > virtualScrollX.value.containerWidth * 1.5;
479
+ return props.virtualX && tableHeaderLast.value.reduce((sum, col) => sum += getCalcWidth(col), 0) > virtualScrollX.value.containerWidth + 100;
473
480
  });
474
481
  const virtualX_columnPart = computed(() => {
475
482
  if (virtualX_on.value) {
@@ -696,10 +703,16 @@ function howDeepTheHeader(arr, level = 1) {
696
703
  });
697
704
  return Math.max(...levels);
698
705
  }
699
- const _hoisted_1 = { key: 0 };
706
+ const _hoisted_1 = {
707
+ key: 0
708
+ };
700
709
  const _hoisted_2 = ["data-col-key", "draggable", "rowspan", "colspan", "title", "onClick"];
701
- const _hoisted_3 = { class: "table-header-cell-wrapper" };
702
- const _hoisted_4 = { class: "table-header-title" };
710
+ const _hoisted_3 = {
711
+ class: "table-header-cell-wrapper"
712
+ };
713
+ const _hoisted_4 = {
714
+ class: "table-header-title"
715
+ };
703
716
  const _hoisted_5 = {
704
717
  key: 2,
705
718
  class: "table-header-sorter"
@@ -709,71 +722,150 @@ const _hoisted_6 = /* @__PURE__ */ createElementVNode("svg", {
709
722
  width: "16px",
710
723
  height: "16px",
711
724
  viewBox: "0 0 16 16"
712
- }, [
713
- /* @__PURE__ */ createElementVNode("g", { id: "sort-btn" }, [
714
- /* @__PURE__ */ createElementVNode("polygon", {
715
- id: "arrow-up",
716
- fill: "#757699",
717
- points: "8 2 4.8 6 11.2 6"
718
- }),
719
- /* @__PURE__ */ createElementVNode("polygon", {
720
- id: "arrow-down",
721
- transform: "translate(8, 12) rotate(-180) translate(-8, -12) ",
722
- points: "8 10 4.8 14 11.2 14"
723
- })
724
- ])
725
- ], -1);
726
- const _hoisted_7 = [
727
- _hoisted_6
728
- ];
725
+ }, [/* @__PURE__ */ createElementVNode("polygon", {
726
+ class: "arrow-up",
727
+ fill: "#757699",
728
+ points: "8 2 4.8 6 11.2 6"
729
+ }), /* @__PURE__ */ createElementVNode("polygon", {
730
+ class: "arrow-down",
731
+ transform: "translate(8, 12) rotate(-180) translate(-8, -12) ",
732
+ points: "8 10 4.8 14 11.2 14"
733
+ })], -1);
734
+ const _hoisted_7 = [_hoisted_6];
729
735
  const _hoisted_8 = ["onMousedown"];
730
736
  const _hoisted_9 = ["onMousedown"];
731
737
  const _hoisted_10 = {
732
738
  key: 0,
733
739
  class: "virtual-x-left",
734
- style: { "padding": "0" }
740
+ style: {
741
+ "padding": "0"
742
+ }
735
743
  };
736
744
  const _hoisted_11 = ["data-row-key", "onClick", "onDblclick", "onContextmenu", "onMouseover"];
737
745
  const _hoisted_12 = {
738
746
  key: 0,
739
747
  class: "virtual-x-left",
740
- style: { "padding": "0" }
748
+ style: {
749
+ "padding": "0"
750
+ }
741
751
  };
742
752
  const _hoisted_13 = ["data-index", "onClick"];
743
753
  const _hoisted_14 = ["title"];
744
754
  const _sfc_main = /* @__PURE__ */ defineComponent({
745
755
  __name: "StkTable",
746
756
  props: {
747
- width: { default: "" },
748
- minWidth: { default: "" },
749
- maxWidth: { default: "" },
750
- stripe: { type: Boolean, default: false },
751
- fixedMode: { type: Boolean, default: false },
752
- headless: { type: Boolean, default: false },
753
- theme: { default: "light" },
754
- rowHeight: { default: 28 },
755
- virtual: { type: Boolean, default: false },
756
- virtualX: { type: Boolean, default: false },
757
- columns: { default: () => [] },
758
- dataSource: { default: () => [] },
759
- rowKey: { type: [String, Function], default: "" },
760
- colKey: { type: [String, Function], default: "dataIndex" },
761
- emptyCellText: { default: "--" },
762
- noDataFull: { type: Boolean, default: false },
763
- showNoData: { type: Boolean, default: true },
764
- sortRemote: { type: Boolean, default: false },
765
- showHeaderOverflow: { type: Boolean, default: false },
766
- showOverflow: { type: Boolean, default: false },
767
- showTrHoverClass: { type: Boolean, default: false },
768
- headerDrag: { type: Boolean, default: false },
769
- rowClassName: { type: Function, default: () => "" },
770
- colResizable: { type: Boolean, default: false },
771
- colMinWidth: { default: 10 },
772
- bordered: { type: [Boolean, String], default: true },
773
- autoResize: { type: [Boolean, Function], default: true }
757
+ width: {
758
+ default: ""
759
+ },
760
+ minWidth: {
761
+ default: ""
762
+ },
763
+ maxWidth: {
764
+ default: ""
765
+ },
766
+ stripe: {
767
+ type: Boolean,
768
+ default: false
769
+ },
770
+ fixedMode: {
771
+ type: Boolean,
772
+ default: false
773
+ },
774
+ headless: {
775
+ type: Boolean,
776
+ default: false
777
+ },
778
+ theme: {
779
+ default: "light"
780
+ },
781
+ rowHeight: {
782
+ default: Default_Row_Height
783
+ },
784
+ headerRowHeight: {
785
+ default: null
786
+ },
787
+ virtual: {
788
+ type: Boolean,
789
+ default: false
790
+ },
791
+ virtualX: {
792
+ type: Boolean,
793
+ default: false
794
+ },
795
+ columns: {
796
+ default: () => []
797
+ },
798
+ dataSource: {
799
+ default: () => []
800
+ },
801
+ rowKey: {
802
+ type: [String, Function],
803
+ default: ""
804
+ },
805
+ colKey: {
806
+ type: [String, Function],
807
+ default: "dataIndex"
808
+ },
809
+ emptyCellText: {
810
+ default: "--"
811
+ },
812
+ noDataFull: {
813
+ type: Boolean,
814
+ default: false
815
+ },
816
+ showNoData: {
817
+ type: Boolean,
818
+ default: true
819
+ },
820
+ sortRemote: {
821
+ type: Boolean,
822
+ default: false
823
+ },
824
+ showHeaderOverflow: {
825
+ type: Boolean,
826
+ default: false
827
+ },
828
+ showOverflow: {
829
+ type: Boolean,
830
+ default: false
831
+ },
832
+ showTrHoverClass: {
833
+ type: Boolean,
834
+ default: false
835
+ },
836
+ headerDrag: {
837
+ type: Boolean,
838
+ default: false
839
+ },
840
+ rowClassName: {
841
+ type: Function,
842
+ default: () => ""
843
+ },
844
+ colResizable: {
845
+ type: Boolean,
846
+ default: false
847
+ },
848
+ colMinWidth: {
849
+ default: 10
850
+ },
851
+ bordered: {
852
+ type: [Boolean, String],
853
+ default: true
854
+ },
855
+ autoResize: {
856
+ type: [Boolean, Function],
857
+ default: true
858
+ },
859
+ fixedColShadow: {
860
+ type: Boolean,
861
+ default: false
862
+ }
774
863
  },
775
864
  emits: ["sort-change", "row-click", "current-change", "row-dblclick", "header-row-menu", "row-menu", "cell-click", "header-cell-click", "scroll", "scroll-x", "col-order-change", "th-drag-start", "th-drop", "update:columns"],
776
- setup(__props, { expose: __expose, emit: __emit }) {
865
+ setup(__props, {
866
+ expose: __expose,
867
+ emit: __emit
868
+ }) {
777
869
  const props = __props;
778
870
  const emits = __emit;
779
871
  const tableContainer = ref();
@@ -786,8 +878,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
786
878
  const tableHeaders = ref([]);
787
879
  const tableHeaderLast = ref([]);
788
880
  const dataSourceCopy = shallowRef([...props.dataSource]);
881
+ const fixedShadow = ref({
882
+ /** 是否展示左侧固定列阴影 */
883
+ showL: false,
884
+ /** 是否展示右侧固定列阴影 */
885
+ showR: false,
886
+ /** 保存需要出现阴影的列 */
887
+ cols: []
888
+ });
789
889
  const rowKeyGenStore = /* @__PURE__ */ new WeakMap();
790
- const { isColResizing, onThResizeMouseDown } = useColResize({
890
+ const {
891
+ isColResizing,
892
+ onThResizeMouseDown
893
+ } = useColResize({
791
894
  props,
792
895
  emits,
793
896
  colKeyGen,
@@ -795,7 +898,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
795
898
  tableContainer,
796
899
  tableHeaderLast
797
900
  });
798
- const { onThDragStart, onThDragOver, onThDrop } = useThDrag({ emits });
901
+ const {
902
+ onThDragStart,
903
+ onThDragOver,
904
+ onThDrop
905
+ } = useThDrag({
906
+ emits
907
+ });
799
908
  const {
800
909
  virtualScroll,
801
910
  virtualScrollX,
@@ -810,8 +919,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
810
919
  initVirtualScrollX,
811
920
  updateVirtualScrollY,
812
921
  updateVirtualScrollX
813
- } = useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLast });
814
- const { getFixedStyle } = useFixedStyle({
922
+ } = useVirtualScroll({
923
+ tableContainer,
924
+ props,
925
+ dataSourceCopy,
926
+ tableHeaderLast
927
+ });
928
+ const {
929
+ getFixedStyle
930
+ } = useFixedStyle({
815
931
  props,
816
932
  tableHeaderLast,
817
933
  virtualScroll,
@@ -819,48 +935,58 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
819
935
  virtualX_on,
820
936
  virtualX_offsetRight
821
937
  });
822
- const { setHighlightDimCell, setHighlightDimRow } = useHighlight({ props, tableContainer, rowKeyGen });
938
+ const {
939
+ setHighlightDimCell,
940
+ setHighlightDimRow
941
+ } = useHighlight({
942
+ props,
943
+ tableContainer,
944
+ rowKeyGen
945
+ });
823
946
  if (props.autoResize) {
824
- useAutoResize({ tableContainer, initVirtualScroll, scrollTo, props, debounceMs: 500 });
947
+ useAutoResize({
948
+ tableContainer,
949
+ initVirtualScroll,
950
+ scrollTo,
951
+ props,
952
+ debounceMs: 500
953
+ });
825
954
  }
826
955
  useKeyboardArrowScroll(tableContainer, {
956
+ props,
827
957
  scrollTo,
828
958
  virtualScroll,
829
- virtualScrollX
959
+ virtualScrollX,
960
+ tableHeaders
961
+ });
962
+ watch(() => props.columns, () => {
963
+ dealColumns();
964
+ initVirtualScrollX();
830
965
  });
831
- watch(
832
- () => props.columns,
833
- () => {
834
- dealColumns();
835
- initVirtualScrollX();
836
- }
837
- );
838
966
  dealColumns();
839
- watch(
840
- () => props.dataSource,
841
- (val) => {
842
- if (!val) {
843
- console.warn("invalid dataSource");
844
- return;
845
- }
846
- let needInitVirtualScrollY = false;
847
- if (dataSourceCopy.value.length !== val.length) {
848
- needInitVirtualScrollY = true;
849
- }
850
- dataSourceCopy.value = [...val];
851
- if (needInitVirtualScrollY)
852
- initVirtualScrollY();
853
- if (sortCol.value) {
854
- const column = tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
855
- onColumnSort(column, false);
856
- }
857
- },
858
- {
859
- deep: false
967
+ watch(() => props.dataSource, (val) => {
968
+ if (!val) {
969
+ console.warn("invalid dataSource");
970
+ return;
860
971
  }
861
- );
972
+ let needInitVirtualScrollY = false;
973
+ if (dataSourceCopy.value.length !== val.length) {
974
+ needInitVirtualScrollY = true;
975
+ }
976
+ dataSourceCopy.value = [...val];
977
+ if (needInitVirtualScrollY)
978
+ initVirtualScrollY();
979
+ if (sortCol.value) {
980
+ const column = tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
981
+ onColumnSort(column, false);
982
+ }
983
+ updateFixedShadow();
984
+ }, {
985
+ deep: false
986
+ });
862
987
  onMounted(() => {
863
988
  initVirtualScroll();
989
+ updateFixedShadow();
864
990
  });
865
991
  function dealColumns() {
866
992
  tableHeaders.value = [];
@@ -871,16 +997,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
871
997
  if (deep > 1 && props.virtualX) {
872
998
  console.error("多级表头不支持横向虚拟滚动");
873
999
  }
874
- function flat(arr, depth = 0) {
1000
+ function flat(arr, parent, depth = 0) {
875
1001
  if (!tableHeaders.value[depth]) {
876
1002
  tableHeaders.value[depth] = [];
877
1003
  }
878
1004
  let allChildrenLen = 0;
879
1005
  arr.forEach((col) => {
1006
+ col.__PARENT__ = parent;
880
1007
  let colChildrenLen = 1;
881
1008
  if (col.children) {
882
1009
  colChildrenLen = flat(
883
1010
  col.children,
1011
+ col,
884
1012
  depth + 1
885
1013
  /* , col.fixed */
886
1014
  );
@@ -900,8 +1028,52 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
900
1028
  });
901
1029
  return allChildrenLen;
902
1030
  }
903
- flat(copyColumn);
1031
+ flat(copyColumn, null);
904
1032
  tableHeaderLast.value = tempHeaderLast;
1033
+ dealFixedColShadow();
1034
+ }
1035
+ function dealFixedColShadow() {
1036
+ if (!props.fixedColShadow)
1037
+ return;
1038
+ fixedShadow.value.cols = [];
1039
+ const lastLeftCol = tableHeaderLast.value.findLast((it) => it.fixed === "left");
1040
+ const lastRightCol = tableHeaderLast.value.find((it) => it.fixed === "right");
1041
+ let node = {
1042
+ __PARENT__: lastLeftCol
1043
+ };
1044
+ while (node = node.__PARENT__) {
1045
+ if (node.fixed) {
1046
+ fixedShadow.value.cols.push(node);
1047
+ }
1048
+ }
1049
+ node = {
1050
+ __PARENT__: lastRightCol
1051
+ };
1052
+ while (node = node.__PARENT__) {
1053
+ if (node.fixed) {
1054
+ fixedShadow.value.cols.push(node);
1055
+ }
1056
+ }
1057
+ }
1058
+ function getFixedColClass(col) {
1059
+ const {
1060
+ showR,
1061
+ showL,
1062
+ cols
1063
+ } = fixedShadow.value;
1064
+ const classArr = [col.fixed ? "fixed-cell" : "", col.fixed ? "fixed-cell--" + col.fixed : "", props.fixedColShadow && col.fixed && (showL && col.fixed === "left" || showR && col.fixed === "right") && cols.includes(col) ? "fixed-cell--shadow" : ""];
1065
+ return classArr;
1066
+ }
1067
+ function updateFixedShadow() {
1068
+ if (!props.fixedColShadow)
1069
+ return;
1070
+ const {
1071
+ clientWidth,
1072
+ scrollWidth,
1073
+ scrollLeft
1074
+ } = tableContainer.value;
1075
+ fixedShadow.value.showL = Boolean(scrollLeft);
1076
+ fixedShadow.value.showR = Math.abs(scrollWidth - scrollLeft - clientWidth) > 0.5;
905
1077
  }
906
1078
  function rowKeyGen(row) {
907
1079
  let key = rowKeyGenStore.get(row);
@@ -944,7 +1116,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
944
1116
  function onColumnSort(col, click = true, options = {}) {
945
1117
  if (!(col == null ? void 0 : col.sorter))
946
1118
  return;
947
- options = { force: false, emit: false, ...options };
1119
+ options = {
1120
+ force: false,
1121
+ emit: false,
1122
+ ...options
1123
+ };
948
1124
  if (sortCol.value !== col.dataIndex) {
949
1125
  sortCol.value = col.dataIndex;
950
1126
  sortOrderIndex.value = 0;
@@ -992,9 +1168,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
992
1168
  function onTableScroll(e) {
993
1169
  if (!(e == null ? void 0 : e.target))
994
1170
  return;
995
- const { scrollTop, scrollLeft } = e.target;
996
- const isYScroll = scrollTop !== virtualScroll.value.scrollTop;
997
- const isXScroll = scrollLeft !== virtualScrollX.value.scrollLeft;
1171
+ const {
1172
+ scrollTop,
1173
+ scrollLeft
1174
+ } = e.target;
1175
+ const {
1176
+ scrollTop: vScrollTop,
1177
+ startIndex,
1178
+ endIndex
1179
+ } = virtualScroll.value;
1180
+ const {
1181
+ scrollLeft: vScrollLeft
1182
+ } = virtualScrollX.value;
1183
+ const isYScroll = scrollTop !== vScrollTop;
1184
+ const isXScroll = scrollLeft !== vScrollLeft;
998
1185
  if (isYScroll) {
999
1186
  virtualScroll.value.scrollTop = scrollTop;
1000
1187
  }
@@ -1003,13 +1190,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1003
1190
  }
1004
1191
  if (isXScroll) {
1005
1192
  virtualScrollX.value.scrollLeft = scrollLeft;
1193
+ updateFixedShadow();
1006
1194
  }
1007
1195
  if (virtualX_on.value) {
1008
1196
  updateVirtualScrollX(scrollLeft);
1009
1197
  }
1010
1198
  const data = {
1011
- startIndex: virtualScroll.value.startIndex,
1012
- endIndex: virtualScroll.value.endIndex
1199
+ startIndex,
1200
+ endIndex
1013
1201
  };
1014
1202
  if (isYScroll) {
1015
1203
  emits("scroll", e, data);
@@ -1023,7 +1211,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1023
1211
  currentHover.value = rowKeyGen(row);
1024
1212
  }
1025
1213
  }
1026
- function setCurrentRow(rowKey, option = { silent: false }) {
1214
+ function setCurrentRow(rowKey, option = {
1215
+ silent: false
1216
+ }) {
1027
1217
  if (!dataSourceCopy.value.length)
1028
1218
  return;
1029
1219
  currentItem.value = dataSourceCopy.value.find((it) => rowKeyGen(it) === rowKey);
@@ -1033,13 +1223,21 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1033
1223
  }
1034
1224
  function setSorter(dataIndex, order, option = {}) {
1035
1225
  var _a;
1036
- const newOption = { silent: true, sortOption: null, sort: true, ...option };
1226
+ const newOption = {
1227
+ silent: true,
1228
+ sortOption: null,
1229
+ sort: true,
1230
+ ...option
1231
+ };
1037
1232
  sortCol.value = dataIndex;
1038
1233
  sortOrderIndex.value = sortSwitchOrder.findIndex((it) => it === order);
1039
1234
  if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
1040
1235
  const column = newOption.sortOption || tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
1041
1236
  if (column)
1042
- onColumnSort(column, false, { force: true, emit: !newOption.silent });
1237
+ onColumnSort(column, false, {
1238
+ force: true,
1239
+ emit: !newOption.silent
1240
+ });
1043
1241
  else
1044
1242
  console.warn("Can not find column by dataIndex:", sortCol.value);
1045
1243
  }
@@ -1062,16 +1260,27 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1062
1260
  return toRaw(dataSourceCopy.value);
1063
1261
  }
1064
1262
  __expose({
1263
+ /** 初始化横向纵向虚拟滚动 */
1065
1264
  initVirtualScroll,
1265
+ /** 初始化横向虚拟滚动 */
1066
1266
  initVirtualScrollX,
1267
+ /** 初始化纵向虚拟滚动 */
1067
1268
  initVirtualScrollY,
1269
+ /** 设置当前选中行 */
1068
1270
  setCurrentRow,
1271
+ /** 设置高亮渐暗单元格 */
1069
1272
  setHighlightDimCell,
1273
+ /** 设置高亮渐暗行 */
1070
1274
  setHighlightDimRow,
1275
+ /** 表格排序列dataIndex */
1071
1276
  sortCol,
1277
+ /** 设置排序 */
1072
1278
  setSorter,
1279
+ /** 重置排序 */
1073
1280
  resetSorter,
1281
+ /** 滚动至 */
1074
1282
  scrollTo,
1283
+ /** 获取表格数据 */
1075
1284
  getTableData
1076
1285
  });
1077
1286
  return (_ctx, _cache) => {
@@ -1091,174 +1300,137 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1091
1300
  "border-body-v": props.bordered === "body-v",
1092
1301
  stripe: props.stripe
1093
1302
  }]),
1094
- style: normalizeStyle(_ctx.virtual && { "--row-height": unref(virtualScroll).rowHeight + "px" }),
1303
+ style: normalizeStyle(_ctx.virtual && {
1304
+ "--row-height": unref(virtualScroll).rowHeight + "px",
1305
+ "--header-row-height": (props.headerRowHeight || props.rowHeight) + "px"
1306
+ }),
1095
1307
  onScroll: onTableScroll,
1096
1308
  onWheel: onTableWheel
1097
- }, [
1098
- withDirectives(createElementVNode("div", {
1099
- ref_key: "colResizeIndicator",
1100
- ref: colResizeIndicator,
1101
- class: "column-resize-indicator"
1102
- }, null, 512), [
1103
- [vShow, _ctx.colResizable]
1104
- ]),
1105
- createElementVNode("table", {
1106
- class: normalizeClass(["stk-table-main", {
1107
- "fixed-mode": props.fixedMode
1108
- }]),
1109
- style: normalizeStyle({ width: _ctx.width, minWidth: _ctx.minWidth, maxWidth: _ctx.maxWidth })
1110
- }, [
1111
- !_ctx.headless ? (openBlock(), createElementBlock("thead", _hoisted_1, [
1112
- (openBlock(true), createElementBlock(Fragment, null, renderList(tableHeaders.value, (row, rowIndex) => {
1113
- return openBlock(), createElementBlock("tr", {
1114
- key: rowIndex,
1115
- onContextmenu: _cache[3] || (_cache[3] = (e) => onHeaderMenu(e))
1116
- }, [
1117
- unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
1118
- key: 0,
1119
- class: "virtual-x-left",
1120
- style: normalizeStyle({
1121
- minWidth: unref(virtualScrollX).offsetLeft + "px",
1122
- width: unref(virtualScrollX).offsetLeft + "px"
1123
- })
1124
- }, null, 4)) : createCommentVNode("", true),
1125
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_on) && rowIndex === tableHeaders.value.length - 1 ? unref(virtualX_columnPart) : row, (col, colIndex) => {
1126
- return openBlock(), createElementBlock("th", {
1127
- key: col.dataIndex,
1128
- "data-col-key": colKeyGen(col),
1129
- draggable: _ctx.headerDrag ? "true" : "false",
1130
- rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
1131
- colspan: col.colSpan,
1132
- style: normalizeStyle(getCellStyle(1, col, rowIndex)),
1133
- title: col.title,
1134
- class: normalizeClass([
1135
- col.sorter ? "sortable" : "",
1136
- col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
1137
- _ctx.showHeaderOverflow ? "text-overflow" : "",
1138
- col.headerClassName,
1139
- col.fixed ? "fixed-cell" : "",
1140
- col.fixed ? "fixed-cell--" + col.fixed : ""
1141
- ]),
1142
- onClick: (e) => {
1143
- onColumnSort(col);
1144
- onHeaderCellClick(e, col);
1145
- },
1146
- onDragstart: _cache[0] || (_cache[0] = //@ts-ignore
1147
- (...args) => unref(onThDragStart) && unref(onThDragStart)(...args)),
1148
- onDrop: _cache[1] || (_cache[1] = //@ts-ignore
1149
- (...args) => unref(onThDrop) && unref(onThDrop)(...args)),
1150
- onDragover: _cache[2] || (_cache[2] = //@ts-ignore
1151
- (...args) => unref(onThDragOver) && unref(onThDragOver)(...args))
1152
- }, [
1153
- createElementVNode("div", _hoisted_3, [
1154
- col.customHeaderCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customHeaderCell), {
1155
- key: 0,
1156
- col
1157
- }, null, 8, ["col"])) : renderSlot(_ctx.$slots, "tableHeader", {
1158
- key: 1,
1159
- column: col
1160
- }, () => [
1161
- createElementVNode("span", _hoisted_4, toDisplayString(col.title), 1)
1162
- ]),
1163
- col.sorter ? (openBlock(), createElementBlock("span", _hoisted_5, _hoisted_7)) : createCommentVNode("", true),
1164
- _ctx.colResizable && colIndex > 0 ? (openBlock(), createElementBlock("div", {
1165
- key: 3,
1166
- class: "table-header-resizer left",
1167
- onMousedown: (e) => unref(onThResizeMouseDown)(e, col, true)
1168
- }, null, 40, _hoisted_8)) : createCommentVNode("", true),
1169
- _ctx.colResizable ? (openBlock(), createElementBlock("div", {
1170
- key: 4,
1171
- class: "table-header-resizer right",
1172
- onMousedown: (e) => unref(onThResizeMouseDown)(e, col)
1173
- }, null, 40, _hoisted_9)) : createCommentVNode("", true)
1174
- ])
1175
- ], 46, _hoisted_2);
1176
- }), 128)),
1177
- unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
1178
- key: 1,
1179
- class: "virtual-x-right",
1180
- style: normalizeStyle({
1181
- minWidth: unref(virtualX_offsetRight) + "px",
1182
- width: unref(virtualX_offsetRight) + "px"
1183
- })
1184
- }, null, 4)) : createCommentVNode("", true)
1185
- ], 32);
1186
- }), 128))
1187
- ])) : createCommentVNode("", true),
1188
- createElementVNode("tbody", null, [
1189
- unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
1190
- key: 0,
1191
- style: normalizeStyle({ height: `${unref(virtualScroll).offsetTop}px` }),
1192
- class: "padding-top-tr"
1193
- }, [
1194
- unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_10)) : createCommentVNode("", true),
1195
- _ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
1196
- return openBlock(), createElementBlock("td", {
1197
- key: col.dataIndex,
1198
- style: normalizeStyle(getCellStyle(2, col))
1199
- }, null, 4);
1200
- }), 128)) : createCommentVNode("", true)
1201
- ], 4)) : createCommentVNode("", true),
1202
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, i) => {
1203
- return openBlock(), createElementBlock("tr", {
1204
- key: _ctx.rowKey ? rowKeyGen(row) : i,
1205
- "data-row-key": _ctx.rowKey ? rowKeyGen(row) : i,
1206
- class: normalizeClass({
1207
- active: _ctx.rowKey ? rowKeyGen(row) === (currentItem.value && rowKeyGen(currentItem.value)) : row === currentItem.value,
1208
- hover: _ctx.rowKey ? rowKeyGen(row) === currentHover.value : row === currentHover.value,
1209
- [_ctx.rowClassName(row, i)]: true
1210
- }),
1211
- style: normalizeStyle({
1212
- backgroundColor: row._bgc
1213
- }),
1214
- onClick: (e) => onRowClick(e, row),
1215
- onDblclick: (e) => onRowDblclick(e, row),
1216
- onContextmenu: (e) => onRowMenu(e, row),
1217
- onMouseover: (e) => onTrMouseOver(e, row)
1218
- }, [
1219
- unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_12)) : createCommentVNode("", true),
1220
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_columnPart), (col) => {
1221
- return openBlock(), createElementBlock("td", {
1222
- key: col.dataIndex,
1223
- "data-index": col.dataIndex,
1224
- class: normalizeClass([
1225
- col.className,
1226
- _ctx.showOverflow ? "text-overflow" : "",
1227
- col.fixed ? "fixed-cell" : "",
1228
- col.fixed ? "fixed-cell--" + col.fixed : ""
1229
- ]),
1230
- style: normalizeStyle(getCellStyle(2, col)),
1231
- onClick: (e) => onCellClick(e, row, col)
1232
- }, [
1233
- col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
1234
- key: 0,
1235
- col,
1236
- row,
1237
- "cell-value": row[col.dataIndex]
1238
- }, null, 8, ["col", "row", "cell-value"])) : (openBlock(), createElementBlock("div", {
1239
- key: 1,
1240
- class: "table-cell-wrapper",
1241
- title: row[col.dataIndex]
1242
- }, toDisplayString(row[col.dataIndex] ?? _ctx.emptyCellText), 9, _hoisted_14))
1243
- ], 14, _hoisted_13);
1244
- }), 128))
1245
- ], 46, _hoisted_11);
1246
- }), 128)),
1247
- unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
1248
- key: 1,
1249
- style: normalizeStyle({ height: `${unref(virtual_offsetBottom)}px` })
1250
- }, null, 4)) : createCommentVNode("", true)
1251
- ])
1252
- ], 6),
1253
- (!dataSourceCopy.value || !dataSourceCopy.value.length) && _ctx.showNoData ? (openBlock(), createElementBlock("div", {
1309
+ }, [withDirectives(createElementVNode("div", {
1310
+ ref_key: "colResizeIndicator",
1311
+ ref: colResizeIndicator,
1312
+ class: "column-resize-indicator"
1313
+ }, null, 512), [[vShow, _ctx.colResizable]]), createElementVNode("table", {
1314
+ class: normalizeClass(["stk-table-main", {
1315
+ "fixed-mode": props.fixedMode
1316
+ }]),
1317
+ style: normalizeStyle({
1318
+ width: _ctx.width,
1319
+ minWidth: _ctx.minWidth,
1320
+ maxWidth: _ctx.maxWidth
1321
+ })
1322
+ }, [!_ctx.headless ? (openBlock(), createElementBlock("thead", _hoisted_1, [(openBlock(true), createElementBlock(Fragment, null, renderList(tableHeaders.value, (row, rowIndex) => {
1323
+ return openBlock(), createElementBlock("tr", {
1324
+ key: rowIndex,
1325
+ onContextmenu: _cache[3] || (_cache[3] = (e) => onHeaderMenu(e))
1326
+ }, [unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
1254
1327
  key: 0,
1255
- class: normalizeClass(["stk-table-no-data", { "no-data-full": _ctx.noDataFull }])
1256
- }, [
1257
- renderSlot(_ctx.$slots, "empty", {}, () => [
1258
- createTextVNode("暂无数据")
1259
- ])
1260
- ], 2)) : createCommentVNode("", true)
1261
- ], 38);
1328
+ class: "virtual-x-left",
1329
+ style: normalizeStyle({
1330
+ minWidth: unref(virtualScrollX).offsetLeft + "px",
1331
+ width: unref(virtualScrollX).offsetLeft + "px"
1332
+ })
1333
+ }, null, 4)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_on) && rowIndex === tableHeaders.value.length - 1 ? unref(virtualX_columnPart) : row, (col, colIndex) => {
1334
+ return openBlock(), createElementBlock("th", {
1335
+ key: col.dataIndex,
1336
+ "data-col-key": colKeyGen(col),
1337
+ draggable: _ctx.headerDrag ? "true" : "false",
1338
+ rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
1339
+ colspan: col.colSpan,
1340
+ style: normalizeStyle(getCellStyle(1, col, rowIndex)),
1341
+ title: col.title,
1342
+ class: normalizeClass([col.sorter ? "sortable" : "", col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)], _ctx.showHeaderOverflow ? "text-overflow" : "", col.headerClassName, ...getFixedColClass(col)]),
1343
+ onClick: (e) => {
1344
+ onColumnSort(col);
1345
+ onHeaderCellClick(e, col);
1346
+ },
1347
+ onDragstart: _cache[0] || (_cache[0] = //@ts-ignore
1348
+ (...args) => unref(onThDragStart) && unref(onThDragStart)(...args)),
1349
+ onDrop: _cache[1] || (_cache[1] = //@ts-ignore
1350
+ (...args) => unref(onThDrop) && unref(onThDrop)(...args)),
1351
+ onDragover: _cache[2] || (_cache[2] = //@ts-ignore
1352
+ (...args) => unref(onThDragOver) && unref(onThDragOver)(...args))
1353
+ }, [createElementVNode("div", _hoisted_3, [col.customHeaderCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customHeaderCell), {
1354
+ key: 0,
1355
+ col
1356
+ }, null, 8, ["col"])) : renderSlot(_ctx.$slots, "tableHeader", {
1357
+ key: 1,
1358
+ col
1359
+ }, () => [createElementVNode("span", _hoisted_4, toDisplayString(col.title), 1)]), col.sorter ? (openBlock(), createElementBlock("span", _hoisted_5, _hoisted_7)) : createCommentVNode("", true), _ctx.colResizable && colIndex > 0 ? (openBlock(), createElementBlock("div", {
1360
+ key: 3,
1361
+ class: "table-header-resizer left",
1362
+ onMousedown: (e) => unref(onThResizeMouseDown)(e, col, true)
1363
+ }, null, 40, _hoisted_8)) : createCommentVNode("", true), _ctx.colResizable ? (openBlock(), createElementBlock("div", {
1364
+ key: 4,
1365
+ class: "table-header-resizer right",
1366
+ onMousedown: (e) => unref(onThResizeMouseDown)(e, col)
1367
+ }, null, 40, _hoisted_9)) : createCommentVNode("", true)])], 46, _hoisted_2);
1368
+ }), 128)), unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
1369
+ key: 1,
1370
+ class: "virtual-x-right",
1371
+ style: normalizeStyle({
1372
+ minWidth: unref(virtualX_offsetRight) + "px",
1373
+ width: unref(virtualX_offsetRight) + "px"
1374
+ })
1375
+ }, null, 4)) : createCommentVNode("", true)], 32);
1376
+ }), 128))])) : createCommentVNode("", true), createElementVNode("tbody", null, [unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
1377
+ key: 0,
1378
+ style: normalizeStyle({
1379
+ height: `${unref(virtualScroll).offsetTop}px`
1380
+ }),
1381
+ class: "padding-top-tr"
1382
+ }, [unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_10)) : createCommentVNode("", true), _ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, {
1383
+ key: 1
1384
+ }, renderList(unref(virtualX_columnPart), (col) => {
1385
+ return openBlock(), createElementBlock("td", {
1386
+ key: col.dataIndex,
1387
+ style: normalizeStyle(getCellStyle(2, col))
1388
+ }, null, 4);
1389
+ }), 128)) : createCommentVNode("", true)], 4)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, i) => {
1390
+ return openBlock(), createElementBlock("tr", {
1391
+ key: _ctx.rowKey ? rowKeyGen(row) : i,
1392
+ "data-row-key": _ctx.rowKey ? rowKeyGen(row) : i,
1393
+ class: normalizeClass({
1394
+ active: _ctx.rowKey ? rowKeyGen(row) === (currentItem.value && rowKeyGen(currentItem.value)) : row === currentItem.value,
1395
+ hover: _ctx.rowKey ? rowKeyGen(row) === currentHover.value : row === currentHover.value,
1396
+ [_ctx.rowClassName(row, i)]: true
1397
+ }),
1398
+ style: normalizeStyle({
1399
+ backgroundColor: row._bgc
1400
+ }),
1401
+ onClick: (e) => onRowClick(e, row),
1402
+ onDblclick: (e) => onRowDblclick(e, row),
1403
+ onContextmenu: (e) => onRowMenu(e, row),
1404
+ onMouseover: (e) => onTrMouseOver(e, row)
1405
+ }, [unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_12)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_columnPart), (col) => {
1406
+ return openBlock(), createElementBlock("td", {
1407
+ key: col.dataIndex,
1408
+ "data-index": col.dataIndex,
1409
+ class: normalizeClass([col.className, _ctx.showOverflow ? "text-overflow" : "", ...getFixedColClass(col)]),
1410
+ style: normalizeStyle(getCellStyle(2, col)),
1411
+ onClick: (e) => onCellClick(e, row, col)
1412
+ }, [col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
1413
+ key: 0,
1414
+ col,
1415
+ row,
1416
+ "cell-value": row[col.dataIndex]
1417
+ }, null, 8, ["col", "row", "cell-value"])) : (openBlock(), createElementBlock("div", {
1418
+ key: 1,
1419
+ class: "table-cell-wrapper",
1420
+ title: row[col.dataIndex]
1421
+ }, toDisplayString(row[col.dataIndex] ?? _ctx.emptyCellText), 9, _hoisted_14))], 14, _hoisted_13);
1422
+ }), 128))], 46, _hoisted_11);
1423
+ }), 128)), unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
1424
+ key: 1,
1425
+ style: normalizeStyle({
1426
+ height: `${unref(virtual_offsetBottom)}px`
1427
+ })
1428
+ }, null, 4)) : createCommentVNode("", true)])], 6), (!dataSourceCopy.value || !dataSourceCopy.value.length) && _ctx.showNoData ? (openBlock(), createElementBlock("div", {
1429
+ key: 0,
1430
+ class: normalizeClass(["stk-table-no-data", {
1431
+ "no-data-full": _ctx.noDataFull
1432
+ }])
1433
+ }, [renderSlot(_ctx.$slots, "empty", {}, () => [createTextVNode("暂无数据")])], 2)) : createCommentVNode("", true)], 38);
1262
1434
  };
1263
1435
  }
1264
1436
  });