stk-table-vue 0.0.1-beta.1
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 +136 -0
- package/lib/StkTable/StkTable.vue.d.ts +169 -0
- package/lib/StkTable/const.d.ts +20 -0
- package/lib/StkTable/index.d.ts +2 -0
- package/lib/StkTable/types/index.d.ts +82 -0
- package/lib/StkTable/useColResize.d.ts +18 -0
- package/lib/StkTable/useThDrag.d.ts +14 -0
- package/lib/StkTable/useVirtualScroll.d.ts +35 -0
- package/lib/StkTable/utils.d.ts +23 -0
- package/lib/StkTableC/store.d.ts +12 -0
- package/lib/stk-table-vue.js +1054 -0
- package/lib/style.css +225 -0
- package/package.json +56 -0
- package/src/StkTable/StkTable.vue +1042 -0
- package/src/StkTable/const.ts +26 -0
- package/src/StkTable/index.ts +2 -0
- package/src/StkTable/types/index.ts +109 -0
- package/src/StkTable/useColResize.ts +172 -0
- package/src/StkTable/useHighlight.ts +150 -0
- package/src/StkTable/useThDrag.ts +43 -0
- package/src/StkTable/useVirtualScroll.ts +186 -0
- package/src/StkTable/utils.ts +132 -0
- package/src/StkTable.d.ts +17 -0
- package/src/StkTable.vue +1686 -0
- package/src/StkTableC/index.vue +193 -0
- package/src/StkTableC/store.js +6 -0
- package/src/StkTable_compatible.vue +590 -0
- package/src/VirtualTree.vue +617 -0
- package/src/VirtualTreeSelect.vue +338 -0
- package/src/images/sort-btn.svg +7 -0
- package/src/vite-env.d.ts +5 -0
|
@@ -0,0 +1,1054 @@
|
|
|
1
|
+
import { ref, onMounted, onBeforeUnmount, computed, defineComponent, shallowRef, watch, toRaw, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, withDirectives, createElementVNode, vShow, Fragment, renderList, createCommentVNode, createBlock, resolveDynamicComponent, renderSlot, toDisplayString, createTextVNode, pushScopeId, popScopeId } from "vue";
|
|
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 Highlight_Color = {
|
|
7
|
+
light: { from: "#71a2fd", to: "#fff" },
|
|
8
|
+
dark: { from: "#1e4c99", to: "#181c21" }
|
|
9
|
+
};
|
|
10
|
+
const Highlight_Duration = 2e3;
|
|
11
|
+
const Highlight_Color_Change_Freq = 100;
|
|
12
|
+
let _chromeVersion = 0;
|
|
13
|
+
try {
|
|
14
|
+
const userAgent = navigator.userAgent.match(/chrome\/\d+/i);
|
|
15
|
+
if (userAgent) {
|
|
16
|
+
_chromeVersion = +userAgent[0].split("/")[1];
|
|
17
|
+
}
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.error("Cannot get Chrome version", e);
|
|
20
|
+
}
|
|
21
|
+
const Is_Legacy_Mode = _chromeVersion < 56;
|
|
22
|
+
function useColResize({ tableContainer, tableHeaderLast, colResizeIndicator, props, emit, colKeyGen }) {
|
|
23
|
+
const isColResizing = ref(false);
|
|
24
|
+
let colResizeState = {
|
|
25
|
+
currentCol: null,
|
|
26
|
+
currentColIndex: 0,
|
|
27
|
+
startX: 0,
|
|
28
|
+
startOffsetTableX: 0
|
|
29
|
+
};
|
|
30
|
+
onMounted(() => {
|
|
31
|
+
initColResizeEvent();
|
|
32
|
+
});
|
|
33
|
+
onBeforeUnmount(() => {
|
|
34
|
+
clearColResizeEvent();
|
|
35
|
+
});
|
|
36
|
+
function initColResizeEvent() {
|
|
37
|
+
window.addEventListener("mousemove", onThResizeMouseMove);
|
|
38
|
+
window.addEventListener("mouseup", onThResizeMouseUp);
|
|
39
|
+
}
|
|
40
|
+
function clearColResizeEvent() {
|
|
41
|
+
window.removeEventListener("mousemove", onThResizeMouseMove);
|
|
42
|
+
window.removeEventListener("mouseup", onThResizeMouseUp);
|
|
43
|
+
}
|
|
44
|
+
function onThResizeMouseDown(e, col, isPrev = false) {
|
|
45
|
+
if (!tableContainer.value)
|
|
46
|
+
return;
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
const { clientX } = e;
|
|
50
|
+
const { scrollLeft } = tableContainer.value;
|
|
51
|
+
const { left } = tableContainer.value.getBoundingClientRect();
|
|
52
|
+
let colIndex = tableHeaderLast.value.findIndex((it) => colKeyGen(it) === colKeyGen(col));
|
|
53
|
+
if (isPrev) {
|
|
54
|
+
colIndex -= 1;
|
|
55
|
+
col = tableHeaderLast.value[colIndex];
|
|
56
|
+
}
|
|
57
|
+
const offsetTableX = clientX - left + scrollLeft;
|
|
58
|
+
isColResizing.value = true;
|
|
59
|
+
Object.assign(colResizeState, {
|
|
60
|
+
currentCol: col,
|
|
61
|
+
currentColIndex: colIndex,
|
|
62
|
+
startX: clientX,
|
|
63
|
+
startOffsetTableX: offsetTableX
|
|
64
|
+
});
|
|
65
|
+
if (colResizeIndicator.value) {
|
|
66
|
+
colResizeIndicator.value.style.display = "block";
|
|
67
|
+
colResizeIndicator.value.style.left = offsetTableX + "px";
|
|
68
|
+
colResizeIndicator.value.style.top = tableContainer.value.scrollTop + "px";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function onThResizeMouseMove(e) {
|
|
72
|
+
if (!isColResizing.value)
|
|
73
|
+
return;
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
const { currentCol, startX, startOffsetTableX } = colResizeState;
|
|
77
|
+
const { clientX } = e;
|
|
78
|
+
let moveX = clientX - startX;
|
|
79
|
+
const currentColWidth = parseInt((currentCol == null ? void 0 : currentCol.width) || Default_Col_Width);
|
|
80
|
+
if (currentColWidth + moveX < props.colMinWidth) {
|
|
81
|
+
moveX = -currentColWidth;
|
|
82
|
+
}
|
|
83
|
+
const offsetTableX = startOffsetTableX + moveX;
|
|
84
|
+
if (!colResizeIndicator.value)
|
|
85
|
+
return;
|
|
86
|
+
colResizeIndicator.value.style.left = offsetTableX + "px";
|
|
87
|
+
}
|
|
88
|
+
function onThResizeMouseUp(e) {
|
|
89
|
+
if (!isColResizing.value)
|
|
90
|
+
return;
|
|
91
|
+
const { startX, currentCol } = colResizeState;
|
|
92
|
+
const { clientX } = e;
|
|
93
|
+
const moveX = clientX - startX;
|
|
94
|
+
let width = parseInt((currentCol == null ? void 0 : currentCol.width) || Default_Col_Width) + moveX;
|
|
95
|
+
if (width < props.colMinWidth)
|
|
96
|
+
width = props.colMinWidth;
|
|
97
|
+
const curCol = tableHeaderLast.value.find((it) => colKeyGen(it) === colKeyGen(currentCol));
|
|
98
|
+
if (!curCol)
|
|
99
|
+
return;
|
|
100
|
+
curCol.width = width + "px";
|
|
101
|
+
emit("update:columns", [...props.columns]);
|
|
102
|
+
if (colResizeIndicator.value) {
|
|
103
|
+
colResizeIndicator.value.style.display = "none";
|
|
104
|
+
colResizeIndicator.value.style.left = "0";
|
|
105
|
+
colResizeIndicator.value.style.top = "0";
|
|
106
|
+
}
|
|
107
|
+
isColResizing.value = false;
|
|
108
|
+
colResizeState = {
|
|
109
|
+
currentCol: null,
|
|
110
|
+
currentColIndex: 0,
|
|
111
|
+
startX: 0,
|
|
112
|
+
startOffsetTableX: 0
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
isColResizing,
|
|
117
|
+
onThResizeMouseDown,
|
|
118
|
+
onThResizeMouseMove,
|
|
119
|
+
onThResizeMouseUp
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function useThDrag({ emit }) {
|
|
123
|
+
let dragStartKey = void 0;
|
|
124
|
+
function onThDragStart(e) {
|
|
125
|
+
dragStartKey = e.target.dataset.colKey;
|
|
126
|
+
emit("th-drag-start", dragStartKey);
|
|
127
|
+
}
|
|
128
|
+
function onThDragOver(e) {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
}
|
|
131
|
+
function onThDrop(e) {
|
|
132
|
+
let th = e.target;
|
|
133
|
+
while (th) {
|
|
134
|
+
if (th.tagName === "TH")
|
|
135
|
+
break;
|
|
136
|
+
th = th.parentNode;
|
|
137
|
+
}
|
|
138
|
+
if (dragStartKey !== th.dataset.colKey) {
|
|
139
|
+
emit("col-order-change", dragStartKey, th.dataset.colKey);
|
|
140
|
+
}
|
|
141
|
+
emit("th-drop", th.dataset.colKey);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
onThDragStart,
|
|
145
|
+
onThDragOver,
|
|
146
|
+
onThDrop
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLast }) {
|
|
150
|
+
const virtualScroll = ref({
|
|
151
|
+
containerHeight: 0,
|
|
152
|
+
startIndex: 0,
|
|
153
|
+
// 数组开始位置
|
|
154
|
+
rowHeight: 28,
|
|
155
|
+
offsetTop: 0,
|
|
156
|
+
// 表格定位上边距
|
|
157
|
+
scrollTop: 0
|
|
158
|
+
// 纵向滚动条位置,用于判断是横向滚动还是纵向
|
|
159
|
+
});
|
|
160
|
+
const virtualScrollX = ref({
|
|
161
|
+
containerWidth: 0,
|
|
162
|
+
startIndex: 0,
|
|
163
|
+
endIndex: 0,
|
|
164
|
+
offsetLeft: 0,
|
|
165
|
+
scrollLeft: 0
|
|
166
|
+
// 横向滚动位置,用于判断是横向滚动还是纵向
|
|
167
|
+
});
|
|
168
|
+
const virtual_on = computed(() => {
|
|
169
|
+
return props.virtual && dataSourceCopy.value.length > virtual_pageSize.value * 2;
|
|
170
|
+
});
|
|
171
|
+
const virtual_pageSize = computed(() => {
|
|
172
|
+
return Math.ceil(virtualScroll.value.containerHeight / virtualScroll.value.rowHeight) + 1;
|
|
173
|
+
});
|
|
174
|
+
const virtual_dataSourcePart = computed(() => {
|
|
175
|
+
if (!virtual_on.value)
|
|
176
|
+
return dataSourceCopy.value;
|
|
177
|
+
return dataSourceCopy.value.slice(
|
|
178
|
+
virtualScroll.value.startIndex,
|
|
179
|
+
virtualScroll.value.startIndex + virtual_pageSize.value
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
const virtual_offsetBottom = computed(() => {
|
|
183
|
+
if (!virtual_on.value)
|
|
184
|
+
return 0;
|
|
185
|
+
return (dataSourceCopy.value.length - virtualScroll.value.startIndex - virtual_dataSourcePart.value.length) * virtualScroll.value.rowHeight;
|
|
186
|
+
});
|
|
187
|
+
const virtualX_on = computed(() => {
|
|
188
|
+
return props.virtualX && tableHeaderLast.value.reduce((sum, col) => sum += parseInt(col.minWidth || col.width || Default_Col_Width), 0) > virtualScrollX.value.containerWidth * 1.5;
|
|
189
|
+
});
|
|
190
|
+
const virtualX_columnPart = computed(() => {
|
|
191
|
+
if (virtualX_on.value) {
|
|
192
|
+
const leftCols = [];
|
|
193
|
+
const rightCols = [];
|
|
194
|
+
for (let i = 0; i < virtualScrollX.value.startIndex; i++) {
|
|
195
|
+
const col = tableHeaderLast.value[i];
|
|
196
|
+
if (col.fixed === "left")
|
|
197
|
+
leftCols.push(col);
|
|
198
|
+
}
|
|
199
|
+
for (let i = virtualScrollX.value.endIndex; i < tableHeaderLast.value.length; i++) {
|
|
200
|
+
const col = tableHeaderLast.value[i];
|
|
201
|
+
if (col.fixed === "right")
|
|
202
|
+
rightCols.push(col);
|
|
203
|
+
}
|
|
204
|
+
const mainColumns = tableHeaderLast.value.slice(virtualScrollX.value.startIndex, virtualScrollX.value.endIndex);
|
|
205
|
+
return leftCols.concat(mainColumns).concat(rightCols);
|
|
206
|
+
}
|
|
207
|
+
return tableHeaderLast.value;
|
|
208
|
+
});
|
|
209
|
+
const virtualX_offsetRight = computed(() => {
|
|
210
|
+
if (!virtualX_on.value)
|
|
211
|
+
return 0;
|
|
212
|
+
let width = 0;
|
|
213
|
+
for (let i = virtualScrollX.value.endIndex; i < tableHeaderLast.value.length; i++) {
|
|
214
|
+
const col = tableHeaderLast.value[i];
|
|
215
|
+
width += parseInt(col.width || col.maxWidth || col.minWidth || Default_Col_Width);
|
|
216
|
+
}
|
|
217
|
+
return width;
|
|
218
|
+
});
|
|
219
|
+
function initVirtualScrollY(height) {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
if (virtual_on.value) {
|
|
222
|
+
virtualScroll.value.containerHeight = typeof height === "number" ? height : ((_a = tableContainer.value) == null ? void 0 : _a.offsetHeight) || Default_Table_Height;
|
|
223
|
+
updateVirtualScrollY((_b = tableContainer.value) == null ? void 0 : _b.scrollTop);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function initVirtualScrollX() {
|
|
227
|
+
if (props.virtualX) {
|
|
228
|
+
const { offsetWidth, scrollLeft } = tableContainer.value || {};
|
|
229
|
+
virtualScrollX.value.containerWidth = offsetWidth || Default_Table_Width;
|
|
230
|
+
updateVirtualScrollX(scrollLeft);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function updateVirtualScrollY(sTop = 0) {
|
|
234
|
+
const { rowHeight } = virtualScroll.value;
|
|
235
|
+
const startIndex = Math.floor(sTop / rowHeight);
|
|
236
|
+
Object.assign(virtualScroll.value, {
|
|
237
|
+
startIndex,
|
|
238
|
+
offsetTop: startIndex * rowHeight
|
|
239
|
+
// startIndex之前的高度
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function updateVirtualScrollX(sLeft = 0) {
|
|
243
|
+
var _a;
|
|
244
|
+
if (!((_a = tableHeaderLast.value) == null ? void 0 : _a.length))
|
|
245
|
+
return;
|
|
246
|
+
let startIndex = 0;
|
|
247
|
+
let offsetLeft = 0;
|
|
248
|
+
let colWidthSum = 0;
|
|
249
|
+
for (let colIndex = 0; colIndex < tableHeaderLast.value.length; colIndex++) {
|
|
250
|
+
startIndex++;
|
|
251
|
+
const col = tableHeaderLast.value[colIndex];
|
|
252
|
+
if (col.fixed === "left")
|
|
253
|
+
continue;
|
|
254
|
+
const colWidth = parseInt(col.width || col.maxWidth || col.minWidth || Default_Col_Width);
|
|
255
|
+
colWidthSum += colWidth;
|
|
256
|
+
if (colWidthSum >= sLeft) {
|
|
257
|
+
offsetLeft = colWidthSum - colWidth;
|
|
258
|
+
startIndex--;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
colWidthSum = 0;
|
|
263
|
+
let endIndex = tableHeaderLast.value.length;
|
|
264
|
+
for (let colIndex = startIndex; colIndex < tableHeaderLast.value.length - 1; colIndex++) {
|
|
265
|
+
const col = tableHeaderLast.value[colIndex];
|
|
266
|
+
colWidthSum += parseInt(col.width || col.maxWidth || col.minWidth || Default_Col_Width);
|
|
267
|
+
if (colWidthSum >= virtualScrollX.value.containerWidth) {
|
|
268
|
+
endIndex = colIndex + 2;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
Object.assign(virtualScrollX.value, { startIndex, endIndex, offsetLeft });
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
virtualScroll,
|
|
276
|
+
virtualScrollX,
|
|
277
|
+
virtual_on,
|
|
278
|
+
virtual_dataSourcePart,
|
|
279
|
+
virtual_offsetBottom,
|
|
280
|
+
virtualX_on,
|
|
281
|
+
virtualX_columnPart,
|
|
282
|
+
virtualX_offsetRight,
|
|
283
|
+
initVirtualScrollY,
|
|
284
|
+
initVirtualScrollX,
|
|
285
|
+
updateVirtualScrollY,
|
|
286
|
+
updateVirtualScrollX
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function insertToOrderedArray(sortState, newItem, targetArray) {
|
|
290
|
+
const { dataIndex, order } = sortState;
|
|
291
|
+
let { sortType } = sortState;
|
|
292
|
+
if (!sortType)
|
|
293
|
+
sortType = typeof newItem[dataIndex];
|
|
294
|
+
const data = [...targetArray];
|
|
295
|
+
if (!order) {
|
|
296
|
+
data.unshift(newItem);
|
|
297
|
+
return data;
|
|
298
|
+
}
|
|
299
|
+
let sIndex = 0;
|
|
300
|
+
let eIndex = data.length - 1;
|
|
301
|
+
const targetVal = newItem[dataIndex];
|
|
302
|
+
while (sIndex <= eIndex) {
|
|
303
|
+
const midIndex = Math.floor((sIndex + eIndex) / 2);
|
|
304
|
+
const midVal = data[midIndex][dataIndex];
|
|
305
|
+
const compareRes = strCompare(midVal, targetVal, sortType);
|
|
306
|
+
if (compareRes === 0) {
|
|
307
|
+
sIndex = midIndex;
|
|
308
|
+
break;
|
|
309
|
+
} else if (compareRes === -1) {
|
|
310
|
+
if (order === "asc")
|
|
311
|
+
sIndex = midIndex + 1;
|
|
312
|
+
else
|
|
313
|
+
eIndex = midIndex - 1;
|
|
314
|
+
} else {
|
|
315
|
+
if (order === "asc")
|
|
316
|
+
eIndex = midIndex - 1;
|
|
317
|
+
else
|
|
318
|
+
sIndex = midIndex + 1;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
data.splice(sIndex, 0, newItem);
|
|
322
|
+
return data;
|
|
323
|
+
}
|
|
324
|
+
function strCompare(a, b, type) {
|
|
325
|
+
if (type === "number") {
|
|
326
|
+
if (+a > +b)
|
|
327
|
+
return 1;
|
|
328
|
+
if (+a === +b)
|
|
329
|
+
return 0;
|
|
330
|
+
if (+a < +b)
|
|
331
|
+
return -1;
|
|
332
|
+
} else {
|
|
333
|
+
return String(a).localeCompare(b);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function tableSort(sortOption, order, dataSource) {
|
|
337
|
+
let targetDataSource = [...dataSource];
|
|
338
|
+
if (typeof sortOption.sorter === "function") {
|
|
339
|
+
const customSorterData = sortOption.sorter(targetDataSource, { order, column: sortOption });
|
|
340
|
+
if (customSorterData)
|
|
341
|
+
targetDataSource = customSorterData;
|
|
342
|
+
} else if (order) {
|
|
343
|
+
const sortField = sortOption.sortField || sortOption.dataIndex;
|
|
344
|
+
let { sortType } = sortOption;
|
|
345
|
+
if (!sortType)
|
|
346
|
+
sortType = typeof dataSource[0][sortField];
|
|
347
|
+
if (sortType === "number") {
|
|
348
|
+
const nanArr = [];
|
|
349
|
+
const numArr = [];
|
|
350
|
+
for (let i = 0; i < targetDataSource.length; i++) {
|
|
351
|
+
const row = targetDataSource[i];
|
|
352
|
+
if (row[sortField] === null || row[sortField] === "" || typeof row[sortField] === "boolean" || Number.isNaN(+row[sortField])) {
|
|
353
|
+
nanArr.push(row);
|
|
354
|
+
} else {
|
|
355
|
+
numArr.push(row);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (order === "asc") {
|
|
359
|
+
numArr.sort((a, b) => +a[sortField] - +b[sortField]);
|
|
360
|
+
targetDataSource = [...nanArr, ...numArr];
|
|
361
|
+
} else {
|
|
362
|
+
numArr.sort((a, b) => +b[sortField] - +a[sortField]);
|
|
363
|
+
targetDataSource = [...numArr, ...nanArr];
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
if (order === "asc") {
|
|
367
|
+
targetDataSource.sort((a, b) => String(a[sortField]).localeCompare(b[sortField]));
|
|
368
|
+
} else {
|
|
369
|
+
targetDataSource.sort((a, b) => String(a[sortField]).localeCompare(b[sortField]) * -1);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return targetDataSource;
|
|
374
|
+
}
|
|
375
|
+
function howDeepTheColumn(arr, level = 1) {
|
|
376
|
+
const levels = [level];
|
|
377
|
+
arr.forEach((item) => {
|
|
378
|
+
var _a;
|
|
379
|
+
if ((_a = item.children) == null ? void 0 : _a.length) {
|
|
380
|
+
levels.push(howDeepTheColumn(item.children, level + 1));
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
return Math.max(...levels);
|
|
384
|
+
}
|
|
385
|
+
const _withScopeId = (n) => (pushScopeId("data-v-12388195"), n = n(), popScopeId(), n);
|
|
386
|
+
const _hoisted_1 = { key: 0 };
|
|
387
|
+
const _hoisted_2 = ["data-col-key", "draggable", "rowspan", "colspan", "title", "onClick"];
|
|
388
|
+
const _hoisted_3 = { class: "table-header-cell-wrapper" };
|
|
389
|
+
const _hoisted_4 = { class: "table-header-title" };
|
|
390
|
+
const _hoisted_5 = {
|
|
391
|
+
key: 2,
|
|
392
|
+
class: "table-header-sorter"
|
|
393
|
+
};
|
|
394
|
+
const _hoisted_6 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("svg", {
|
|
395
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
396
|
+
width: "16px",
|
|
397
|
+
height: "16px",
|
|
398
|
+
viewBox: "0 0 16 16"
|
|
399
|
+
}, [
|
|
400
|
+
/* @__PURE__ */ createElementVNode("g", { id: "sort-btn" }, [
|
|
401
|
+
/* @__PURE__ */ createElementVNode("polygon", {
|
|
402
|
+
id: "arrow-up",
|
|
403
|
+
fill: "#757699",
|
|
404
|
+
points: "8 2 4.8 6 11.2 6"
|
|
405
|
+
}),
|
|
406
|
+
/* @__PURE__ */ createElementVNode("polygon", {
|
|
407
|
+
id: "arrow-down",
|
|
408
|
+
transform: "translate(8, 12) rotate(-180) translate(-8, -12) ",
|
|
409
|
+
points: "8 10 4.8 14 11.2 14"
|
|
410
|
+
})
|
|
411
|
+
])
|
|
412
|
+
], -1));
|
|
413
|
+
const _hoisted_7 = [
|
|
414
|
+
_hoisted_6
|
|
415
|
+
];
|
|
416
|
+
const _hoisted_8 = ["onMousedown"];
|
|
417
|
+
const _hoisted_9 = ["onMousedown"];
|
|
418
|
+
const _hoisted_10 = ["data-row-key", "onClick", "onDblclick", "onContextmenu", "onMouseover"];
|
|
419
|
+
const _hoisted_11 = {
|
|
420
|
+
key: 0,
|
|
421
|
+
class: "virtual-x-left",
|
|
422
|
+
style: { "padding": "0" }
|
|
423
|
+
};
|
|
424
|
+
const _hoisted_12 = ["data-index", "onClick"];
|
|
425
|
+
const _hoisted_13 = ["title"];
|
|
426
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
427
|
+
__name: "StkTable",
|
|
428
|
+
props: {
|
|
429
|
+
width: { default: "" },
|
|
430
|
+
minWidth: { default: "min-content" },
|
|
431
|
+
maxWidth: { default: "" },
|
|
432
|
+
headless: { type: Boolean, default: false },
|
|
433
|
+
theme: { default: "light" },
|
|
434
|
+
virtual: { type: Boolean, default: false },
|
|
435
|
+
virtualX: { type: Boolean, default: false },
|
|
436
|
+
columns: { default: () => [] },
|
|
437
|
+
dataSource: { default: () => [] },
|
|
438
|
+
rowKey: { type: [String, Function], default: "" },
|
|
439
|
+
colKey: { type: [String, Function], default: "dataIndex" },
|
|
440
|
+
emptyCellText: { default: "--" },
|
|
441
|
+
noDataFull: { type: Boolean, default: false },
|
|
442
|
+
showNoData: { type: Boolean, default: true },
|
|
443
|
+
sortRemote: { type: Boolean, default: false },
|
|
444
|
+
showHeaderOverflow: { type: Boolean, default: false },
|
|
445
|
+
showOverflow: { type: Boolean, default: false },
|
|
446
|
+
showTrHoverClass: { type: Boolean, default: false },
|
|
447
|
+
headerDrag: { type: Boolean, default: false },
|
|
448
|
+
rowClassName: { type: Function, default: () => "" },
|
|
449
|
+
colResizable: { type: Boolean, default: false },
|
|
450
|
+
colMinWidth: { default: 10 }
|
|
451
|
+
},
|
|
452
|
+
emits: [
|
|
453
|
+
"sort-change",
|
|
454
|
+
"row-click",
|
|
455
|
+
"current-change",
|
|
456
|
+
"row-dblclick",
|
|
457
|
+
"header-row-menu",
|
|
458
|
+
"row-menu",
|
|
459
|
+
"cell-click",
|
|
460
|
+
"header-cell-click",
|
|
461
|
+
"scroll",
|
|
462
|
+
"col-order-change",
|
|
463
|
+
"th-drop",
|
|
464
|
+
"th-drag-start",
|
|
465
|
+
"columns"
|
|
466
|
+
],
|
|
467
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
468
|
+
const props = __props;
|
|
469
|
+
const emit = __emit;
|
|
470
|
+
const tableContainer = ref();
|
|
471
|
+
const colResizeIndicator = ref();
|
|
472
|
+
const currentItem = ref(null);
|
|
473
|
+
const currentHover = ref(null);
|
|
474
|
+
let sortCol = ref();
|
|
475
|
+
let sortOrderIndex = ref(0);
|
|
476
|
+
const sortSwitchOrder = [null, "desc", "asc"];
|
|
477
|
+
const tableHeaders = ref([]);
|
|
478
|
+
const tableHeaderLast = ref([]);
|
|
479
|
+
const dataSourceCopy = shallowRef([...props.dataSource]);
|
|
480
|
+
let highlightDimRows = /* @__PURE__ */ new Set();
|
|
481
|
+
let highlightDimRowsTimeout = /* @__PURE__ */ new Map();
|
|
482
|
+
let highlightDimCellsTimeout = /* @__PURE__ */ new Map();
|
|
483
|
+
let calcHighlightDimLoop = false;
|
|
484
|
+
const rowKeyGenStore = /* @__PURE__ */ new WeakMap();
|
|
485
|
+
const tableWidth = computed(() => {
|
|
486
|
+
return props.colResizable ? "fit-content" : props.width;
|
|
487
|
+
});
|
|
488
|
+
const highlightInter = computed(() => {
|
|
489
|
+
return interpolateRgb(Highlight_Color[props.theme].from, Highlight_Color[props.theme].to);
|
|
490
|
+
});
|
|
491
|
+
const fixedColumnsPositionStore = computed(() => {
|
|
492
|
+
const store = {};
|
|
493
|
+
const cols = [...tableHeaderLast.value];
|
|
494
|
+
let left = 0;
|
|
495
|
+
for (let i = 0; i < cols.length; i++) {
|
|
496
|
+
const item = cols[i];
|
|
497
|
+
if (item.fixed === "left") {
|
|
498
|
+
store[item.dataIndex] = left;
|
|
499
|
+
left += parseInt(item.width || Default_Col_Width);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
let right = 0;
|
|
503
|
+
for (let i = cols.length - 1; i >= 0; i--) {
|
|
504
|
+
const item = cols[i];
|
|
505
|
+
if (item.fixed === "right") {
|
|
506
|
+
store[item.dataIndex] = right;
|
|
507
|
+
right += parseInt(item.width || Default_Col_Width);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return store;
|
|
511
|
+
});
|
|
512
|
+
watch(
|
|
513
|
+
() => props.columns,
|
|
514
|
+
() => {
|
|
515
|
+
dealColumns();
|
|
516
|
+
initVirtualScrollX();
|
|
517
|
+
}
|
|
518
|
+
);
|
|
519
|
+
dealColumns();
|
|
520
|
+
const { isColResizing, onThResizeMouseDown } = useColResize({
|
|
521
|
+
props,
|
|
522
|
+
emit,
|
|
523
|
+
colKeyGen,
|
|
524
|
+
colResizeIndicator,
|
|
525
|
+
tableContainer,
|
|
526
|
+
tableHeaderLast
|
|
527
|
+
});
|
|
528
|
+
const { onThDragStart, onThDragOver, onThDrop } = useThDrag({ emit });
|
|
529
|
+
const {
|
|
530
|
+
virtualScroll,
|
|
531
|
+
virtualScrollX,
|
|
532
|
+
virtual_on,
|
|
533
|
+
virtual_dataSourcePart,
|
|
534
|
+
virtual_offsetBottom,
|
|
535
|
+
virtualX_on,
|
|
536
|
+
virtualX_columnPart,
|
|
537
|
+
virtualX_offsetRight,
|
|
538
|
+
initVirtualScrollY,
|
|
539
|
+
initVirtualScrollX,
|
|
540
|
+
updateVirtualScrollY,
|
|
541
|
+
updateVirtualScrollX
|
|
542
|
+
} = useVirtualScroll({ tableContainer, props, dataSourceCopy, tableHeaderLast });
|
|
543
|
+
watch(
|
|
544
|
+
() => props.dataSource,
|
|
545
|
+
(val) => {
|
|
546
|
+
let needInitVirtualScrollY = false;
|
|
547
|
+
if (dataSourceCopy.value.length !== val.length) {
|
|
548
|
+
needInitVirtualScrollY = true;
|
|
549
|
+
}
|
|
550
|
+
dataSourceCopy.value = [...val];
|
|
551
|
+
if (needInitVirtualScrollY)
|
|
552
|
+
initVirtualScrollY();
|
|
553
|
+
if (sortCol.value) {
|
|
554
|
+
const column = tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
|
|
555
|
+
onColumnSort(column, false);
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
deep: false
|
|
560
|
+
}
|
|
561
|
+
);
|
|
562
|
+
onMounted(() => {
|
|
563
|
+
initVirtualScroll();
|
|
564
|
+
});
|
|
565
|
+
function initVirtualScroll(height) {
|
|
566
|
+
initVirtualScrollY(height);
|
|
567
|
+
initVirtualScrollX();
|
|
568
|
+
}
|
|
569
|
+
function getFixedStyle(tagType, col) {
|
|
570
|
+
const style = {};
|
|
571
|
+
if (Is_Legacy_Mode) {
|
|
572
|
+
if (tagType === 1) {
|
|
573
|
+
style.position = "relative";
|
|
574
|
+
style.top = virtualScroll.value.scrollTop + "px";
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const { fixed, dataIndex } = col;
|
|
578
|
+
if (fixed === "left" || fixed === "right") {
|
|
579
|
+
const isFixedLeft = fixed === "left";
|
|
580
|
+
if (Is_Legacy_Mode) {
|
|
581
|
+
style.position = "relative";
|
|
582
|
+
if (isFixedLeft) {
|
|
583
|
+
if (virtualX_on.value)
|
|
584
|
+
style.left = virtualScrollX.value.scrollLeft - virtualScrollX.value.offsetLeft + "px";
|
|
585
|
+
else
|
|
586
|
+
style.left = virtualScrollX.value.scrollLeft + "px";
|
|
587
|
+
} else {
|
|
588
|
+
style.right = `${virtualX_offsetRight.value}px`;
|
|
589
|
+
}
|
|
590
|
+
if (tagType === 1) {
|
|
591
|
+
style.top = virtualScroll.value.scrollTop + "px";
|
|
592
|
+
style.zIndex = isFixedLeft ? "4" : "3";
|
|
593
|
+
} else {
|
|
594
|
+
style.zIndex = isFixedLeft ? "3" : "2";
|
|
595
|
+
}
|
|
596
|
+
} else {
|
|
597
|
+
style.position = "sticky";
|
|
598
|
+
if (isFixedLeft) {
|
|
599
|
+
style.left = fixedColumnsPositionStore.value[dataIndex] + "px";
|
|
600
|
+
} else {
|
|
601
|
+
style.right = fixedColumnsPositionStore.value[dataIndex] + "px";
|
|
602
|
+
}
|
|
603
|
+
if (tagType === 1) {
|
|
604
|
+
style.top = "0";
|
|
605
|
+
style.zIndex = isFixedLeft ? "4" : "3";
|
|
606
|
+
} else {
|
|
607
|
+
style.zIndex = isFixedLeft ? "3" : "2";
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return style;
|
|
612
|
+
}
|
|
613
|
+
function dealColumns() {
|
|
614
|
+
tableHeaders.value = [];
|
|
615
|
+
tableHeaderLast.value = [];
|
|
616
|
+
const copyColumn = props.columns;
|
|
617
|
+
const deep = howDeepTheColumn(copyColumn);
|
|
618
|
+
const tmpHeaderRows = [];
|
|
619
|
+
const tmpHeaderLast = [];
|
|
620
|
+
(function flat(arr, level = 0) {
|
|
621
|
+
const colArr = [];
|
|
622
|
+
const childrenArr = [];
|
|
623
|
+
arr.forEach((col) => {
|
|
624
|
+
var _a;
|
|
625
|
+
col.rowSpan = col.children ? 1 : deep - level;
|
|
626
|
+
col.colSpan = (_a = col.children) == null ? void 0 : _a.length;
|
|
627
|
+
if (col.rowSpan === 1)
|
|
628
|
+
delete col.rowSpan;
|
|
629
|
+
if (col.colSpan === 1)
|
|
630
|
+
delete col.colSpan;
|
|
631
|
+
colArr.push(col);
|
|
632
|
+
if (col.children) {
|
|
633
|
+
childrenArr.push(...col.children);
|
|
634
|
+
} else {
|
|
635
|
+
tmpHeaderLast.push(col);
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
tmpHeaderRows.push(colArr);
|
|
639
|
+
if (childrenArr.length)
|
|
640
|
+
flat(childrenArr, level + 1);
|
|
641
|
+
})(copyColumn);
|
|
642
|
+
tableHeaders.value = tmpHeaderRows;
|
|
643
|
+
tableHeaderLast.value = tmpHeaderLast;
|
|
644
|
+
}
|
|
645
|
+
function rowKeyGen(row) {
|
|
646
|
+
let key = rowKeyGenStore.get(row);
|
|
647
|
+
if (!key) {
|
|
648
|
+
key = typeof props.rowKey === "function" ? props.rowKey(row) : row[props.rowKey];
|
|
649
|
+
rowKeyGenStore.set(row, key);
|
|
650
|
+
}
|
|
651
|
+
return key;
|
|
652
|
+
}
|
|
653
|
+
function colKeyGen(col) {
|
|
654
|
+
return typeof props.colKey === "function" ? props.colKey(col) : col[props.colKey];
|
|
655
|
+
}
|
|
656
|
+
function getCellStyle(tagType, col) {
|
|
657
|
+
const fixedStyle = getFixedStyle(tagType, col);
|
|
658
|
+
const style = {
|
|
659
|
+
width: col.width,
|
|
660
|
+
minWidth: props.colResizable ? col.width : col.minWidth || col.width,
|
|
661
|
+
maxWidth: props.colResizable ? col.width : col.maxWidth || col.width,
|
|
662
|
+
...fixedStyle
|
|
663
|
+
};
|
|
664
|
+
if (tagType === 1) {
|
|
665
|
+
style.textAlign = col.headerAlign;
|
|
666
|
+
} else if (tagType === 2) {
|
|
667
|
+
style.textAlign = col.align;
|
|
668
|
+
}
|
|
669
|
+
return style;
|
|
670
|
+
}
|
|
671
|
+
function onColumnSort(col, click = true, options = {}) {
|
|
672
|
+
if (!(col == null ? void 0 : col.sorter))
|
|
673
|
+
return;
|
|
674
|
+
options = { force: false, emit: false, ...options };
|
|
675
|
+
if (sortCol.value !== col.dataIndex) {
|
|
676
|
+
sortCol.value = col.dataIndex;
|
|
677
|
+
sortOrderIndex.value = 0;
|
|
678
|
+
}
|
|
679
|
+
if (click)
|
|
680
|
+
sortOrderIndex.value++;
|
|
681
|
+
sortOrderIndex.value = sortOrderIndex.value % 3;
|
|
682
|
+
const order = sortSwitchOrder[sortOrderIndex.value];
|
|
683
|
+
if (!props.sortRemote || options.force) {
|
|
684
|
+
dataSourceCopy.value = tableSort(col, order, props.dataSource);
|
|
685
|
+
}
|
|
686
|
+
if (click || options.emit) {
|
|
687
|
+
emit("sort-change", col, order, toRaw(dataSourceCopy.value));
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
function onRowClick(e, row) {
|
|
691
|
+
emit("row-click", e, row);
|
|
692
|
+
if (currentItem.value === row)
|
|
693
|
+
return;
|
|
694
|
+
currentItem.value = row;
|
|
695
|
+
emit("current-change", e, row);
|
|
696
|
+
}
|
|
697
|
+
function onRowDblclick(e, row) {
|
|
698
|
+
emit("row-dblclick", e, row);
|
|
699
|
+
}
|
|
700
|
+
function onHeaderMenu(e) {
|
|
701
|
+
emit("header-row-menu", e);
|
|
702
|
+
}
|
|
703
|
+
function onRowMenu(e, row) {
|
|
704
|
+
emit("row-menu", e, row);
|
|
705
|
+
}
|
|
706
|
+
function onCellClick(e, row, col) {
|
|
707
|
+
emit("cell-click", e, row, col);
|
|
708
|
+
}
|
|
709
|
+
function onHeaderCellClick(e, col) {
|
|
710
|
+
emit("header-cell-click", e, col);
|
|
711
|
+
}
|
|
712
|
+
function onTableWheel(e) {
|
|
713
|
+
if (isColResizing.value) {
|
|
714
|
+
e.preventDefault();
|
|
715
|
+
e.stopPropagation();
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
function onTableScroll(e) {
|
|
720
|
+
if (!(e == null ? void 0 : e.target))
|
|
721
|
+
return;
|
|
722
|
+
const { scrollTop, scrollLeft } = e.target;
|
|
723
|
+
if (scrollTop !== virtualScroll.value.scrollTop)
|
|
724
|
+
virtualScroll.value.scrollTop = scrollTop;
|
|
725
|
+
if (virtual_on.value) {
|
|
726
|
+
updateVirtualScrollY(scrollTop);
|
|
727
|
+
}
|
|
728
|
+
if (scrollLeft !== virtualScrollX.value.scrollLeft)
|
|
729
|
+
virtualScrollX.value.scrollLeft = scrollLeft;
|
|
730
|
+
if (virtualX_on.value) {
|
|
731
|
+
updateVirtualScrollX(scrollLeft);
|
|
732
|
+
}
|
|
733
|
+
emit("scroll", e);
|
|
734
|
+
}
|
|
735
|
+
function onTrMouseOver(e, row) {
|
|
736
|
+
if (props.showTrHoverClass) {
|
|
737
|
+
currentHover.value = rowKeyGen(row);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
function calcHighlightLoop() {
|
|
741
|
+
if (calcHighlightDimLoop)
|
|
742
|
+
return;
|
|
743
|
+
calcHighlightDimLoop = true;
|
|
744
|
+
const recursion = () => {
|
|
745
|
+
window.setTimeout(() => {
|
|
746
|
+
const highlightRows = [...highlightDimRows];
|
|
747
|
+
const nowTs = Date.now();
|
|
748
|
+
for (let i = 0; i < highlightRows.length; i++) {
|
|
749
|
+
const row = highlightRows[i];
|
|
750
|
+
const progress = (nowTs - row._bgc_progress_ms) / Highlight_Duration;
|
|
751
|
+
if (progress <= 1) {
|
|
752
|
+
row._bgc = highlightInter.value(progress);
|
|
753
|
+
} else {
|
|
754
|
+
row._bgc = "";
|
|
755
|
+
highlightRows.splice(i--, 1);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
highlightDimRows = new Set(highlightRows);
|
|
759
|
+
if (highlightDimRows.size > 0) {
|
|
760
|
+
recursion();
|
|
761
|
+
} else {
|
|
762
|
+
calcHighlightDimLoop = false;
|
|
763
|
+
}
|
|
764
|
+
}, Highlight_Color_Change_Freq);
|
|
765
|
+
};
|
|
766
|
+
recursion();
|
|
767
|
+
}
|
|
768
|
+
function setCurrentRow(rowKey, option = { silent: false }) {
|
|
769
|
+
if (!dataSourceCopy.value.length)
|
|
770
|
+
return;
|
|
771
|
+
currentItem.value = dataSourceCopy.value.find((it) => rowKeyGen(it) === rowKey);
|
|
772
|
+
if (!option.silent) {
|
|
773
|
+
emit("current-change", null, currentItem.value);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function setHighlightDimCell(rowKeyValue, dataIndex) {
|
|
777
|
+
var _a;
|
|
778
|
+
const cellEl = (_a = tableContainer.value) == null ? void 0 : _a.querySelector(
|
|
779
|
+
`[data-row-key="${rowKeyValue}"]>[data-index="${dataIndex}"]`
|
|
780
|
+
);
|
|
781
|
+
if (!cellEl)
|
|
782
|
+
return;
|
|
783
|
+
if (cellEl.classList.contains("highlight-cell")) {
|
|
784
|
+
cellEl.classList.remove("highlight-cell");
|
|
785
|
+
void cellEl.offsetHeight;
|
|
786
|
+
}
|
|
787
|
+
cellEl.classList.add("highlight-cell");
|
|
788
|
+
window.clearTimeout(highlightDimCellsTimeout.get(rowKeyValue));
|
|
789
|
+
highlightDimCellsTimeout.set(
|
|
790
|
+
rowKeyValue,
|
|
791
|
+
window.setTimeout(() => {
|
|
792
|
+
cellEl.classList.remove("highlight-cell");
|
|
793
|
+
highlightDimCellsTimeout.delete(rowKeyValue);
|
|
794
|
+
}, Highlight_Duration)
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
function setHighlightDimRow(rowKeyValues) {
|
|
798
|
+
var _a, _b;
|
|
799
|
+
if (!Array.isArray(rowKeyValues))
|
|
800
|
+
rowKeyValues = [rowKeyValues];
|
|
801
|
+
if (props.virtual) {
|
|
802
|
+
const nowTs = Date.now();
|
|
803
|
+
for (let i = 0; i < rowKeyValues.length; i++) {
|
|
804
|
+
const rowKeyValue = rowKeyValues[i];
|
|
805
|
+
const row = props.dataSource.find((it) => rowKeyGen(it) === rowKeyValue);
|
|
806
|
+
if (!row)
|
|
807
|
+
continue;
|
|
808
|
+
row._bgc_progress_ms = nowTs;
|
|
809
|
+
highlightDimRows.add(row);
|
|
810
|
+
}
|
|
811
|
+
calcHighlightLoop();
|
|
812
|
+
} else {
|
|
813
|
+
let needRepaint = false;
|
|
814
|
+
const rowElTemp = [];
|
|
815
|
+
for (let i = 0; i < rowKeyValues.length; i++) {
|
|
816
|
+
const rowKeyValue = rowKeyValues[i];
|
|
817
|
+
const rowEl = (_a = tableContainer.value) == null ? void 0 : _a.querySelector(`[data-row-key="${rowKeyValue}"]`);
|
|
818
|
+
if (!rowEl)
|
|
819
|
+
continue;
|
|
820
|
+
if (rowEl.classList.contains("highlight-row")) {
|
|
821
|
+
rowEl.classList.remove("highlight-row");
|
|
822
|
+
needRepaint = true;
|
|
823
|
+
}
|
|
824
|
+
rowElTemp.push(rowEl);
|
|
825
|
+
window.clearTimeout(highlightDimRowsTimeout.get(rowKeyValue));
|
|
826
|
+
highlightDimRowsTimeout.set(
|
|
827
|
+
rowKeyValue,
|
|
828
|
+
window.setTimeout(() => {
|
|
829
|
+
rowEl.classList.remove("highlight-row");
|
|
830
|
+
highlightDimRowsTimeout.delete(rowKeyValue);
|
|
831
|
+
}, Highlight_Duration)
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
if (needRepaint) {
|
|
835
|
+
void ((_b = tableContainer.value) == null ? void 0 : _b.offsetWidth);
|
|
836
|
+
}
|
|
837
|
+
rowElTemp.forEach((el) => el.classList.add("highlight-row"));
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
function setSorter(dataIndex, order, option = {}) {
|
|
841
|
+
var _a;
|
|
842
|
+
const newOption = { silent: true, sortOption: null, sort: true, ...option };
|
|
843
|
+
sortCol.value = dataIndex;
|
|
844
|
+
sortOrderIndex.value = sortSwitchOrder.findIndex((it) => it === order);
|
|
845
|
+
if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
|
|
846
|
+
const column = newOption.sortOption || tableHeaderLast.value.find((it) => it.dataIndex === sortCol.value);
|
|
847
|
+
if (column)
|
|
848
|
+
onColumnSort(column, false, { force: true, emit: !newOption.silent });
|
|
849
|
+
else
|
|
850
|
+
console.warn("Can not find column by dataIndex:", sortCol.value);
|
|
851
|
+
}
|
|
852
|
+
return dataSourceCopy.value;
|
|
853
|
+
}
|
|
854
|
+
function resetSorter() {
|
|
855
|
+
sortCol.value = null;
|
|
856
|
+
sortOrderIndex.value = 0;
|
|
857
|
+
dataSourceCopy.value = [...props.dataSource];
|
|
858
|
+
}
|
|
859
|
+
function scrollTo(top = 0, left = 0) {
|
|
860
|
+
if (!tableContainer.value)
|
|
861
|
+
return;
|
|
862
|
+
if (top !== null)
|
|
863
|
+
tableContainer.value.scrollTop = top;
|
|
864
|
+
if (left !== null)
|
|
865
|
+
tableContainer.value.scrollLeft = left;
|
|
866
|
+
}
|
|
867
|
+
function getTableData() {
|
|
868
|
+
return toRaw(dataSourceCopy.value);
|
|
869
|
+
}
|
|
870
|
+
__expose({
|
|
871
|
+
setCurrentRow,
|
|
872
|
+
setHighlightDimCell,
|
|
873
|
+
setHighlightDimRow,
|
|
874
|
+
setSorter,
|
|
875
|
+
resetSorter,
|
|
876
|
+
scrollTo,
|
|
877
|
+
getTableData
|
|
878
|
+
});
|
|
879
|
+
return (_ctx, _cache) => {
|
|
880
|
+
return openBlock(), createElementBlock("div", {
|
|
881
|
+
ref_key: "tableContainer",
|
|
882
|
+
ref: tableContainer,
|
|
883
|
+
class: normalizeClass(["stk-table", {
|
|
884
|
+
virtual: _ctx.virtual,
|
|
885
|
+
"virtual-x": _ctx.virtualX,
|
|
886
|
+
dark: _ctx.theme === "dark",
|
|
887
|
+
headless: _ctx.headless,
|
|
888
|
+
"is-col-resizing": unref(isColResizing)
|
|
889
|
+
}]),
|
|
890
|
+
style: normalizeStyle(_ctx.virtual && { "--row-height": unref(virtualScroll).rowHeight + "px" }),
|
|
891
|
+
onScroll: onTableScroll,
|
|
892
|
+
onWheel: onTableWheel
|
|
893
|
+
}, [
|
|
894
|
+
withDirectives(createElementVNode("div", {
|
|
895
|
+
ref_key: "colResizeIndicator",
|
|
896
|
+
ref: colResizeIndicator,
|
|
897
|
+
class: "column-resize-indicator"
|
|
898
|
+
}, null, 512), [
|
|
899
|
+
[vShow, _ctx.colResizable]
|
|
900
|
+
]),
|
|
901
|
+
createElementVNode("table", {
|
|
902
|
+
class: "stk-table-main",
|
|
903
|
+
style: normalizeStyle({ width: tableWidth.value, minWidth: _ctx.minWidth, maxWidth: _ctx.maxWidth })
|
|
904
|
+
}, [
|
|
905
|
+
!_ctx.headless ? (openBlock(), createElementBlock("thead", _hoisted_1, [
|
|
906
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(tableHeaders.value, (row, rowIndex) => {
|
|
907
|
+
return openBlock(), createElementBlock("tr", {
|
|
908
|
+
key: rowIndex,
|
|
909
|
+
onContextmenu: _cache[3] || (_cache[3] = (e) => onHeaderMenu(e))
|
|
910
|
+
}, [
|
|
911
|
+
unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
|
|
912
|
+
key: 0,
|
|
913
|
+
class: "virtual-x-left",
|
|
914
|
+
style: normalizeStyle({
|
|
915
|
+
minWidth: unref(virtualScrollX).offsetLeft + "px",
|
|
916
|
+
width: unref(virtualScrollX).offsetLeft + "px"
|
|
917
|
+
})
|
|
918
|
+
}, null, 4)) : createCommentVNode("", true),
|
|
919
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_on) && rowIndex === tableHeaders.value.length - 1 ? unref(virtualX_columnPart) : row, (col, colIndex) => {
|
|
920
|
+
return openBlock(), createElementBlock("th", {
|
|
921
|
+
key: col.dataIndex,
|
|
922
|
+
"data-col-key": col.dataIndex,
|
|
923
|
+
draggable: _ctx.headerDrag ? "true" : "false",
|
|
924
|
+
rowspan: col.rowSpan,
|
|
925
|
+
colspan: col.colSpan,
|
|
926
|
+
style: normalizeStyle(getCellStyle(1, col)),
|
|
927
|
+
title: col.title,
|
|
928
|
+
class: normalizeClass([
|
|
929
|
+
col.sorter ? "sortable" : "",
|
|
930
|
+
col.dataIndex === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
|
|
931
|
+
_ctx.showHeaderOverflow ? "text-overflow" : "",
|
|
932
|
+
col.headerClassName,
|
|
933
|
+
col.fixed ? "fixed-cell" : ""
|
|
934
|
+
]),
|
|
935
|
+
onClick: (e) => {
|
|
936
|
+
onColumnSort(col);
|
|
937
|
+
onHeaderCellClick(e, col);
|
|
938
|
+
},
|
|
939
|
+
onDragstart: _cache[0] || (_cache[0] = //@ts-ignore
|
|
940
|
+
(...args) => unref(onThDragStart) && unref(onThDragStart)(...args)),
|
|
941
|
+
onDrop: _cache[1] || (_cache[1] = //@ts-ignore
|
|
942
|
+
(...args) => unref(onThDrop) && unref(onThDrop)(...args)),
|
|
943
|
+
onDragover: _cache[2] || (_cache[2] = //@ts-ignore
|
|
944
|
+
(...args) => unref(onThDragOver) && unref(onThDragOver)(...args))
|
|
945
|
+
}, [
|
|
946
|
+
createElementVNode("div", _hoisted_3, [
|
|
947
|
+
col.customHeaderCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customHeaderCell), {
|
|
948
|
+
key: 0,
|
|
949
|
+
col
|
|
950
|
+
}, null, 8, ["col"])) : renderSlot(_ctx.$slots, "tableHeader", {
|
|
951
|
+
key: 1,
|
|
952
|
+
column: col
|
|
953
|
+
}, () => [
|
|
954
|
+
createElementVNode("span", _hoisted_4, toDisplayString(col.title), 1)
|
|
955
|
+
], true),
|
|
956
|
+
col.sorter ? (openBlock(), createElementBlock("span", _hoisted_5, _hoisted_7)) : createCommentVNode("", true),
|
|
957
|
+
_ctx.colResizable && colIndex > 0 ? (openBlock(), createElementBlock("div", {
|
|
958
|
+
key: 3,
|
|
959
|
+
class: "table-header-resizer left",
|
|
960
|
+
onMousedown: (e) => unref(onThResizeMouseDown)(e, col, true)
|
|
961
|
+
}, null, 40, _hoisted_8)) : createCommentVNode("", true),
|
|
962
|
+
_ctx.colResizable ? (openBlock(), createElementBlock("div", {
|
|
963
|
+
key: 4,
|
|
964
|
+
class: "table-header-resizer right",
|
|
965
|
+
onMousedown: (e) => unref(onThResizeMouseDown)(e, col)
|
|
966
|
+
}, null, 40, _hoisted_9)) : createCommentVNode("", true)
|
|
967
|
+
])
|
|
968
|
+
], 46, _hoisted_2);
|
|
969
|
+
}), 128)),
|
|
970
|
+
unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
|
|
971
|
+
key: 1,
|
|
972
|
+
style: normalizeStyle([{ "padding": "0" }, {
|
|
973
|
+
minWidth: unref(virtualX_offsetRight) + "px",
|
|
974
|
+
width: unref(virtualX_offsetRight) + "px"
|
|
975
|
+
}])
|
|
976
|
+
}, null, 4)) : createCommentVNode("", true)
|
|
977
|
+
], 32);
|
|
978
|
+
}), 128))
|
|
979
|
+
])) : createCommentVNode("", true),
|
|
980
|
+
createElementVNode("tbody", null, [
|
|
981
|
+
unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
|
|
982
|
+
key: 0,
|
|
983
|
+
style: normalizeStyle({ height: `${unref(virtualScroll).offsetTop}px` })
|
|
984
|
+
}, null, 4)) : createCommentVNode("", true),
|
|
985
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, i) => {
|
|
986
|
+
return openBlock(), createElementBlock("tr", {
|
|
987
|
+
key: _ctx.rowKey ? rowKeyGen(row) : i,
|
|
988
|
+
"data-row-key": _ctx.rowKey ? rowKeyGen(row) : i,
|
|
989
|
+
class: normalizeClass({
|
|
990
|
+
active: _ctx.rowKey ? rowKeyGen(row) === (currentItem.value && rowKeyGen(currentItem.value)) : row === currentItem.value,
|
|
991
|
+
hover: _ctx.rowKey ? rowKeyGen(row) === currentHover.value : row === currentHover.value,
|
|
992
|
+
[_ctx.rowClassName(row, i)]: true
|
|
993
|
+
}),
|
|
994
|
+
style: normalizeStyle({
|
|
995
|
+
backgroundColor: row._bgc
|
|
996
|
+
}),
|
|
997
|
+
onClick: (e) => onRowClick(e, row),
|
|
998
|
+
onDblclick: (e) => onRowDblclick(e, row),
|
|
999
|
+
onContextmenu: (e) => onRowMenu(e, row),
|
|
1000
|
+
onMouseover: (e) => onTrMouseOver(e, row)
|
|
1001
|
+
}, [
|
|
1002
|
+
unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_11)) : createCommentVNode("", true),
|
|
1003
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_columnPart), (col) => {
|
|
1004
|
+
return openBlock(), createElementBlock("td", {
|
|
1005
|
+
key: col.dataIndex,
|
|
1006
|
+
"data-index": col.dataIndex,
|
|
1007
|
+
class: normalizeClass([col.className, _ctx.showOverflow ? "text-overflow" : "", col.fixed ? "fixed-cell" : ""]),
|
|
1008
|
+
style: normalizeStyle(getCellStyle(2, col)),
|
|
1009
|
+
onClick: (e) => onCellClick(e, row, col)
|
|
1010
|
+
}, [
|
|
1011
|
+
col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
|
|
1012
|
+
key: 0,
|
|
1013
|
+
col,
|
|
1014
|
+
row
|
|
1015
|
+
}, null, 8, ["col", "row"])) : (openBlock(), createElementBlock("div", {
|
|
1016
|
+
key: 1,
|
|
1017
|
+
class: "table-cell-wrapper",
|
|
1018
|
+
title: row[col.dataIndex]
|
|
1019
|
+
}, toDisplayString(row[col.dataIndex] ?? _ctx.emptyCellText), 9, _hoisted_13))
|
|
1020
|
+
], 14, _hoisted_12);
|
|
1021
|
+
}), 128))
|
|
1022
|
+
], 46, _hoisted_10);
|
|
1023
|
+
}), 128)),
|
|
1024
|
+
unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
|
|
1025
|
+
key: 1,
|
|
1026
|
+
style: normalizeStyle({ height: `${unref(virtual_offsetBottom)}px` })
|
|
1027
|
+
}, null, 4)) : createCommentVNode("", true)
|
|
1028
|
+
])
|
|
1029
|
+
], 4),
|
|
1030
|
+
(!dataSourceCopy.value || !dataSourceCopy.value.length) && _ctx.showNoData ? (openBlock(), createElementBlock("div", {
|
|
1031
|
+
key: 0,
|
|
1032
|
+
class: normalizeClass(["stk-table-no-data", { "no-data-full": _ctx.noDataFull }])
|
|
1033
|
+
}, [
|
|
1034
|
+
renderSlot(_ctx.$slots, "empty", {}, () => [
|
|
1035
|
+
createTextVNode("暂无数据")
|
|
1036
|
+
], true)
|
|
1037
|
+
], 2)) : createCommentVNode("", true)
|
|
1038
|
+
], 38);
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
const _export_sfc = (sfc, props) => {
|
|
1043
|
+
const target = sfc.__vccOpts || sfc;
|
|
1044
|
+
for (const [key, val] of props) {
|
|
1045
|
+
target[key] = val;
|
|
1046
|
+
}
|
|
1047
|
+
return target;
|
|
1048
|
+
};
|
|
1049
|
+
const StkTable = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-12388195"]]);
|
|
1050
|
+
export {
|
|
1051
|
+
StkTable,
|
|
1052
|
+
insertToOrderedArray,
|
|
1053
|
+
tableSort
|
|
1054
|
+
};
|