stk-table-vue 0.2.6 → 0.2.8

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.
@@ -168,7 +168,9 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
168
168
  /** 设置高亮渐暗单元格 */
169
169
  setHighlightDimCell: (rowKeyValue: string, dataIndex: string) => void;
170
170
  /** 设置高亮渐暗行 */
171
- setHighlightDimRow: (rowKeyValues: import("./types/index").UniqKey[]) => void;
171
+ setHighlightDimRow: (rowKeyValues: import("./types/index").UniqKey[], option?: {
172
+ useCss?: boolean | undefined;
173
+ }) => void;
172
174
  /** 表格排序列dataIndex */
173
175
  sortCol: import("vue").Ref<string | null | undefined>;
174
176
  /** 获取当前排序状态 */
@@ -94,4 +94,9 @@ export type SortConfig<T extends Record<string, any>> = {
94
94
  */
95
95
  stringLocaleCompare?: boolean;
96
96
  };
97
+ /** th td类型 */
98
+ export declare const enum TagType {
99
+ TH = 0,
100
+ TD = 1
101
+ }
97
102
  export {};
@@ -2,6 +2,8 @@ import { Ref } from 'vue';
2
2
  import { StkTableColumn } from './types';
3
3
  type Params<T extends Record<string, any>> = {
4
4
  props: any;
5
+ colKeyGen: (col: StkTableColumn<T>) => string;
6
+ tableHeaders: Ref<StkTableColumn<T>[][]>;
5
7
  tableHeaderLast: Ref<StkTableColumn<T>[]>;
6
8
  tableContainer: Ref<HTMLDivElement | undefined>;
7
9
  };
