stk-table-vue 0.2.6 → 0.2.7

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,7 @@ 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;
5
6
  tableHeaderLast: Ref<StkTableColumn<T>[]>;
6
7
  tableContainer: Ref<HTMLDivElement | undefined>;
7
8
  };
@@ -9,9 +10,9 @@ type Params<T extends Record<string, any>> = {
9
10
  * 固定列处理
10
11
  * @returns
11
12
  */
12
- export declare function useFixedCol<DT extends Record<string, any>>({ props, tableHeaderLast, tableContainer }: Params<DT>): {
13
+ export declare function useFixedCol<DT extends Record<string, any>>({ props, colKeyGen, tableHeaderLast, tableContainer }: Params<DT>): {
13
14
  /** 固定列class */
14
- getFixedColClass: (col: StkTableColumn<DT>) => Record<string, boolean>;
15
+ fixedColClassMap: import("vue").ComputedRef<Map<any, any>>;
15
16
  /** 处理固定列阴影 */
16
17
  dealFixedColShadow: () => void;
17
18
  /** 滚动条变化时,更新需要展示阴影的列 */
@@ -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,30 @@ function useColResize({
325
330
  onThResizeMouseUp
326
331
  };
327
332
  }
328
- function useFixedCol({ props, tableHeaderLast, tableContainer }) {
333
+ function useFixedCol({ props, colKeyGen, 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
+ props.columns.forEach((col) => {
342
+ const { showR, showL } = fixedShadow.value;
343
+ const showShadow = props.fixedColShadow && col.fixed && (showL && col.fixed === "left" || showR && col.fixed === "right") && fixedShadowCols.value.includes(col);
344
+ const classObj = {
345
+ "fixed-cell": col.fixed,
346
+ ["fixed-cell--" + col.fixed]: col.fixed,
347
+ "fixed-cell--shadow": showShadow
348
+ };
349
+ colMap.set(colKeyGen(col), classObj);
350
+ });
351
+ return colMap;
352
+ });
334
353
  function dealFixedColShadow() {
335
354
  if (!props.fixedColShadow)
336
355
  return;
337
- fixedShadowCols = [];
356
+ fixedShadowCols.value = [];
338
357
  let lastLeftCol = null;
339
358
  for (let i = tableHeaderLast.value.length - 1; i >= 0; i--) {
340
359
  const col = tableHeaderLast.value[i];
@@ -346,27 +365,17 @@ function useFixedCol({ props, tableHeaderLast, tableContainer }) {
346
365
  let node = { __PARENT__: lastLeftCol };
347
366
  while (node = node.__PARENT__) {
348
367
  if (node.fixed) {
349
- fixedShadowCols.push(node);
368
+ fixedShadowCols.value.push(node);
350
369
  }
351
370
  }
352
371
  const lastRightCol = tableHeaderLast.value.find((it) => it.fixed === "right");
353
372
  node = { __PARENT__: lastRightCol };
354
373
  while (node = node.__PARENT__) {
355
374
  if (node.fixed) {
356
- fixedShadowCols.push(node);
375
+ fixedShadowCols.value.push(node);
357
376
  }
358
377
  }
359
378
  }
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
379
  function updateFixedShadow() {
371
380
  if (!props.fixedColShadow)
372
381
  return;
@@ -376,7 +385,7 @@ function useFixedCol({ props, tableHeaderLast, tableContainer }) {
376
385
  }
377
386
  return {
378
387
  /** 固定列class */
379
- getFixedColClass,
388
+ fixedColClassMap,
380
389
  /** 处理固定列阴影 */
381
390
  dealFixedColShadow,
382
391
  /** 滚动条变化时,更新需要展示阴影的列 */
@@ -436,7 +445,7 @@ function useFixedStyle({
436
445
  } else {
437
446
  style.position = "sticky";
438
447
  }
439
- if (tagType === 1) {
448
+ if (tagType === TagType.TH) {
440
449
  if (Is_Legacy_Mode) {
441
450
  style.top = virtualScroll.value.scrollTop + depth * props.rowHeight + "px";
442
451
  } else {
@@ -528,16 +537,16 @@ function useHighlight({ props, tableContainer }) {
528
537
  }, Highlight_Duration)
529
538
  );
530
539
  }
531
- function setHighlightDimRow(rowKeyValues) {
540
+ function setHighlightDimRow(rowKeyValues, option = {}) {
532
541
  var _a, _b;
533
542
  if (!Array.isArray(rowKeyValues))
534
543
  rowKeyValues = [rowKeyValues];
535
- if (props.virtual) {
544
+ if (props.virtual && !option.useCss) {
536
545
  const nowTs = Date.now();
537
546
  for (let i = 0; i < rowKeyValues.length; i++) {
538
547
  const rowKeyValue = rowKeyValues[i];
539
548
  highlightRowStore.value[rowKeyValue] = {
540
- bgc: "",
549
+ bgc: highlightFrom.value,
541
550
  bgc_progress: 0,
542
551
  bgc_progress_ms: nowTs
543
552
  };
@@ -1042,8 +1051,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1042
1051
  virtualScrollX,
1043
1052
  tableHeaders
1044
1053
  });
1045
- const { getFixedColClass, dealFixedColShadow, updateFixedShadow } = useFixedCol({
1054
+ const { fixedColClassMap, dealFixedColShadow, updateFixedShadow } = useFixedCol({
1046
1055
  props,
1056
+ colKeyGen,
1047
1057
  tableContainer,
1048
1058
  tableHeaderLast
1049
1059
  });
@@ -1157,33 +1167,42 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1157
1167
  function colKeyGen(col) {
1158
1168
  return typeof props.colKey === "function" ? props.colKey(col) : col[props.colKey];
1159
1169
  }
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)
1170
+ const cellStyleMap = computed(() => {
1171
+ const thMap = /* @__PURE__ */ new Map();
1172
+ const tdMap = /* @__PURE__ */ new Map();
1173
+ tableHeaders.value.forEach((cols, depth) => {
1174
+ cols.forEach((col) => {
1175
+ const colKey = colKeyGen(col);
1176
+ const width = getColWidthStr(col);
1177
+ const style = {
1178
+ width
1179
+ };
1180
+ if (props.colResizable) {
1181
+ style.minWidth = width;
1182
+ style.maxWidth = width;
1183
+ } else {
1184
+ style.minWidth = getColWidthStr(col, "minWidth") ?? width;
1185
+ style.maxWidth = getColWidthStr(col, "maxWidth") ?? width;
1186
+ }
1187
+ const thStyle = {
1188
+ ...style,
1189
+ ...getFixedStyle(TagType.TH, col, depth),
1190
+ textAlign: col.headerAlign
1191
+ };
1192
+ const tdStyle = {
1193
+ ...style,
1194
+ ...getFixedStyle(TagType.TD, col, depth),
1195
+ textAlign: col.align
1196
+ };
1197
+ thMap.set(colKey, thStyle);
1198
+ tdMap.set(colKey, tdStyle);
1199
+ });
1200
+ });
1201
+ return {
1202
+ [TagType.TH]: thMap,
1203
+ [TagType.TD]: tdMap
1179
1204
  };
1180
- if (tagType === 1) {
1181
- style.textAlign = col.headerAlign;
1182
- } else if (tagType === 2) {
1183
- style.textAlign = col.align;
1184
- }
1185
- return style;
1186
- }
1205
+ });
1187
1206
  function getHeaderTitle(col) {
1188
1207
  if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(col.dataIndex)) {
1189
1208
  return "";
@@ -1410,14 +1429,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1410
1429
  draggable: unref(isHeaderDraggable)(col) ? "true" : "false",
1411
1430
  rowspan: unref(virtualX_on) ? 1 : col.rowSpan,
1412
1431
  colspan: col.colSpan,
1413
- style: normalizeStyle(getCellStyle(1, col, rowIndex)),
1432
+ style: normalizeStyle(cellStyleMap.value[unref(TagType).TH].get(colKeyGen(col))),
1414
1433
  title: getHeaderTitle(col),
1415
1434
  class: normalizeClass([
1416
1435
  col.sorter ? "sortable" : "",
1417
1436
  col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
1418
1437
  _ctx.showHeaderOverflow ? "text-overflow" : "",
1419
1438
  col.headerClassName,
1420
- unref(getFixedColClass)(col)
1439
+ unref(fixedColClassMap).get(colKeyGen(col))
1421
1440
  ]),
1422
1441
  onClick: (e) => {
1423
1442
  onColumnSort(col);
@@ -1475,7 +1494,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1475
1494
  _ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
1476
1495
  return openBlock(), createElementBlock("td", {
1477
1496
  key: col.dataIndex,
1478
- style: normalizeStyle(getCellStyle(2, col))
1497
+ style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen(col)))
1479
1498
  }, null, 4);
1480
1499
  }), 128)) : createCommentVNode("", true)
1481
1500
  ], 4)) : createCommentVNode("", true),
@@ -1502,8 +1521,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1502
1521
  return openBlock(), createElementBlock("td", {
1503
1522
  key: col.dataIndex,
1504
1523
  "data-index": col.dataIndex,
1505
- class: normalizeClass([col.className, _ctx.showOverflow ? "text-overflow" : "", unref(getFixedColClass)(col)]),
1506
- style: normalizeStyle(getCellStyle(2, col)),
1524
+ class: normalizeClass([col.className, _ctx.showOverflow ? "text-overflow" : "", unref(fixedColClassMap).get(colKeyGen(col))]),
1525
+ style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen(col))),
1507
1526
  onClick: (e) => onCellClick(e, row, col)
1508
1527
  }, [
1509
1528
  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.7",
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,8 +513,9 @@ 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,
519
520
  tableHeaderLast,
520
521
  });
@@ -668,47 +669,45 @@ function colKeyGen(col: StkTableColumn<DT>) {
668
669
  return typeof props.colKey === 'function' ? props.colKey(col) : (col as any)[props.colKey];
669
670
  }
670
671
 
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
- }
672
+ /** 单元格样式 */
673
+ const cellStyleMap = computed(() => {
674
+ const thMap = new Map();
675
+ const tdMap = new Map();
676
+ tableHeaders.value.forEach((cols, depth) => {
677
+ cols.forEach(col => {
678
+ const colKey = colKeyGen(col);
679
+ const width = getColWidthStr(col);
680
+ const style: CSSProperties = {
681
+ width,
682
+ };
683
+ if (props.colResizable) {
684
+ style.minWidth = width;
685
+ style.maxWidth = width;
686
+ } else {
687
+ style.minWidth = getColWidthStr(col, 'minWidth') ?? width;
688
+ style.maxWidth = getColWidthStr(col, 'maxWidth') ?? width;
689
+ }
688
690
 
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),
691
+ const thStyle = {
692
+ ...style,
693
+ ...getFixedStyle(TagType.TH, col, depth),
694
+ textAlign: col.headerAlign,
695
+ };
696
+ const tdStyle = {
697
+ ...style,
698
+ ...getFixedStyle(TagType.TD, col, depth),
699
+ textAlign: col.align,
700
+ };
701
+
702
+ thMap.set(colKey, thStyle);
703
+ tdMap.set(colKey, tdStyle);
704
+ });
705
+ });
706
+ return {
707
+ [TagType.TH]: thMap,
708
+ [TagType.TD]: tdMap,
701
709
  };
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
- }
710
+ });
712
711
 
