stk-table-vue 0.3.1 → 0.3.3
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.
- package/README.md +32 -3
- package/lib/src/StkTable/StkTable.vue.d.ts +42 -6
- package/lib/src/StkTable/useColResize.d.ts +3 -3
- package/lib/src/StkTable/useFixedCol.d.ts +4 -4
- package/lib/src/StkTable/useVirtualScroll.d.ts +4 -1
- package/lib/stk-table-vue.js +117 -76
- package/lib/style.css +116 -123
- package/package.json +1 -1
- package/src/StkTable/StkTable.vue +106 -46
- package/src/StkTable/style.less +205 -229
- package/src/StkTable/useColResize.ts +5 -5
- package/src/StkTable/useFixedCol.ts +4 -4
- package/src/StkTable/useFixedStyle.ts +30 -9
- package/src/StkTable/useHighlight.ts +5 -4
- package/src/StkTable/useVirtualScroll.ts +19 -15
- package/src/StkTable/utils.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { interpolateRgb } from 'd3-interpolate';
|
|
2
2
|
import { Ref, computed } from 'vue';
|
|
3
|
-
import { HIGHLIGHT_CELL_CLASS, HIGHLIGHT_COLOR, HIGHLIGHT_DURATION, HIGHLIGHT_FREQ, HIGHLIGHT_ROW_CLASS
|
|
3
|
+
import { HIGHLIGHT_CELL_CLASS, HIGHLIGHT_COLOR, HIGHLIGHT_DURATION, HIGHLIGHT_FREQ, HIGHLIGHT_ROW_CLASS } from './const';
|
|
4
4
|
import { HighlightConfig, UniqKey } from './types';
|
|
5
5
|
|
|
6
6
|
type Params = {
|
|
@@ -114,7 +114,7 @@ export function useHighlight({ props, stkTableId, tableContainerRef }: Params) {
|
|
|
114
114
|
/** 经过的时间 ÷ 高亮持续时间 计算出 颜色过渡进度 (0-1) */
|
|
115
115
|
const progress = (nowTs - highlightStart) / highlightDuration;
|
|
116
116
|
let bgc = '';
|
|
117
|
-
if (0
|
|
117
|
+
if (0 <= progress && progress <= 1) {
|
|
118
118
|
bgc = highlightInter.value(progress);
|
|
119
119
|
} else {
|
|
120
120
|
highlightDimRowsJs.delete(rowKeyValue);
|
|
@@ -128,7 +128,7 @@ export function useHighlight({ props, stkTableId, tableContainerRef }: Params) {
|
|
|
128
128
|
} else {
|
|
129
129
|
// 没有则停止循环
|
|
130
130
|
calcHighlightDimLoopJs = false;
|
|
131
|
-
highlightDimRowsJs.clear();
|
|
131
|
+
highlightDimRowsJs.clear(); // TODO: 是否需要 清除
|
|
132
132
|
}
|
|
133
133
|
}, highlightFrequency);
|
|
134
134
|
};
|
|
@@ -198,13 +198,13 @@ export function useHighlight({ props, stkTableId, tableContainerRef }: Params) {
|
|
|
198
198
|
...option,
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
const nowTs = Date.now();
|
|
202
201
|
if (method === 'css' || useCss) {
|
|
203
202
|
// -------- use css keyframe
|
|
204
203
|
highlightRowsInCssKeyframe(rowKeyValues, className, duration);
|
|
205
204
|
} else if (method === 'animation') {
|
|
206
205
|
if (props.virtual) {
|
|
207
206
|
// -------- 用animation 接口实现动画
|
|
207
|
+
const nowTs = Date.now();
|
|
208
208
|
for (let i = 0; i < rowKeyValues.length; i++) {
|
|
209
209
|
const rowKeyValue = rowKeyValues[i];
|
|
210
210
|
const store: HighlightDimRowStore = { ts: nowTs, visible: false, keyframe, duration };
|
|
@@ -222,6 +222,7 @@ export function useHighlight({ props, stkTableId, tableContainerRef }: Params) {
|
|
|
222
222
|
}
|
|
223
223
|
} else if (method === 'js') {
|
|
224
224
|
// -------- 用js计算颜色渐变的高亮方案
|
|
225
|
+
const nowTs = Date.now();
|
|
225
226
|
for (let i = 0; i < rowKeyValues.length; i++) {
|
|
226
227
|
const rowKeyValue = rowKeyValues[i];
|
|
227
228
|
highlightDimRowsJs.set(rowKeyValue, nowTs);
|
|
@@ -30,8 +30,10 @@ export type VirtualScrollStore = {
|
|
|
30
30
|
};
|
|
31
31
|
/** 暂存横向虚拟滚动的数据 */
|
|
32
32
|
export type VirtualScrollXStore = {
|
|
33
|
-
/**
|
|
33
|
+
/** 父容器宽度 */
|
|
34
34
|
containerWidth: number;
|
|
35
|
+
/** 滚动容器的宽度 */
|
|
36
|
+
scrollWidth: number;
|
|
35
37
|
/** 开始位置 */
|
|
36
38
|
startIndex: number;
|
|
37
39
|
/** 结束始位置 */
|
|
@@ -69,6 +71,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
69
71
|
|
|
70
72
|
const virtualScrollX = ref<VirtualScrollXStore>({
|
|
71
73
|
containerWidth: 0,
|
|
74
|
+
scrollWidth: 0,
|
|
72
75
|
startIndex: 0,
|
|
73
76
|
endIndex: 0,
|
|
74
77
|
offsetLeft: 0,
|
|
@@ -83,7 +86,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
83
86
|
const virtual_dataSourcePart = computed(() => {
|
|
84
87
|
if (!virtual_on.value) return dataSourceCopy.value;
|
|
85
88
|
const { startIndex, endIndex } = virtualScroll.value;
|
|
86
|
-
return dataSourceCopy.value.slice(startIndex, endIndex);
|
|
89
|
+
return dataSourceCopy.value.slice(startIndex, endIndex + 1);
|
|
87
90
|
});
|
|
88
91
|
|
|
89
92
|
const virtual_offsetBottom = computed(() => {
|
|
@@ -162,10 +165,9 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
162
165
|
}
|
|
163
166
|
|
|
164
167
|
function initVirtualScrollX() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
virtualScrollX.value.containerWidth = offsetWidth || DEFAULT_TABLE_WIDTH;
|
|
168
|
+
const { clientWidth, scrollLeft, scrollWidth } = tableContainerRef.value || {};
|
|
169
|
+
virtualScrollX.value.containerWidth = clientWidth || DEFAULT_TABLE_WIDTH;
|
|
170
|
+
virtualScrollX.value.scrollWidth = scrollWidth || DEFAULT_TABLE_WIDTH;
|
|
169
171
|
updateVirtualScrollX(scrollLeft);
|
|
170
172
|
}
|
|
171
173
|
/**
|
|
@@ -184,6 +186,10 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
184
186
|
const { rowHeight, pageSize, scrollTop, startIndex: oldStartIndex } = virtualScroll.value;
|
|
185
187
|
// 先更新滚动条位置记录,其他地方可能有依赖。(stripe 时ArrowUp/Down滚动依赖)
|
|
186
188
|
virtualScroll.value.scrollTop = sTop;
|
|
189
|
+
|
|
190
|
+
// 非虚拟滚动不往下执行
|
|
191
|
+
if (!virtual_on.value) return;
|
|
192
|
+
|
|
187
193
|
let startIndex = Math.floor(sTop / rowHeight);
|
|
188
194
|
if (props.stripe) {
|
|
189
195
|
startIndex -= 1; //预渲染1行
|
|
@@ -200,15 +206,13 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
200
206
|
startIndex -= 1; // 奇数-1变成偶数
|
|
201
207
|
}
|
|
202
208
|
}
|
|
203
|
-
let endIndex = startIndex + pageSize
|
|
209
|
+
let endIndex = startIndex + pageSize;
|
|
204
210
|
if (props.stripe) {
|
|
205
211
|
// 由于stripe上方预渲染-1行,这里也要预渲染1+1行
|
|
206
|
-
endIndex +=
|
|
212
|
+
endIndex += 1;
|
|
207
213
|
}
|
|
208
214
|
const offsetTop = startIndex * rowHeight; // startIndex之前的高度
|
|
209
|
-
|
|
210
|
-
endIndex = dataSourceCopy.value.length; // 溢出index修正
|
|
211
|
-
}
|
|
215
|
+
endIndex = Math.min(endIndex, dataSourceCopy.value.length); // 溢出index修正
|
|
212
216
|
if (vue2ScrollYTimeout) {
|
|
213
217
|
window.clearTimeout(vue2ScrollYTimeout);
|
|
214
218
|
}
|
|
@@ -235,6 +239,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
235
239
|
|
|
236
240
|
/** 通过横向滚动条位置,计算横向虚拟滚动的参数 */
|
|
237
241
|
function updateVirtualScrollX(sLeft = 0) {
|
|
242
|
+
if (!props.virtualX) return;
|
|
238
243
|
const headerLength = tableHeaderLast.value?.length;
|
|
239
244
|
const { scrollLeft } = virtualScrollX.value;
|
|
240
245
|
if (!headerLength) return;
|
|
@@ -269,13 +274,12 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
269
274
|
colWidthSum += getCalculatedColWidth(col);
|
|
270
275
|
// 列宽大于容器宽度则停止
|
|
271
276
|
if (colWidthSum >= containerWidth) {
|
|
272
|
-
endIndex = colIndex + 1; //
|
|
277
|
+
endIndex = colIndex + 1; // slice endIndex + 1
|
|
273
278
|
break;
|
|
274
279
|
}
|
|
275
280
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
281
|
+
|
|
282
|
+
endIndex = Math.min(endIndex, headerLength);
|
|
279
283
|
|
|
280
284
|
if (vue2ScrollXTimeout) {
|
|
281
285
|
window.clearTimeout(vue2ScrollXTimeout);
|
package/src/StkTable/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Order, SortConfig, SortOption, SortState, StkTableColumn } from './type
|
|
|
5
5
|
function isEmptyValue(val: any, isNumber?: boolean) {
|
|
6
6
|
let isEmpty = val === null || val === '';
|
|
7
7
|
if (isNumber) {
|
|
8
|
-
isEmpty
|
|
8
|
+
isEmpty = isEmpty || typeof val === 'boolean' || Number.isNaN(+val);
|
|
9
9
|
}
|
|
10
10
|
return isEmpty;
|
|
11
11
|
}
|