@@ -9,9 +11,9 @@ type Params<T extends Record<string, any>> = {
9
11
  * 固定列处理
10
12
  * @returns
11
13
  */
12
- export declare function useFixedCol<DT extends Record<string, any>>({ props, tableHeaderLast, tableContainer }: Params<DT>): {
14
+ export declare function useFixedCol<DT extends Record<string, any>>({ props, colKeyGen, tableHeaders, tableHeaderLast, tableContainer }: Params<DT>): {
13
15
  /** 固定列class */
14
- getFixedColClass: (col: StkTableColumn<DT>) => Record<string, boolean>;
16
+ fixedColClassMap: import("vue").ComputedRef<Map<any, any>>;
15
17
  /** 处理固定列阴影 */
16
18
  dealFixedColShadow: () => void;
17
19
  /** 滚动条变化时,更新需要展示阴影的列 */
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, Ref } from 'vue';
2
- import { StkTableColumn } from './types';
2
+ import { StkTableColumn, TagType } from './types';
3
3
  import { VirtualScrollStore, VirtualScrollXStore } from './useVirtualScroll';
4
4
  type Options<T extends Record<string, any>> = {
5
5
  props: any;
@@ -15,6 +15,6 @@ type Options<T extends Record<string, any>> = {
15
15
  * @returns
16
16
  */
17
17
  export declare function useFixedStyle<DT extends Record<string, any>>({ props, tableHeaders, virtualScroll, virtualScrollX, virtualX_on, virtualX_offsetRight, }: Options<DT>): {
18
- getFixedStyle: (tagType: 1 | 2, col: StkTableColumn<any>, depth?: number) => CSSProperties;
18
+ getFixedStyle: (tagType: TagType, col: StkTableColumn<DT>, depth?: number) => CSSProperties;
19
19
  };
20
20
  export {};
@@ -20,7 +20,9 @@ type HighlightRowStore = {
20
20
  */
21
21
  export declare function useHighlight({ props, tableContainer }: Params): {
22
22
  highlightRowStore: Ref<Record<UniqKey, HighlightRowStore>>;
23
- setHighlightDimRow: (rowKeyValues: UniqKey[]) => void;
23
+ setHighlightDimRow: (rowKeyValues: UniqKey[], option?: {
24
+ useCss?: boolean;
25
+ }) => void;
24
26
  setHighlightDimCell: (rowKeyValue: string, dataIndex: string) => void;
25
27
  };
26
28
  export {};
@@ -1,4 +1,4 @@
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";
1
+ import { onMounted, onBeforeUnmount, watch, ref, shallowRef, computed, defineComponent, 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
3
  const Default_Col_Width = "100";
4
4
  const Default_Table_Height = 100;
@@ -20,6 +20,11 @@ try {
20
20
  console.error("Cannot get Chrome version", e);
21
21
  }
22
22
  const Is_Legacy_Mode = _chromeVersion < 56;
23
+ var TagType = /* @__PURE__ */ ((TagType2) => {
24
+ TagType2[TagType2["TH"] = 0] = "TH";
25
+ TagType2[TagType2["TD"] = 1] = "TD";
26
+ return TagType2;
27
+ })(TagType || {});
23
28
  function useAutoResize({ tableContainer, initVirtualScroll, props, debounceMs }) {
24
29
  let resizeObserver = null;
25
30
  onMounted(() => {
@@ -325,16 +330,32 @@ function useColResize({
325
330
  onThResizeMouseUp
326
331
  };
327
332
  }
328
- function useFixedCol({ props, tableHeaderLast, tableContainer }) {
333
+ function useFixedCol({ props, colKeyGen, tableHeaders, tableHeaderLast, tableContainer }) {
329
334
  const fixedShadow = ref({
330
335
  showL: false,
331
336
  showR: false
332
337
  });
333
- let fixedShadowCols = [];
338
+ const fixedShadowCols = shallowRef([]);
339
+ const fixedColClassMap = computed(() => {
340
+ const colMap = /* @__PURE__ */ new Map();
341
+ tableHeaders.value.forEach((cols) => {
342
+ cols.forEach((col) => {
343
+ const { showR, showL } = fixedShadow.value;
344
+ const showShadow = props.fixedColShadow && col.fixed && (showL && col.fixed === "left" || showR && col.fixed === "right") && fixedShadowCols.value.includes(col);
345
+ const classObj = {
346
+ "fixed-cell": col.fixed,
347
+ ["fixed-cell--" + col.fixed]: col.fixed,
348
+ "fixed-cell--shadow": showShadow
349
+ };
350
+ colMap.set(colKeyGen(col), classObj);
351
+ });
352
+ });
353
+ return colMap;
354
+ });
334
355
  function dealFixedColShadow() {
335
356
  if (!props.fixedColShadow)
336
357
  return;
337
- fixedShadowCols = [];
358
+ fixedShadowCols.value = [];
338
359
  let lastLeftCol = null;
339
360
  for (let i = tableHeaderLast.value.length - 1; i >= 0; i--) {
340
361
  const col = tableHeaderLast.value[i];
@@ -346,27 +367,17 @@ function useFixedCol({ props, tableHeaderLast, tableContainer }) {
346
367
  let node = { __PARENT__: lastLeftCol };
347
368
  while (node = node.__PARENT__) {
348
369
  if (node.fixed) {
349
- fixedShadowCols.push(node);
370
+ fixedShadowCols.value.push(node);
350
371
  }
351
372
  }
352
373
  const lastRightCol = tableHeaderLast.value.find((it) => it.fixed === "right");
353
374
  node = { __PARENT__: lastRightCol };
354
375
  while (node = node.__PARENT__) {
355
376
  if (node.fixed) {
356
- fixedShadowCols.push(node);
377
+ fixedShadowCols.value.push(node);
357
378
  }
358
379
  }
359
380
  }
360
- function getFixedColClass(col) {
361
- const { showR, showL } = fixedShadow.value;
362
- const showShadow = props.fixedColShadow && col.fixed && (showL && col.fixed === "left" || showR && col.fixed === "right") && fixedShadowCols.includes(col);
363
- const classObj = {
364
- "fixed-cell": col.fixed,
365
- ["fixed-cell--" + col.fixed]: col.fixed,
366
- "fixed-cell--shadow": showShadow
367
- };
368
- return classObj;
369
- }
370
381
  function updateFixedShadow() {
371
382
  if (!props.fixedColShadow)
372
383
  return;
@@ -376,7 +387,7 @@ function useFixedCol({ props, tableHeaderLast, tableContainer }) {
376
387
  }
377
388
  return {
378
389
  /** 固定列class */
379
- getFixedColClass,
390
+ fixedColClassMap,
380
391
  /** 处理固定列阴影 */
381
392
  dealFixedColShadow,
382
393
  /** 滚动条变化时,更新需要展示阴影的列 */
@@ -436,7 +447,7 @@ function useFixedStyle({
436
447
  } else {
437
448
  style.position = "sticky";
438
449
  }
439
- if (tagType === 1) {
450
+ if (tagType === TagType.TH) {
440
451
  if (Is_Legacy_Mode) {
441
452
  style.top = virtualScroll.value.scrollTop + depth * props.rowHeight + "px";
442
453
  } else {
@@ -528,16 +539,16 @@ function useHighlight({ props, tableContainer }) {
528
539
  }, Highlight_Duration)
529
540
  );
530
541
  }
531
- function setHighlightDimRow(rowKeyValues) {
542
+ function setHighlightDimRow(rowKeyValues, option = {}) {
532
543
  var _a, _b;
533
544
  if (!Array.isArray(rowKeyValues))
534
545
  rowKeyValues = [rowKeyValues];
535
- if (props.virtual) {
546
+ if (props.virtual && !option.useCss) {
536
547
  const nowTs = Date.now();
537
548
  for (let i = 0; i < rowKeyValues.length; i++) {
538
549
  const rowKeyValue = rowKeyValues[i];
539
550
  highlightRowStore.value[rowKeyValue] = {
540
- bgc: "",
551
+ bgc: highlightFrom.value,
541
552
  bgc_progress: 0,
542
553
  bgc_progress_ms: nowTs
543
554
  };
@@ -1042,9 +1053,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1042
1053
  virtualScrollX,
1043
1054
  tableHeaders
1044
1055
  });
1045
- const { getFixedColClass, dealFixedColShadow, updateFixedShadow } = useFixedCol({
1056
+ const { fixedColClassMap, dealFixedColShadow, updateFixedShadow } = useFixedCol({
1046
1057
  props,
1058
+ colKeyGen,
1047
1059
  tableContainer,
1060
+ tableHeaders,
1048
1061
  tableHeaderLast
1049
1062
  });
1050
1063
  watch(
@@ -1157,33 +1170,42 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1157
1170
  function colKeyGen(col) {
1158
1171
  return typeof props.colKey === "function" ? props.colKey(col) : col[props.colKey];
1159
1172
  }
1160
- function getColWidthStyle(col) {
1161
- const width = getColWidthStr(col);
1162
- const minWidth = getColWidthStr(col, "minWidth");
1163
- const maxWidth = getColWidthStr(col, "maxWidth");
1164
- const style = {
1165
- width,
1166
- minWidth: minWidth ?? width,
1167
- maxWidth: maxWidth ?? width
1168
- };
1169
- if (props.colResizable) {
1170
- style.minWidth = width;
1171
- style.maxWidth = width;
1172
- }
1173
- return style;
1174
- }
1175
- function getCellStyle(tagType, col, depth) {
1176
- const style = {
1177
- ...getColWidthStyle(col),
1178
- ...getFixedStyle(tagType, col, depth)
1173
+ const cellStyleMap = computed(() => {
1174
+ const thMap = /* @__PURE__ */ new Map();
1175
+ const tdMap = /* @__PURE__ */ new Map();
1176
+ tableHeaders.value.forEach((cols, depth) => {
1177
+ cols.forEach((col) => {
1178
+ const colKey = colKeyGen(col);
1179
+ const width = getColWidthStr(col);
1180
+ const style = {
1181
+ width
1182
+ };
1183
+ if (props.colResizable) {
1184
+ style.minWidth = width;
1185
+ style.maxWidth = width;
1186
+ } else {
1187
+ style.minWidth = getColWidthStr(col, "minWidth") ?? width;
1188
+ style.maxWidth = getColWidthStr(col, "maxWidth") ?? width;
1189
+ }
1190
+ const thStyle = {
1191
+ ...style,
1192
+ ...getFixedStyle(TagType.TH, col, depth),
1193
+ textAlign: col.headerAlign
1194
+ };
1195
+ const tdStyle = {
1196
+ ...style,
1197
+ ...getFixedStyle(TagType.TD, col, depth),
1198
+ textAlign: col.align
1199
+ };
1200
+ thMap.set(colKey, thStyle);
1201
+ tdMap.set(colKey, tdStyle);
1202
+ });
1203
+ });
1204
+ return {
1205
+ [TagType.TH]: thMap,
1206
+ [TagType.TD]: tdMap
1179
1207
  };
1180
- if (tagType === 1) {
1181
- style.textAlign = col.headerAlign;
1182
- } else if (tagType === 2) {
1183
- style.textAlign = col.align;
1184
- }
1185
- return style;
1186
- }
1208
+ });
1187
1209
  function getHeaderTitle(col) {
1188
1210
  if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(col.dataIndex)) {
1189
1211
  return "";
@@ -1410,14 +1432,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1410
1432
  draggable: unref(isHeaderDraggable)(col) ? "true" : "false",
1411
1433
  rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
1412
1434
  colspan: col.colSpan,
1413
- style: normalizeStyle(getCellStyle(1, col, rowIndex)),
1435
+ style: normalizeStyle(cellStyleMap.value[unref(TagType).TH].get(colKeyGen(col))),
1414
1436
  title: getHeaderTitle(col),
1415
1437
  class: normalizeClass([
1416
1438
  col.sorter ? "sortable" : "",
1417
1439
  col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
1418
1440
  _ctx.showHeaderOverflow ? "text-overflow" : "",
1419
1441
  col.headerClassName,
1420
- unref(getFixedColClass)(col)
1442
+ unref(fixedColClassMap).get(colKeyGen(col))
1421
1443
  ]),
1422
1444
  onClick: (e) => {
1423
1445
  onColumnSort(col);
@@ -1475,7 +1497,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1475
1497
  _ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
1476
1498
  return openBlock(), createElementBlock("td", {
1477
1499
  key: col.dataIndex,
1478
- style: normalizeStyle(getCellStyle(2, col))
1500
+ style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen(col)))
1479
1501
  }, null, 4);
1480
1502
  }), 128)) : createCommentVNode("", true)
1481
1503
  ], 4)) : createCommentVNode("", true),
@@ -1502,8 +1524,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1502
1524
  return openBlock(), createElementBlock("td", {
1503
1525
  key: col.dataIndex,
1504
1526
  "data-index": col.dataIndex,
1505
- class: normalizeClass([col.className, _ctx.showOverflow ? "text-overflow" : "", unref(getFixedColClass)(col)]),
1506
- style: normalizeStyle(getCellStyle(2, col)),
1527
+ class: normalizeClass([col.className, _ctx.showOverflow ? "text-overflow" : "", unref(fixedColClassMap).get(colKeyGen(col))]),
1528
+ style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen(col))),
1507
1529
  onClick: (e) => onCellClick(e, row, col)
1508
1530
  }, [
1509
1531
  col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stk-table-vue",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Simple realtime virtual table for vue3&vue2.7",
5
5
  "main": "./lib/stk-table-vue.js",
6
6
  "types": "./lib/src/StkTable/index.d.ts",
@@ -60,14 +60,14 @@
60
60
  :draggable="isHeaderDraggable(col) ? 'true' : 'false'"
61
61
  :rowspan="virtualX_on ? 1 : col.rowSpan"
62
62
  :colspan="col.colSpan"
63
- :style="getCellStyle(1, col, rowIndex)"
63
+ :style="cellStyleMap[TagType.TH].get(colKeyGen(col))"
64
64
  :title="getHeaderTitle(col)"
65
65
  :class="[
66
66
  col.sorter ? 'sortable' : '',
67
67
  col.dataIndex === sortCol && sortOrderIndex !== 0 && 'sorter-' + sortSwitchOrder[sortOrderIndex],
68
68
  showHeaderOverflow ? 'text-overflow' : '',
69
69
  col.headerClassName,
70
- getFixedColClass(col),
70
+ fixedColClassMap.get(colKeyGen(col)),
71
71
  ]"
72
72
  @click="
73
73
  e => {
@@ -135,7 +135,7 @@
135
135
  <!--这个td用于配合虚拟滚动的th对应,防止列错位-->
136
136
  <td v-if="virtualX_on && fixedMode && headless" class="virtual-x-left" style="padding: 0"></td>
137
137
  <template v-if="fixedMode && headless">
138
- <td v-for="col in virtualX_columnPart" :key="col.dataIndex" :style="getCellStyle(2, col)"></td
138
+ <td v-for="col in virtualX_columnPart" :key="col.dataIndex" :style="cellStyleMap[TagType.TD].get(colKeyGen(col))"></td
139
139
  ></template>
140
140
  </tr>
141
141
  <tr
@@ -161,8 +161,8 @@
161
161
  v-for="col in virtualX_columnPart"
162
162
  :key="col.dataIndex"
163
163
  :data-index="col.dataIndex"
164
- :class="[col.className, showOverflow ? 'text-overflow' : '', getFixedColClass(col)]"
165
- :style="getCellStyle(2, col)"
164
+ :class="[col.className, showOverflow ? 'text-overflow' : '', fixedColClassMap.get(colKeyGen(col))]"
165
+ :style="cellStyleMap[TagType.TD].get(colKeyGen(col))"
166
166
  @click="e => onCellClick(e, row, col)"
167
167
  >
168
168
  <component :is="col.customCell" v-if="col.customCell" :col="col" :row="row" :cell-value="row[col.dataIndex]" />
@@ -191,7 +191,7 @@
191
191
  */
192
192
  import { CSSProperties, computed, onMounted, ref, shallowRef, toRaw, watch } from 'vue';
193
193
  import { Default_Row_Height } from './const';
194
- import { Order, SortConfig, SortOption, SortState, StkTableColumn, UniqKeyProp } from './types/index';
194
+ import { Order, SortConfig, SortOption, SortState, StkTableColumn, TagType, UniqKeyProp } from './types/index';
195
195
  import { useAutoResize } from './useAutoResize';
196
196
  import { useColResize } from './useColResize';
197
197
  import { useFixedCol } from './useFixedCol';
@@ -513,9 +513,11 @@ useKeyboardArrowScroll(tableContainer, {
513
513
  });
514
514
 
515
515
  /** 固定列处理 */
516
- const { getFixedColClass, dealFixedColShadow, updateFixedShadow } = useFixedCol({
516
+ const { fixedColClassMap, dealFixedColShadow, updateFixedShadow } = useFixedCol({
517
517
  props,
518
+ colKeyGen,
518
519
  tableContainer,
520
+ tableHeaders,
519
521
  tableHeaderLast,
520
522
  });
521
523
 
@@ -668,47 +670,45 @@ function colKeyGen(col: StkTableColumn<DT>) {
668
670
  return typeof props.colKey === 'function' ? props.colKey(col) : (col as any)[props.colKey];
669
671
  }
670
672
 
671
- /** 获取列宽度样式 */
672
- function getColWidthStyle(col: StkTableColumn<DT>) {
673
- const width = getColWidthStr(col);
674
- const minWidth = getColWidthStr(col, 'minWidth');
675
- const maxWidth = getColWidthStr(col, 'maxWidth');
676
- const style: CSSProperties = {
677
- width,
678
- minWidth: minWidth ?? width,
679
- maxWidth: maxWidth ?? width,
680
- };
681
- if (props.colResizable) {
682
- style.minWidth = width;
683
- style.maxWidth = width;
684
- }
685
-
686
- return style;
687
- }
673
+ /** 单元格样式 */
674
+ const cellStyleMap = computed(() => {
675
+ const thMap = new Map();
676
+ const tdMap = new Map();
677
+ tableHeaders.value.forEach((cols, depth) => {
678
+ cols.forEach(col => {
679
+ const colKey = colKeyGen(col);
680
+ const width = getColWidthStr(col);
681
+ const style: CSSProperties = {
682
+ width,
683
+ };
684
+ if (props.colResizable) {
685
+ style.minWidth = width;
686
+ style.maxWidth = width;
687
+ } else {
688
+ style.minWidth = getColWidthStr(col, 'minWidth') ?? width;
689
+ style.maxWidth = getColWidthStr(col, 'maxWidth') ?? width;
690
+ }
688
691
 
689
- /**
690
- * 性能优化,缓存style行内样式
691
- *
692
- * FIXME: col变化时仍从缓存拿style。watch col?
693
- * @param tagType 1-th 2-td
694
- * @param col
695
- * @param depth 表头层级
696
- */
697
- function getCellStyle(tagType: 1 | 2, col: StkTableColumn<DT>, depth?: number): CSSProperties {
698
- const style: CSSProperties = {
699
- ...getColWidthStyle(col),
700
- ...getFixedStyle(tagType, col, depth),
692
+ const thStyle = {
693
+ ...style,
694
+ ...getFixedStyle(TagType.TH, col, depth),
695
+ textAlign: col.headerAlign,
696
+ };
697
+ const tdStyle = {
698
+ ...style,
699
+ ...getFixedStyle(TagType.TD, col, depth),
700
+ textAlign: col.align,
701
+ };
702
+
703
+ thMap.set(colKey, thStyle);
704
+ tdMap.set(colKey, tdStyle);
705
+ });
706
+ });
707
+ return {
708
+ [TagType.TH]: thMap,
709
+ [TagType.TD]: tdMap,
701
710
  };
702
- if (tagType === 1) {
703
- // TH
704
- style.textAlign = col.headerAlign;
705
- } else if (tagType === 2) {
706
- // TD
707
- style.textAlign = col.align;
708
- }
709
-
710
- return style;
711
- }
711
+ });
712
712
 
713
713
  /** th title */
714
714
  function getHeaderTitle(col: StkTableColumn<DT>): string {
@@ -93,3 +93,9 @@ export type SortConfig<T extends Record<string, any>> = {
93
93
  */
94
94
  stringLocaleCompare?: boolean;
95
95
  };
96
+
97
+ /** th td类型 */
98
+ export const enum TagType {
99
+ TH,
100
+ TD,
101
+ }
@@ -1,8 +1,10 @@
1
- import { ref, Ref } from 'vue';
1
+ import { computed, ref, Ref, shallowRef } from 'vue';
2
2
  import { StkTableColumn } from './types';
3
3
 
4
4
  type Params<T extends Record<string, any>> = {
5
5
  props: any;
6
+ colKeyGen: (col: StkTableColumn<T>) => string;
7
+ tableHeaders: Ref<StkTableColumn<T>[][]>;
6
8
  tableHeaderLast: Ref<StkTableColumn<T>[]>;
7
9
  tableContainer: Ref<HTMLDivElement | undefined>;
8
10
  };
@@ -11,7 +13,7 @@ type Params<T extends Record<string, any>> = {
11
13
  * 固定列处理
12
14
  * @returns
13
15
  */
14
- export function useFixedCol<DT extends Record<string, any>>({ props, tableHeaderLast, tableContainer }: Params<DT>) {
16
+ export function useFixedCol<DT extends Record<string, any>>({ props, colKeyGen, tableHeaders, tableHeaderLast, tableContainer }: Params<DT>) {
15
17
  /** 固定列阴影 */
16
18
  const fixedShadow = ref<{
17
19
  /** 是否展示左侧固定列阴影 */
@@ -23,12 +25,33 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
23
25
  showR: false,
24
26
  });
25
27
  /** 保存需要出现阴影的列 */
26
- let fixedShadowCols: StkTableColumn<DT>[] = [];
28
+ const fixedShadowCols = shallowRef<StkTableColumn<DT>[]>([]);
29
+
30
+ const fixedColClassMap = computed(() => {
31
+ const colMap = new Map();
32
+ tableHeaders.value.forEach(cols => {
33
+ cols.forEach(col => {
34
+ const { showR, showL } = fixedShadow.value;
35
+ const showShadow =
36
+ props.fixedColShadow &&
37
+ col.fixed &&
38
+ ((showL && col.fixed === 'left') || (showR && col.fixed === 'right')) &&
39
+ fixedShadowCols.value.includes(col);
40
+ const classObj = {
41
+ 'fixed-cell': col.fixed,
42
+ ['fixed-cell--' + col.fixed]: col.fixed,
43
+ 'fixed-cell--shadow': showShadow,
44
+ };
45
+ colMap.set(colKeyGen(col), classObj);
46
+ });
47
+ });
48
+ return colMap;
49
+ });
27
50
 
28
51
  /** 处理固定列阴影 */
29
52
  function dealFixedColShadow() {
30
53
  if (!props.fixedColShadow) return;
31
- fixedShadowCols = [];
54
+ fixedShadowCols.value = [];
32
55
  // 找到最右边的固定列 findLast
33
56
  let lastLeftCol = null;
34
57
  for (let i = tableHeaderLast.value.length - 1; i >= 0; i--) {
@@ -42,7 +65,7 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
42
65
  let node: any = { __PARENT__: lastLeftCol };
43
66
  while ((node = node.__PARENT__)) {
44
67
  if (node.fixed) {
45
- fixedShadowCols.push(node);
68
+ fixedShadowCols.value.push(node);
46
69
  }
47
70
  }
48
71
 
@@ -51,27 +74,11 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
51
74
  node = { __PARENT__: lastRightCol };
52
75
  while ((node = node.__PARENT__)) {
53
76
  if (node.fixed) {
54
- fixedShadowCols.push(node);
77
+ fixedShadowCols.value.push(node);
55
78
  }
56
79
  }
57
80
  }
58
81
 
59
- /** 固定列class */
60
- function getFixedColClass(col: StkTableColumn<DT>): Record<string, boolean> {
61
- const { showR, showL } = fixedShadow.value;
62
- const showShadow =
63
- props.fixedColShadow &&
64
- col.fixed &&
65
- ((showL && col.fixed === 'left') || (showR && col.fixed === 'right')) &&
66
- fixedShadowCols.includes(col);
67
- const classObj = {
68
- 'fixed-cell': col.fixed,
69
- ['fixed-cell--' + col.fixed]: col.fixed,
70
- 'fixed-cell--shadow': showShadow,
71
- };
72
- return classObj;
73
- }
74
-
75
82
  /** 滚动条变化时,更新需要展示阴影的列 */
76
83
  function updateFixedShadow() {
77
84
  if (!props.fixedColShadow) return;
@@ -82,7 +89,7 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
82
89
 
83
90
  return {
84
91
  /** 固定列class */
85
- getFixedColClass,
92
+ fixedColClassMap,
86
93
  /** 处理固定列阴影 */
87
94
  dealFixedColShadow,
88
95
  /** 滚动条变化时,更新需要展示阴影的列 */
@@ -1,6 +1,6 @@
1
1
  import { CSSProperties, Ref, computed } from 'vue';
2
2
  import { Is_Legacy_Mode } from './const';
3
- import { StkTableColumn } from './types';
3
+ import { StkTableColumn, TagType } from './types';
4
4
  import { VirtualScrollStore, VirtualScrollXStore } from './useVirtualScroll';
5
5
  import { getColWidth } from './utils';
6
6
 
@@ -64,24 +64,25 @@ export function useFixedStyle<DT extends Record<string, any>>({
64
64
 
65
65
  return { refStore, colKeyStore };
66
66
  });
67
+
67
68
  /**
68
69
  * 固定列的style
69
70
  * @param tagType 1-th 2-td
70
71
  * @param col
71
72
  * @param depth 深度。tagType = 1时使用
72
73
  */
73
- function getFixedStyle(tagType: 1 | 2, col: StkTableColumn<any>, depth = 0): CSSProperties {
74
+ function getFixedStyle(tagType: TagType, col: StkTableColumn<DT>, depth = 0): CSSProperties {
74
75
  const { fixed } = col;
75
76
  const isFixedLeft = fixed === 'left';
76
77
  const style: CSSProperties = {};
77
78
  const { colKeyStore, refStore } = fixedColumnsPositionStore.value;
78
- // TD
79
+
79
80
  if (Is_Legacy_Mode) {
80
81
  style.position = 'relative';
81
82
  } else {
82
83
  style.position = 'sticky';
83
84
  }
84
- if (tagType === 1) {
85
+ if (tagType === TagType.TH) {
85
86
  // TH
86
87
  if (Is_Legacy_Mode) {
87
88
  style.top = virtualScroll.value.scrollTop + depth * props.rowHeight + 'px';
@@ -90,6 +91,7 @@ export function useFixedStyle<DT extends Record<string, any>>({
90
91
  }
91
92
  style.zIndex = isFixedLeft ? '5' : '4'; // 保证固定列高于其他单元格
92
93
  } else {
94
+ // TD
93
95
  style.zIndex = isFixedLeft ? '3' : '2';
94
96
  }
95
97
 
@@ -114,16 +114,17 @@ export function useHighlight({ props, tableContainer }: Params) {
114
114
  /**
115
115
  * 高亮一行
116
116
  * @param rowKeyValues
117
+ * @param option.useCss 虚拟滚动时,高亮由js控制。如果仍想使用css 关键帧控制,则配置此项
117
118
  */
118
- function setHighlightDimRow(rowKeyValues: UniqKey[]) {
119
+ function setHighlightDimRow(rowKeyValues: UniqKey[], option: { useCss?: boolean } = {}) {
119
120
  if (!Array.isArray(rowKeyValues)) rowKeyValues = [rowKeyValues];
120
- if (props.virtual) {
121
+ if (props.virtual && !option.useCss) {
121
122
  // --------虚拟滚动用js计算颜色渐变的高亮方案
122
123
  const nowTs = Date.now(); // 重置渐变进度
123
124
  for (let i = 0; i < rowKeyValues.length; i++) {
124
125
  const rowKeyValue = rowKeyValues[i];
125
126
  highlightRowStore.value[rowKeyValue] = {
126
- bgc: '',
127
+ bgc: highlightFrom.value,
127
128
  bgc_progress: 0,
128
129
  bgc_progress_ms: nowTs,
129
130
  };