713
712
  /** th title */
714
713
  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,9 @@
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;
6
7
  tableHeaderLast: Ref<StkTableColumn<T>[]>;
7
8
  tableContainer: Ref<HTMLDivElement | undefined>;
8
9
  };
@@ -11,7 +12,7 @@ type Params<T extends Record<string, any>> = {
11
12
  * 固定列处理
12
13
  * @returns
13
14
  */
14
- export function useFixedCol<DT extends Record<string, any>>({ props, tableHeaderLast, tableContainer }: Params<DT>) {
15
+ export function useFixedCol<DT extends Record<string, any>>({ props, colKeyGen, tableHeaderLast, tableContainer }: Params<DT>) {
15
16
  /** 固定列阴影 */
16
17
  const fixedShadow = ref<{
17
18
  /** 是否展示左侧固定列阴影 */
@@ -23,12 +24,31 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
23
24
  showR: false,
24
25
  });
25
26
  /** 保存需要出现阴影的列 */
26
- let fixedShadowCols: StkTableColumn<DT>[] = [];
27
+ const fixedShadowCols = shallowRef<StkTableColumn<DT>[]>([]);
28
+
29
+ const fixedColClassMap = computed(() => {
30
+ const colMap = new Map();
31
+ props.columns.forEach((col: any) => {
32
+ const { showR, showL } = fixedShadow.value;
33
+ const showShadow =
34
+ props.fixedColShadow &&
35
+ col.fixed &&
36
+ ((showL && col.fixed === 'left') || (showR && col.fixed === 'right')) &&
37
+ fixedShadowCols.value.includes(col);
38
+ const classObj = {
39
+ 'fixed-cell': col.fixed,
40
+ ['fixed-cell--' + col.fixed]: col.fixed,
41
+ 'fixed-cell--shadow': showShadow,
42
+ };
43
+ colMap.set(colKeyGen(col), classObj);
44
+ });
45
+ return colMap;
46
+ });
27
47
 
28
48
  /** 处理固定列阴影 */
29
49
  function dealFixedColShadow() {
30
50
  if (!props.fixedColShadow) return;
31
- fixedShadowCols = [];
51
+ fixedShadowCols.value = [];
32
52
  // 找到最右边的固定列 findLast
33
53
  let lastLeftCol = null;
34
54
  for (let i = tableHeaderLast.value.length - 1; i >= 0; i--) {
@@ -42,7 +62,7 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
42
62
  let node: any = { __PARENT__: lastLeftCol };
43
63
  while ((node = node.__PARENT__)) {
44
64
  if (node.fixed) {
45
- fixedShadowCols.push(node);
65
+ fixedShadowCols.value.push(node);
46
66
  }
47
67
  }
48
68
 
@@ -51,27 +71,11 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
51
71
  node = { __PARENT__: lastRightCol };
52
72
  while ((node = node.__PARENT__)) {
53
73
  if (node.fixed) {
54
- fixedShadowCols.push(node);
74
+ fixedShadowCols.value.push(node);
55
75
  }
56
76
  }
57
77
  }
58
78
 
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
79
  /** 滚动条变化时,更新需要展示阴影的列 */
76
80
  function updateFixedShadow() {
77
81
  if (!props.fixedColShadow) return;
@@ -82,7 +86,7 @@ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeader
82
86
 
83
87
  return {
84
88
  /** 固定列class */
85
- getFixedColClass,
89
+ fixedColClassMap,
86
90
  /** 处理固定列阴影 */
87
91
  dealFixedColShadow,
88
92
  /** 滚动条变化时,更新需要展示阴影的列 */
@@ -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
  };