stk-table-vue 0.8.10 → 0.8.12
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/lib/src/StkTable/StkTable.vue.d.ts +11 -11
- package/lib/src/StkTable/types/index.d.ts +8 -5
- package/lib/src/StkTable/useVirtualScroll.d.ts +6 -6
- package/lib/stk-table-vue.js +126 -142
- package/lib/style.css +3 -0
- package/package.json +5 -5
- package/src/StkTable/StkTable.vue +98 -117
- package/src/StkTable/style.less +6 -0
- package/src/StkTable/types/index.ts +8 -5
- package/src/StkTable/useRowExpand.ts +7 -7
- package/src/StkTable/useTree.ts +34 -27
- package/src/StkTable/useVirtualScroll.ts +11 -11
|
@@ -56,11 +56,11 @@ declare function getSortColumns(): {
|
|
|
56
56
|
}[];
|
|
57
57
|
declare function __VLS_template(): {
|
|
58
58
|
tableHeader?(_: {
|
|
59
|
-
col: PrivateStkTableColumn<
|
|
59
|
+
col: PrivateStkTableColumn<PrivateRowDT>;
|
|
60
60
|
}): any;
|
|
61
61
|
expand?(_: {
|
|
62
62
|
row: any;
|
|
63
|
-
col: any;
|
|
63
|
+
col: StkTableColumn<any> | undefined;
|
|
64
64
|
}): any;
|
|
65
65
|
empty?(_: {}): any;
|
|
66
66
|
customBottom?(_: {}): any;
|
|
@@ -135,7 +135,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
135
135
|
/** 单元格再次点击否可以取消选中 (cellActive=true)*/
|
|
136
136
|
selectedCellRevokable?: boolean;
|
|
137
137
|
/** 表头是否可拖动。支持回调函数。 */
|
|
138
|
-
headerDrag?: boolean | HeaderDragConfig
|
|
138
|
+
headerDrag?: boolean | HeaderDragConfig<DT>;
|
|
139
139
|
/**
|
|
140
140
|
* 给行附加className<br>
|
|
141
141
|
* FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
|
|
@@ -212,7 +212,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
212
212
|
headless: boolean;
|
|
213
213
|
theme: string;
|
|
214
214
|
rowHeight: number;
|
|
215
|
-
autoRowHeight:
|
|
215
|
+
autoRowHeight: () => false;
|
|
216
216
|
rowHover: boolean;
|
|
217
217
|
rowActive: () => Required<RowActiveOption<any>>;
|
|
218
218
|
rowCurrentRevokable: boolean;
|
|
@@ -233,9 +233,9 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
233
233
|
cellHover: boolean;
|
|
234
234
|
cellActive: boolean;
|
|
235
235
|
selectedCellRevokable: boolean;
|
|
236
|
-
headerDrag:
|
|
236
|
+
headerDrag: () => false;
|
|
237
237
|
rowClassName: () => "";
|
|
238
|
-
colResizable:
|
|
238
|
+
colResizable: () => false;
|
|
239
239
|
colMinWidth: number;
|
|
240
240
|
bordered: boolean;
|
|
241
241
|
autoResize: boolean;
|
|
@@ -504,7 +504,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
504
504
|
/** 单元格再次点击否可以取消选中 (cellActive=true)*/
|
|
505
505
|
selectedCellRevokable?: boolean;
|
|
506
506
|
/** 表头是否可拖动。支持回调函数。 */
|
|
507
|
-
headerDrag?: boolean | HeaderDragConfig
|
|
507
|
+
headerDrag?: boolean | HeaderDragConfig<DT>;
|
|
508
508
|
/**
|
|
509
509
|
* 给行附加className<br>
|
|
510
510
|
* FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
|
|
@@ -581,7 +581,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
581
581
|
headless: boolean;
|
|
582
582
|
theme: string;
|
|
583
583
|
rowHeight: number;
|
|
584
|
-
autoRowHeight:
|
|
584
|
+
autoRowHeight: () => false;
|
|
585
585
|
rowHover: boolean;
|
|
586
586
|
rowActive: () => Required<RowActiveOption<any>>;
|
|
587
587
|
rowCurrentRevokable: boolean;
|
|
@@ -602,9 +602,9 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
602
602
|
cellHover: boolean;
|
|
603
603
|
cellActive: boolean;
|
|
604
604
|
selectedCellRevokable: boolean;
|
|
605
|
-
headerDrag:
|
|
605
|
+
headerDrag: () => false;
|
|
606
606
|
rowClassName: () => "";
|
|
607
|
-
colResizable:
|
|
607
|
+
colResizable: () => false;
|
|
608
608
|
colMinWidth: number;
|
|
609
609
|
bordered: boolean;
|
|
610
610
|
autoResize: boolean;
|
|
@@ -710,7 +710,7 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
710
710
|
cellHover: boolean;
|
|
711
711
|
cellActive: boolean;
|
|
712
712
|
selectedCellRevokable: boolean;
|
|
713
|
-
headerDrag: boolean | HeaderDragConfig
|
|
713
|
+
headerDrag: boolean | HeaderDragConfig<DT>;
|
|
714
714
|
rowClassName: (row: DT, i: number) => string | undefined;
|
|
715
715
|
colResizable: boolean | ColResizableConfig<DT>;
|
|
716
716
|
colMinWidth: number;
|
|
@@ -19,6 +19,8 @@ export type CustomCellProps<T extends Record<string, any>> = {
|
|
|
19
19
|
* - 展开: 返回column配置
|
|
20
20
|
*/
|
|
21
21
|
expanded?: PrivateRowDT['__EXP__'];
|
|
22
|
+
/** if tree expanded */
|
|
23
|
+
treeExpanded?: PrivateRowDT['__T_EXP__'];
|
|
22
24
|
};
|
|
23
25
|
export type CustomHeaderCellProps<T extends Record<string, any>> = {
|
|
24
26
|
col: StkTableColumn<T>;
|
|
@@ -142,7 +144,7 @@ export type PrivateRowDT = {
|
|
|
142
144
|
* if row expanded
|
|
143
145
|
* @private
|
|
144
146
|
*/
|
|
145
|
-
__EXP__?: StkTableColumn<any
|
|
147
|
+
__EXP__?: StkTableColumn<any>;
|
|
146
148
|
/**
|
|
147
149
|
* if tree node row expanded
|
|
148
150
|
* @private
|
|
@@ -158,6 +160,11 @@ export type PrivateRowDT = {
|
|
|
158
160
|
* @private
|
|
159
161
|
*/
|
|
160
162
|
__T_LV__?: number;
|
|
163
|
+
/** expanded row */
|
|
164
|
+
__EXP_R__?: any;
|
|
165
|
+
/** expanded col */
|
|
166
|
+
__EXP_C__?: StkTableColumn<any>;
|
|
167
|
+
children?: any[];
|
|
161
168
|
};
|
|
162
169
|
export type SortOption<T extends Record<string, any>> = Pick<StkTableColumn<T>, 'sorter' | 'dataIndex' | 'sortField' | 'sortType'>;
|
|
163
170
|
export type SortState<T extends Record<string, any>> = Pick<StkTableColumn<T>, 'dataIndex' | 'sortField' | 'sortType'> & {
|
|
@@ -225,10 +232,6 @@ export type ExpandConfig = {
|
|
|
225
232
|
/** worked in virtual mode */
|
|
226
233
|
height?: number;
|
|
227
234
|
};
|
|
228
|
-
export type ExpandedRow = PrivateRowDT & {
|
|
229
|
-
__EXPANDED_ROW__: any;
|
|
230
|
-
__EXPANDED_COL__: any;
|
|
231
|
-
};
|
|
232
235
|
/** drag row config */
|
|
233
236
|
export type DragRowConfig = {
|
|
234
237
|
mode?: 'none' | 'insert' | 'swap';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Ref, ShallowRef } from 'vue';
|
|
2
|
-
import { PrivateStkTableColumn, RowKeyGen, UniqKey } from './types';
|
|
2
|
+
import { PrivateRowDT, PrivateStkTableColumn, RowKeyGen, UniqKey } from './types';
|
|
3
3
|
|
|
4
4
|
type Option<DT extends Record<string, any>> = {
|
|
5
5
|
props: any;
|
|
6
6
|
tableContainerRef: Ref<HTMLElement | undefined>;
|
|
7
7
|
trRef: Ref<HTMLTableRowElement[] | undefined>;
|
|
8
|
-
dataSourceCopy: ShallowRef<
|
|
9
|
-
tableHeaderLast: ShallowRef<PrivateStkTableColumn<
|
|
10
|
-
tableHeaders: ShallowRef<PrivateStkTableColumn<
|
|
8
|
+
dataSourceCopy: ShallowRef<PrivateRowDT[]>;
|
|
9
|
+
tableHeaderLast: ShallowRef<PrivateStkTableColumn<PrivateRowDT>[]>;
|
|
10
|
+
tableHeaders: ShallowRef<PrivateStkTableColumn<PrivateRowDT>[][]>;
|
|
11
11
|
rowKeyGen: RowKeyGen;
|
|
12
12
|
maxRowSpan: Map<UniqKey, number>;
|
|
13
13
|
};
|
|
@@ -86,10 +86,10 @@ export declare function useVirtualScroll<DT extends Record<string, any>>({ props
|
|
|
86
86
|
scrollLeft: number;
|
|
87
87
|
}>;
|
|
88
88
|
virtual_on: import('vue').ComputedRef<any>;
|
|
89
|
-
virtual_dataSourcePart: import('vue').ComputedRef<
|
|
89
|
+
virtual_dataSourcePart: import('vue').ComputedRef<PrivateRowDT[]>;
|
|
90
90
|
virtual_offsetBottom: import('vue').ComputedRef<number>;
|
|
91
91
|
virtualX_on: import('vue').ComputedRef<any>;
|
|
92
|
-
virtualX_columnPart: import('vue').ComputedRef<PrivateStkTableColumn<
|
|
92
|
+
virtualX_columnPart: import('vue').ComputedRef<PrivateStkTableColumn<PrivateRowDT>[]>;
|
|
93
93
|
virtualX_offsetRight: import('vue').ComputedRef<number>;
|
|
94
94
|
tableHeaderHeight: import('vue').ComputedRef<number>;
|
|
95
95
|
initVirtualScroll: (height?: number) => void;
|
package/lib/stk-table-vue.js
CHANGED
|
@@ -12,7 +12,7 @@ const _hoisted_1$3 = {
|
|
|
12
12
|
draggable: "true"
|
|
13
13
|
};
|
|
14
14
|
function _sfc_render$2(_ctx, _cache) {
|
|
15
|
-
return openBlock(), createElementBlock("span", _hoisted_1$3, _cache[0] || (_cache[0] = [
|
|
15
|
+
return openBlock(), createElementBlock("span", _hoisted_1$3, [..._cache[0] || (_cache[0] = [
|
|
16
16
|
createElementVNode("svg", {
|
|
17
17
|
viewBox: "0 0 1024 1024",
|
|
18
18
|
width: "16",
|
|
@@ -21,7 +21,7 @@ function _sfc_render$2(_ctx, _cache) {
|
|
|
21
21
|
}, [
|
|
22
22
|
createElementVNode("path", { d: "M640 853.3a85.3 85.3 0 1 1 85.3-85.3 85.3 85.3 0 0 1-85.3 85.3z m-256 0a85.3 85.3 0 1 1 85.3-85.3 85.3 85.3 0 0 1-85.3 85.3z m256-256a85.3 85.3 0 1 1 85.3-85.3 85.3 85.3 0 0 1-85.3 85.3z m-256 0a85.3 85.3 0 1 1 85.3-85.3 85.3 85.3 0 0 1-85.3 85.3z m256-256a85.3 85.3 0 1 1 85.3-85.3 85.3 85.3 0 0 1-85.3 85.3zM384 341.3a85.3 85.3 0 1 1 85.3-85.3 85.3 85.3 0 0 1-85.3 85.3z" })
|
|
23
23
|
], -1)
|
|
24
|
-
]));
|
|
24
|
+
])]);
|
|
25
25
|
}
|
|
26
26
|
const DragHandle = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$2]]);
|
|
27
27
|
const _sfc_main$2 = {};
|
|
@@ -32,7 +32,7 @@ const _hoisted_1$2 = {
|
|
|
32
32
|
viewBox: "0 0 16 16"
|
|
33
33
|
};
|
|
34
34
|
function _sfc_render$1(_ctx, _cache) {
|
|
35
|
-
return openBlock(), createElementBlock("svg", _hoisted_1$2, _cache[0] || (_cache[0] = [
|
|
35
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$2, [..._cache[0] || (_cache[0] = [
|
|
36
36
|
createElementVNode("polygon", {
|
|
37
37
|
class: "arrow-up",
|
|
38
38
|
fill: "#757699",
|
|
@@ -43,7 +43,7 @@ function _sfc_render$1(_ctx, _cache) {
|
|
|
43
43
|
transform: "translate(8, 12) rotate(-180) translate(-8, -12) ",
|
|
44
44
|
points: "8 10 4.8 14 11.2 14"
|
|
45
45
|
}, null, -1)
|
|
46
|
-
]));
|
|
46
|
+
])]);
|
|
47
47
|
}
|
|
48
48
|
const SortIcon = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$1]]);
|
|
49
49
|
const _sfc_main$1 = {};
|
|
@@ -1003,20 +1003,20 @@ function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1003
1003
|
}
|
|
1004
1004
|
}
|
|
1005
1005
|
const row = tempData[index];
|
|
1006
|
-
const col =
|
|
1006
|
+
const col = data == null ? void 0 : data.col;
|
|
1007
1007
|
if (expand == null) {
|
|
1008
1008
|
expand = isExpanded(row, col);
|
|
1009
1009
|
}
|
|
1010
1010
|
if (expand) {
|
|
1011
1011
|
const newExpandRow = {
|
|
1012
1012
|
__ROW_K__: EXPANDED_ROW_KEY_PREFIX + rowKey,
|
|
1013
|
-
|
|
1014
|
-
|
|
1013
|
+
__EXP_R__: row,
|
|
1014
|
+
__EXP_C__: col
|
|
1015
1015
|
};
|
|
1016
1016
|
tempData.splice(index + 1, 0, newExpandRow);
|
|
1017
1017
|
}
|
|
1018
1018
|
if (row) {
|
|
1019
|
-
row
|
|
1019
|
+
row[expandedKey] = expand ? col : void 0;
|
|
1020
1020
|
}
|
|
1021
1021
|
dataSourceCopy.value = tempData;
|
|
1022
1022
|
if (!(data == null ? void 0 : data.silent)) {
|
|
@@ -1252,6 +1252,7 @@ function useTrDrag({ props, emits, dataSourceCopy }) {
|
|
|
1252
1252
|
}
|
|
1253
1253
|
function useTree({ props, dataSourceCopy, rowKeyGen, emits }) {
|
|
1254
1254
|
const { defaultExpandAll, defaultExpandKeys, defaultExpandLevel } = props.treeConfig;
|
|
1255
|
+
let isFirstLoad = true;
|
|
1255
1256
|
function toggleTreeNode(row, col) {
|
|
1256
1257
|
const expand = row ? !row.__T_EXP__ : false;
|
|
1257
1258
|
privateSetTreeExpand(row, { expand, col, isClick: true });
|
|
@@ -1301,33 +1302,36 @@ function useTree({ props, dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1301
1302
|
row.__T_LV__ = level;
|
|
1302
1303
|
}
|
|
1303
1304
|
}
|
|
1304
|
-
function
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
if (
|
|
1314
|
-
|
|
1305
|
+
function recursionFlat(data, level, parent) {
|
|
1306
|
+
if (!data) return [];
|
|
1307
|
+
let result = [];
|
|
1308
|
+
for (let i = 0; i < data.length; i++) {
|
|
1309
|
+
const item = data[i];
|
|
1310
|
+
result.push(item);
|
|
1311
|
+
const isExpanded = Boolean(item.__T_EXP__);
|
|
1312
|
+
setNodeExpanded(item, isExpanded, level);
|
|
1313
|
+
if (isFirstLoad && !isExpanded) {
|
|
1314
|
+
if (defaultExpandAll) {
|
|
1315
|
+
setNodeExpanded(item, true);
|
|
1316
|
+
} else {
|
|
1317
|
+
if (defaultExpandLevel && level < defaultExpandLevel) {
|
|
1318
|
+
setNodeExpanded(item, true);
|
|
1319
|
+
}
|
|
1320
|
+
if (defaultExpandKeys == null ? void 0 : defaultExpandKeys.includes(rowKeyGen(item))) {
|
|
1315
1321
|
setNodeExpanded(item, true);
|
|
1316
|
-
} else {
|
|
1317
|
-
if (defaultExpandLevel && level < defaultExpandLevel) {
|
|
1318
|
-
setNodeExpanded(item, true);
|
|
1319
|
-
}
|
|
1320
|
-
if (defaultExpandKeys == null ? void 0 : defaultExpandKeys.includes(rowKeyGen(item))) {
|
|
1321
|
-
setNodeExpanded(item, true);
|
|
1322
|
-
}
|
|
1323
|
-
if (!item.__T_EXP__) {
|
|
1324
|
-
continue;
|
|
1325
|
-
}
|
|
1326
1322
|
}
|
|
1327
1323
|
}
|
|
1328
|
-
recursion(item.children, level + 1);
|
|
1329
1324
|
}
|
|
1330
|
-
|
|
1325
|
+
if (item.__T_EXP__) {
|
|
1326
|
+
const res = recursionFlat(item.children, level + 1);
|
|
1327
|
+
result = result.concat(res);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return result;
|
|
1331
|
+
}
|
|
1332
|
+
function flatTreeData(data) {
|
|
1333
|
+
const result = recursionFlat(data, 0);
|
|
1334
|
+
isFirstLoad = false;
|
|
1331
1335
|
return result;
|
|
1332
1336
|
}
|
|
1333
1337
|
function expandNode(row, level) {
|
|
@@ -1462,7 +1466,7 @@ function useVirtualScroll({
|
|
|
1462
1466
|
if (hasExpandCol.value) {
|
|
1463
1467
|
const expandedRowHeight = (_a = props.expandConfig) == null ? void 0 : _a.height;
|
|
1464
1468
|
const tempRowHeightFn = rowHeightFn;
|
|
1465
|
-
rowHeightFn = (row) => row && row.
|
|
1469
|
+
rowHeightFn = (row) => row && row.__EXP_R__ && expandedRowHeight || tempRowHeightFn(row);
|
|
1466
1470
|
}
|
|
1467
1471
|
return rowHeightFn;
|
|
1468
1472
|
});
|
|
@@ -1719,7 +1723,6 @@ const _hoisted_9 = ["colspan"];
|
|
|
1719
1723
|
const _hoisted_10 = { class: "table-cell-wrapper" };
|
|
1720
1724
|
const _hoisted_11 = ["data-cell-key", "onClick", "onMousedown", "onMouseenter", "onMouseleave", "onMouseover"];
|
|
1721
1725
|
const _hoisted_12 = ["title"];
|
|
1722
|
-
const _hoisted_13 = ["title"];
|
|
1723
1726
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
1724
1727
|
__name: "StkTable",
|
|
1725
1728
|
props: {
|
|
@@ -1731,9 +1734,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1731
1734
|
headless: { type: Boolean, default: false },
|
|
1732
1735
|
theme: { default: "light" },
|
|
1733
1736
|
rowHeight: { default: DEFAULT_ROW_HEIGHT },
|
|
1734
|
-
autoRowHeight: { type: Boolean, default: false },
|
|
1737
|
+
autoRowHeight: { type: [Boolean, Object], default: () => false },
|
|
1735
1738
|
rowHover: { type: Boolean, default: true },
|
|
1736
|
-
rowActive: { type: Boolean, default: () => DEFAULT_ROW_ACTIVE_CONFIG },
|
|
1739
|
+
rowActive: { type: [Boolean, Object], default: () => DEFAULT_ROW_ACTIVE_CONFIG },
|
|
1737
1740
|
rowCurrentRevokable: { type: Boolean, default: true },
|
|
1738
1741
|
headerRowHeight: { default: DEFAULT_ROW_HEIGHT },
|
|
1739
1742
|
virtual: { type: Boolean, default: false },
|
|
@@ -1752,9 +1755,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1752
1755
|
cellHover: { type: Boolean, default: false },
|
|
1753
1756
|
cellActive: { type: Boolean, default: false },
|
|
1754
1757
|
selectedCellRevokable: { type: Boolean, default: true },
|
|
1755
|
-
headerDrag: { type: Boolean, default: false },
|
|
1758
|
+
headerDrag: { type: [Boolean, Object], default: () => false },
|
|
1756
1759
|
rowClassName: { type: Function, default: () => "" },
|
|
1757
|
-
colResizable: { type: Boolean, default: false },
|
|
1760
|
+
colResizable: { type: [Boolean, Object], default: () => false },
|
|
1758
1761
|
colMinWidth: { default: 10 },
|
|
1759
1762
|
bordered: { type: [Boolean, String], default: true },
|
|
1760
1763
|
autoResize: { type: [Boolean, Function], default: true },
|
|
@@ -1952,27 +1955,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1952
1955
|
);
|
|
1953
1956
|
watch(
|
|
1954
1957
|
() => props.dataSource,
|
|
1955
|
-
(val) =>
|
|
1956
|
-
if (!Array.isArray(val)) {
|
|
1957
|
-
console.warn("invalid dataSource");
|
|
1958
|
-
return;
|
|
1959
|
-
}
|
|
1960
|
-
let needInitVirtualScrollY = false;
|
|
1961
|
-
if (dataSourceCopy.value.length !== val.length) {
|
|
1962
|
-
needInitVirtualScrollY = true;
|
|
1963
|
-
}
|
|
1964
|
-
initDataSource(val);
|
|
1965
|
-
updateMaxRowSpan();
|
|
1966
|
-
if (needInitVirtualScrollY) {
|
|
1967
|
-
nextTick(() => initVirtualScrollY());
|
|
1968
|
-
}
|
|
1969
|
-
const sortColValue = sortCol.value;
|
|
1970
|
-
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
1971
|
-
const colKey = colKeyGen.value;
|
|
1972
|
-
const column = tableHeaderLast.value.find((it) => colKey(it) === sortColValue);
|
|
1973
|
-
onColumnSort(column, false);
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1958
|
+
(val) => updateDataSource(val)
|
|
1976
1959
|
);
|
|
1977
1960
|
watch(
|
|
1978
1961
|
() => props.fixedColShadow,
|
|
@@ -2067,13 +2050,34 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2067
2050
|
tableHeaders.value = tableHeadersTemp;
|
|
2068
2051
|
tableHeadersForCalc.value = tableHeadersForCalcTemp;
|
|
2069
2052
|
}
|
|
2053
|
+
function updateDataSource(val) {
|
|
2054
|
+
if (!Array.isArray(val)) {
|
|
2055
|
+
console.warn("invalid dataSource");
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
let needInitVirtualScrollY = false;
|
|
2059
|
+
if (dataSourceCopy.value.length !== val.length) {
|
|
2060
|
+
needInitVirtualScrollY = true;
|
|
2061
|
+
}
|
|
2062
|
+
initDataSource(val);
|
|
2063
|
+
updateMaxRowSpan();
|
|
2064
|
+
if (needInitVirtualScrollY) {
|
|
2065
|
+
nextTick(() => initVirtualScrollY());
|
|
2066
|
+
}
|
|
2067
|
+
const sortColValue = sortCol.value;
|
|
2068
|
+
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
2069
|
+
const colKey = colKeyGen.value;
|
|
2070
|
+
const column = tableHeaderLast.value.find((it) => colKey(it) === sortColValue);
|
|
2071
|
+
onColumnSort(column, false);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2070
2074
|
function rowKeyGen(row) {
|
|
2071
2075
|
if (!row) return row;
|
|
2072
2076
|
let key = rowKeyGenCache.get(row) || row.__ROW_K__;
|
|
2073
2077
|
if (!key) {
|
|
2074
2078
|
key = rowKeyGenComputed.value(row);
|
|
2075
2079
|
if (key === void 0) {
|
|
2076
|
-
key = Math.random().toString();
|
|
2080
|
+
key = Math.random().toString(36).slice(2);
|
|
2077
2081
|
}
|
|
2078
2082
|
rowKeyGenCache.set(row, key);
|
|
2079
2083
|
}
|
|
@@ -2530,18 +2534,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2530
2534
|
ref_key: "tableContainerRef",
|
|
2531
2535
|
ref: tableContainerRef,
|
|
2532
2536
|
class: normalizeClass(["stk-table", {
|
|
2533
|
-
virtual:
|
|
2534
|
-
"virtual-x":
|
|
2537
|
+
virtual: __props.virtual,
|
|
2538
|
+
"virtual-x": __props.virtualX,
|
|
2535
2539
|
"vt-on": unref(virtual_on),
|
|
2536
|
-
light:
|
|
2537
|
-
dark:
|
|
2538
|
-
headless:
|
|
2540
|
+
light: __props.theme === "light",
|
|
2541
|
+
dark: __props.theme === "dark",
|
|
2542
|
+
headless: __props.headless,
|
|
2539
2543
|
"is-col-resizing": unref(isColResizing),
|
|
2540
2544
|
"col-resizable": props.colResizable,
|
|
2541
2545
|
bordered: props.bordered,
|
|
2542
|
-
|
|
2543
|
-
"bordered-v": props.bordered === "v",
|
|
2544
|
-
"bordered-body-v": props.bordered === "body-v",
|
|
2546
|
+
[`bordered-${props.bordered}`]: typeof props.bordered === "string",
|
|
2545
2547
|
stripe: props.stripe,
|
|
2546
2548
|
"cell-hover": props.cellHover,
|
|
2547
2549
|
"cell-active": props.cellActive,
|
|
@@ -2567,7 +2569,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2567
2569
|
class: "row-by-row-table-height",
|
|
2568
2570
|
style: normalizeStyle(`height: ${SRBRTotalHeight.value}px`)
|
|
2569
2571
|
}, null, 4)) : createCommentVNode("", true),
|
|
2570
|
-
|
|
2572
|
+
__props.colResizable ? (openBlock(), createElementBlock("div", {
|
|
2571
2573
|
key: 1,
|
|
2572
2574
|
ref_key: "colResizeIndicatorRef",
|
|
2573
2575
|
ref: colResizeIndicatorRef,
|
|
@@ -2577,9 +2579,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2577
2579
|
class: normalizeClass(["stk-table-main", {
|
|
2578
2580
|
"fixed-mode": props.fixedMode
|
|
2579
2581
|
}]),
|
|
2580
|
-
style: normalizeStyle({ width:
|
|
2582
|
+
style: normalizeStyle({ width: __props.width, minWidth: __props.minWidth, maxWidth: __props.maxWidth })
|
|
2581
2583
|
}, [
|
|
2582
|
-
!
|
|
2584
|
+
!__props.headless ? (openBlock(), createElementBlock("thead", _hoisted_1, [
|
|
2583
2585
|
(openBlock(true), createElementBlock(Fragment, null, renderList(tableHeaders.value, (row, rowIndex) => {
|
|
2584
2586
|
return openBlock(), createElementBlock("tr", {
|
|
2585
2587
|
key: rowIndex,
|
|
@@ -2670,8 +2672,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2670
2672
|
style: normalizeStyle(`height:${unref(virtualScroll).offsetTop}px`),
|
|
2671
2673
|
class: "padding-top-tr"
|
|
2672
2674
|
}, [
|
|
2673
|
-
unref(virtualX_on) &&
|
|
2674
|
-
|
|
2675
|
+
unref(virtualX_on) && __props.fixedMode && __props.headless ? (openBlock(), createElementBlock("td", _hoisted_6)) : createCommentVNode("", true),
|
|
2676
|
+
__props.fixedMode && __props.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
|
|
2675
2677
|
return openBlock(), createElementBlock("td", {
|
|
2676
2678
|
key: colKeyGen.value(col),
|
|
2677
2679
|
style: normalizeStyle(cellStyleMap.value[unref(TagType).TD].get(colKeyGen.value(col)))
|
|
@@ -2681,21 +2683,21 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2681
2683
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, rowIndex) => {
|
|
2682
2684
|
var _a, _b;
|
|
2683
2685
|
return openBlock(), createElementBlock("tr", {
|
|
2684
|
-
id: unref(stkTableId) + "-" + (
|
|
2686
|
+
id: unref(stkTableId) + "-" + (__props.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex)),
|
|
2685
2687
|
ref_for: true,
|
|
2686
2688
|
ref_key: "trRef",
|
|
2687
2689
|
ref: trRef,
|
|
2688
|
-
key:
|
|
2689
|
-
"data-row-key":
|
|
2690
|
+
key: __props.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex),
|
|
2691
|
+
"data-row-key": __props.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex),
|
|
2690
2692
|
class: normalizeClass({
|
|
2691
|
-
active:
|
|
2692
|
-
hover: props.showTrHoverClass && (
|
|
2693
|
-
[
|
|
2694
|
-
expanded: row
|
|
2695
|
-
"expanded-row": row && row.
|
|
2693
|
+
active: __props.rowKey ? rowKeyGen(row) === currentRowKey.value : row === currentRow.value,
|
|
2694
|
+
hover: props.showTrHoverClass && (__props.rowKey ? rowKeyGen(row) === currentHoverRowKey.value : row === currentHoverRowKey.value),
|
|
2695
|
+
[__props.rowClassName(row, getRowIndex(rowIndex)) || ""]: true,
|
|
2696
|
+
expanded: row && row.__EXP__,
|
|
2697
|
+
"expanded-row": row && row.__EXP_R__
|
|
2696
2698
|
}),
|
|
2697
2699
|
style: normalizeStyle({
|
|
2698
|
-
"--row-height": row && row.
|
|
2700
|
+
"--row-height": row && row.__EXP_R__ && props.virtual && ((_a = props.expandConfig) == null ? void 0 : _a.height) && ((_b = props.expandConfig) == null ? void 0 : _b.height) + "px"
|
|
2699
2701
|
}),
|
|
2700
2702
|
onClick: ($event) => onRowClick($event, row, getRowIndex(rowIndex)),
|
|
2701
2703
|
onDblclick: ($event) => onRowDblclick($event, row, getRowIndex(rowIndex)),
|
|
@@ -2705,18 +2707,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2705
2707
|
onDrop: ($event) => unref(onTrDrop)($event, getRowIndex(rowIndex))
|
|
2706
2708
|
}, [
|
|
2707
2709
|
unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_8)) : createCommentVNode("", true),
|
|
2708
|
-
row && row.
|
|
2710
|
+
row && row.__EXP_R__ ? (openBlock(), createElementBlock("td", {
|
|
2709
2711
|
key: 1,
|
|
2710
2712
|
colspan: unref(virtualX_columnPart).length
|
|
2711
2713
|
}, [
|
|
2712
2714
|
createElementVNode("div", _hoisted_10, [
|
|
2713
2715
|
renderSlot(_ctx.$slots, "expand", {
|
|
2714
|
-
row: row.
|
|
2715
|
-
col: row.
|
|
2716
|
+
row: row.__EXP_R__,
|
|
2717
|
+
col: row.__EXP_C__
|
|
2716
2718
|
}, () => {
|
|
2717
2719
|
var _a2;
|
|
2718
2720
|
return [
|
|
2719
|
-
createTextVNode(toDisplayString(((_a2 = row.
|
|
2721
|
+
createTextVNode(toDisplayString(((_a2 = row.__EXP_R__) == null ? void 0 : _a2[row.__EXP_C__.dataIndex]) ?? ""), 1)
|
|
2720
2722
|
];
|
|
2721
2723
|
})
|
|
2722
2724
|
])
|
|
@@ -2747,27 +2749,42 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2747
2749
|
onMouseleave: ($event) => onCellMouseLeave($event, row, col),
|
|
2748
2750
|
onMouseover: ($event) => onCellMouseOver($event, row, col)
|
|
2749
2751
|
}), [
|
|
2750
|
-
col.
|
|
2752
|
+
col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
|
|
2751
2753
|
key: 0,
|
|
2752
2754
|
class: "table-cell-wrapper",
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
+
col,
|
|
2756
|
+
row,
|
|
2757
|
+
rowIndex: getRowIndex(rowIndex),
|
|
2758
|
+
colIndex,
|
|
2759
|
+
cellValue: row && row[col.dataIndex],
|
|
2760
|
+
expanded: row && row.__EXP__,
|
|
2761
|
+
"tree-expanded": row && row.__T_EXP__
|
|
2762
|
+
}, {
|
|
2763
|
+
stkFoldIcon: withCtx(() => [
|
|
2764
|
+
createVNode(TriangleIcon, {
|
|
2765
|
+
onClick: ($event) => triangleClick($event, row, col)
|
|
2766
|
+
}, null, 8, ["onClick"])
|
|
2767
|
+
]),
|
|
2768
|
+
stkDragIcon: withCtx(() => [
|
|
2769
|
+
createVNode(DragHandle, {
|
|
2770
|
+
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2771
|
+
}, null, 8, ["onDragstart"])
|
|
2772
|
+
]),
|
|
2773
|
+
_: 2
|
|
2774
|
+
}, 1032, ["col", "row", "rowIndex", "colIndex", "cellValue", "expanded", "tree-expanded"])) : (openBlock(), createElementBlock("div", {
|
|
2775
|
+
key: 1,
|
|
2776
|
+
class: "table-cell-wrapper",
|
|
2777
|
+
title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : "",
|
|
2778
|
+
style: normalizeStyle(col.type === "tree-node" ? { paddingLeft: row.__T_LV__ && row.__T_LV__ * 16 + "px" } : {})
|
|
2755
2779
|
}, [
|
|
2756
|
-
col.
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
"tree-expanded": row && row.__T_EXP__ || null
|
|
2765
|
-
}, {
|
|
2766
|
-
stkFoldIcon: withCtx(() => [
|
|
2767
|
-
createVNode(TriangleIcon)
|
|
2768
|
-
]),
|
|
2769
|
-
_: 2
|
|
2770
|
-
}, 1032, ["col", "row", "rowIndex", "colIndex", "cellValue", "expanded", "tree-expanded"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
2780
|
+
col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
2781
|
+
createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1), 1)
|
|
2782
|
+
], 64)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
2783
|
+
createVNode(DragHandle, {
|
|
2784
|
+
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2785
|
+
}, null, 8, ["onDragstart"]),
|
|
2786
|
+
createElementVNode("span", null, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)
|
|
2787
|
+
], 64)) : col.type === "expand" || col.type === "tree-node" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
2771
2788
|
col.type === "expand" || col.type === "tree-node" && row.children !== void 0 ? (openBlock(), createBlock(TriangleIcon, {
|
|
2772
2789
|
key: 0,
|
|
2773
2790
|
onClick: ($event) => triangleClick($event, row, col)
|
|
@@ -2775,43 +2792,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2775
2792
|
createElementVNode("span", {
|
|
2776
2793
|
style: normalizeStyle(col.type === "tree-node" && !row.children ? "padding-left: 16px;" : "")
|
|
2777
2794
|
}, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 5)
|
|
2795
|
+
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
|
|
2796
|
+
createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
|
|
2778
2797
|
], 64))
|
|
2779
|
-
], 12, _hoisted_12))
|
|
2780
|
-
col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
|
|
2781
|
-
key: 0,
|
|
2782
|
-
class: "table-cell-wrapper",
|
|
2783
|
-
col,
|
|
2784
|
-
row,
|
|
2785
|
-
rowIndex: getRowIndex(rowIndex),
|
|
2786
|
-
colIndex,
|
|
2787
|
-
cellValue: row && row[col.dataIndex]
|
|
2788
|
-
}, {
|
|
2789
|
-
stkFoldIcon: withCtx(() => [
|
|
2790
|
-
createVNode(TriangleIcon)
|
|
2791
|
-
]),
|
|
2792
|
-
stkDragIcon: withCtx(() => [
|
|
2793
|
-
createVNode(DragHandle, {
|
|
2794
|
-
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2795
|
-
}, null, 8, ["onDragstart"])
|
|
2796
|
-
]),
|
|
2797
|
-
_: 2
|
|
2798
|
-
}, 1032, ["col", "row", "rowIndex", "colIndex", "cellValue"])) : (openBlock(), createElementBlock("div", {
|
|
2799
|
-
key: 1,
|
|
2800
|
-
class: "table-cell-wrapper",
|
|
2801
|
-
title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : ""
|
|
2802
|
-
}, [
|
|
2803
|
-
col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
2804
|
-
createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1), 1)
|
|
2805
|
-
], 64)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
2806
|
-
createVNode(DragHandle, {
|
|
2807
|
-
onDragstart: ($event) => unref(onTrDragStart)($event, getRowIndex(rowIndex))
|
|
2808
|
-
}, null, 8, ["onDragstart"]),
|
|
2809
|
-
createElementVNode("span", null, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)
|
|
2810
|
-
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
2811
|
-
createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
|
|
2812
|
-
], 64))
|
|
2813
|
-
], 8, _hoisted_13))
|
|
2814
|
-
], 64))
|
|
2798
|
+
], 12, _hoisted_12))
|
|
2815
2799
|
], 16, _hoisted_11)) : createCommentVNode("", true)
|
|
2816
2800
|
], 64);
|
|
2817
2801
|
}), 256))
|
|
@@ -2827,12 +2811,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2827
2811
|
}, null, 4)) : createCommentVNode("", true)
|
|
2828
2812
|
], 32)
|
|
2829
2813
|
], 6),
|
|
2830
|
-
(!dataSourceCopy.value || !dataSourceCopy.value.length) &&
|
|
2814
|
+
(!dataSourceCopy.value || !dataSourceCopy.value.length) && __props.showNoData ? (openBlock(), createElementBlock("div", {
|
|
2831
2815
|
key: 2,
|
|
2832
|
-
class: normalizeClass(["stk-table-no-data", { "no-data-full":
|
|
2816
|
+
class: normalizeClass(["stk-table-no-data", { "no-data-full": __props.noDataFull }])
|
|
2833
2817
|
}, [
|
|
2834
2818
|
renderSlot(_ctx.$slots, "empty", {}, () => [
|
|
2835
|
-
_cache[8] || (_cache[8] = createTextVNode("暂无数据"))
|
|
2819
|
+
_cache[8] || (_cache[8] = createTextVNode("暂无数据", -1))
|
|
2836
2820
|
])
|
|
2837
2821
|
], 2)) : createCommentVNode("", true),
|
|
2838
2822
|
renderSlot(_ctx.$slots, "customBottom")
|
package/lib/style.css
CHANGED
|
@@ -102,6 +102,9 @@
|
|
|
102
102
|
.stk-table.bordered-body-v tbody{
|
|
103
103
|
--bg-border-bottom:linear-gradient(transparent, transparent);
|
|
104
104
|
}
|
|
105
|
+
.stk-table.bordered-body-h tbody{
|
|
106
|
+
--bg-border-right:linear-gradient(transparent, transparent);
|
|
107
|
+
}
|
|
105
108
|
.stk-table.stripe:not(.vt-on) .stk-tbody-main tr:nth-child(even){
|
|
106
109
|
background-color:var(--stripe-bgc);
|
|
107
110
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stk-table-vue",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.8.12",
|
|
4
|
+
"description": "High performance realtime virtual table for vue3 and vue2.7",
|
|
5
5
|
"main": "./lib/stk-table-vue.js",
|
|
6
6
|
"types": "./lib/src/StkTable/index.d.ts",
|
|
7
7
|
"packageManager": "pnpm@10.7.0",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/mockjs": "^1.0.10",
|
|
44
|
-
"@types/node": "^
|
|
44
|
+
"@types/node": "^22.18.10",
|
|
45
45
|
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
|
46
46
|
"@typescript-eslint/parser": "^7.7.0",
|
|
47
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
47
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
48
48
|
"@vue/test-utils": "^2.4.6",
|
|
49
49
|
"eslint": "^8.57.0",
|
|
50
50
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"prettier": "^3.2.5",
|
|
62
62
|
"stk-table-vue": "^0.8.7",
|
|
63
63
|
"typescript": "^5.8.3",
|
|
64
|
-
"vite": "^7.
|
|
64
|
+
"vite": "^7.2.2",
|
|
65
65
|
"vite-plugin-dts": "3.9.1",
|
|
66
66
|
"vitepress": "^1.6.4",
|
|
67
67
|
"vitepress-demo-plugin": "^1.4.7",
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
'is-col-resizing': isColResizing,
|
|
14
14
|
'col-resizable': props.colResizable,
|
|
15
15
|
bordered: props.bordered,
|
|
16
|
-
|
|
17
|
-
'bordered-v': props.bordered === 'v',
|
|
18
|
-
'bordered-body-v': props.bordered === 'body-v',
|
|
16
|
+
[`bordered-${props.bordered}`]: typeof props.bordered === 'string',
|
|
19
17
|
stripe: props.stripe,
|
|
20
18
|
'cell-hover': props.cellHover,
|
|
21
19
|
'cell-active': props.cellActive,
|
|
@@ -115,12 +113,11 @@
|
|
|
115
113
|
active: rowKey ? rowKeyGen(row) === currentRowKey : row === currentRow,
|
|
116
114
|
hover: props.showTrHoverClass && (rowKey ? rowKeyGen(row) === currentHoverRowKey : row === currentHoverRowKey),
|
|
117
115
|
[rowClassName(row, getRowIndex(rowIndex)) || '']: true,
|
|
118
|
-
expanded: row
|
|
119
|
-
'expanded-row': row && row.
|
|
116
|
+
expanded: row && row.__EXP__,
|
|
117
|
+
'expanded-row': row && row.__EXP_R__,
|
|
120
118
|
}"
|
|
121
119
|
:style="{
|
|
122
|
-
'--row-height':
|
|
123
|
-
row && row.__EXPANDED_ROW__ && props.virtual && props.expandConfig?.height && props.expandConfig?.height + 'px',
|
|
120
|
+
'--row-height': row && row.__EXP_R__ && props.virtual && props.expandConfig?.height && props.expandConfig?.height + 'px',
|
|
124
121
|
}"
|
|
125
122
|
@click="onRowClick($event, row, getRowIndex(rowIndex))"
|
|
126
123
|
@dblclick="onRowDblclick($event, row, getRowIndex(rowIndex))"
|
|
@@ -130,10 +127,10 @@
|
|
|
130
127
|
@drop="onTrDrop($event, getRowIndex(rowIndex))"
|
|
131
128
|
>
|
|
132
129
|
<td v-if="virtualX_on" class="vt-x-left"></td>
|
|
133
|
-
<td v-if="row && row.
|
|
130
|
+
<td v-if="row && row.__EXP_R__" :colspan="virtualX_columnPart.length">
|
|
134
131
|
<div class="table-cell-wrapper">
|
|
135
|
-
<slot name="expand" :row="row.
|
|
136
|
-
{{ row.
|
|
132
|
+
<slot name="expand" :row="row.__EXP_R__" :col="row.__EXP_C__">
|
|
133
|
+
{{ row.__EXP_R__?.[row.__EXP_C__!.dataIndex] ?? '' }}
|
|
137
134
|
</slot>
|
|
138
135
|
</div>
|
|
139
136
|
</td>
|
|
@@ -164,71 +161,53 @@
|
|
|
164
161
|
@mouseleave="onCellMouseLeave($event, row, col)"
|
|
165
162
|
@mouseover="onCellMouseOver($event, row, col)"
|
|
166
163
|
>
|
|
167
|
-
<
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
>
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
215
|
-
</template>
|
|
216
|
-
</component>
|
|
217
|
-
<div v-else class="table-cell-wrapper" :title="col.type !== 'seq' ? row?.[col.dataIndex] : ''">
|
|
218
|
-
<template v-if="col.type === 'seq'">
|
|
219
|
-
{{ (props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1 }}
|
|
220
|
-
</template>
|
|
221
|
-
<template v-else-if="col.type === 'dragRow'">
|
|
222
|
-
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
223
|
-
<span>
|
|
224
|
-
{{ row?.[col.dataIndex] ?? '' }}
|
|
225
|
-
</span>
|
|
226
|
-
</template>
|
|
227
|
-
<template v-else>
|
|
228
|
-
{{ row?.[col.dataIndex] ?? getEmptyCellText(col, row) }}
|
|
229
|
-
</template>
|
|
230
|
-
</div>
|
|
231
|
-
</template>
|
|
164
|
+
<component
|
|
165
|
+
:is="col.customCell"
|
|
166
|
+
v-if="col.customCell"
|
|
167
|
+
class="table-cell-wrapper"
|
|
168
|
+
:col="col"
|
|
169
|
+
:row="row"
|
|
170
|
+
:rowIndex="getRowIndex(rowIndex)"
|
|
171
|
+
:colIndex="colIndex"
|
|
172
|
+
:cellValue="row && row[col.dataIndex]"
|
|
173
|
+
:expanded="row && row.__EXP__"
|
|
174
|
+
:tree-expanded="row && row.__T_EXP__"
|
|
175
|
+
>
|
|
176
|
+
<template #stkFoldIcon>
|
|
177
|
+
<TriangleIcon @click="triangleClick($event, row, col)"></TriangleIcon>
|
|
178
|
+
</template>
|
|
179
|
+
<template #stkDragIcon>
|
|
180
|
+
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
181
|
+
</template>
|
|
182
|
+
</component>
|
|
183
|
+
<div
|
|
184
|
+
v-else
|
|
185
|
+
class="table-cell-wrapper"
|
|
186
|
+
:title="col.type !== 'seq' ? row?.[col.dataIndex] : ''"
|
|
187
|
+
:style="col.type === 'tree-node' ? { paddingLeft: row.__T_LV__ && row.__T_LV__ * 16 + 'px' } : {}"
|
|
188
|
+
>
|
|
189
|
+
<template v-if="col.type === 'seq'">
|
|
190
|
+
{{ (props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1 }}
|
|
191
|
+
</template>
|
|
192
|
+
<template v-else-if="col.type === 'dragRow'">
|
|
193
|
+
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
194
|
+
<span>
|
|
195
|
+
{{ row?.[col.dataIndex] ?? '' }}
|
|
196
|
+
</span>
|
|
197
|
+
</template>
|
|
198
|
+
<template v-else-if="col.type === 'expand' || col.type === 'tree-node'">
|
|
199
|
+
<TriangleIcon
|
|
200
|
+
v-if="col.type === 'expand' || (col.type === 'tree-node' && row.children !== void 0)"
|
|
201
|
+
@click="triangleClick($event, row, col)"
|
|
202
|
+
/>
|
|
203
|
+
<span :style="col.type === 'tree-node' && !row.children ? 'padding-left: 16px;' : ''">
|
|
204
|
+
{{ row?.[col.dataIndex] ?? '' }}
|
|
205
|
+
</span>
|
|
206
|
+
</template>
|
|
207
|
+
<template v-else>
|
|
208
|
+
{{ row?.[col.dataIndex] ?? getEmptyCellText(col, row) }}
|
|
209
|
+
</template>
|
|
210
|
+
</div>
|
|
232
211
|
</td>
|
|
233
212
|
</template>
|
|
234
213
|
</template>
|
|
@@ -375,7 +354,7 @@ const props = withDefaults(
|
|
|
375
354
|
/** 单元格再次点击否可以取消选中 (cellActive=true)*/
|
|
376
355
|
selectedCellRevokable?: boolean;
|
|
377
356
|
/** 表头是否可拖动。支持回调函数。 */
|
|
378
|
-
headerDrag?: boolean | HeaderDragConfig
|
|
357
|
+
headerDrag?: boolean | HeaderDragConfig<DT>;
|
|
379
358
|
/**
|
|
380
359
|
* 给行附加className<br>
|
|
381
360
|
* FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
|
|
@@ -453,7 +432,7 @@ const props = withDefaults(
|
|
|
453
432
|
headless: false,
|
|
454
433
|
theme: 'light',
|
|
455
434
|
rowHeight: DEFAULT_ROW_HEIGHT,
|
|
456
|
-
autoRowHeight: false,
|
|
435
|
+
autoRowHeight: () => false,
|
|
457
436
|
rowHover: true,
|
|
458
437
|
rowActive: () => DEFAULT_ROW_ACTIVE_CONFIG,
|
|
459
438
|
rowCurrentRevokable: true,
|
|
@@ -474,9 +453,9 @@ const props = withDefaults(
|
|
|
474
453
|
cellHover: false,
|
|
475
454
|
cellActive: false,
|
|
476
455
|
selectedCellRevokable: true,
|
|
477
|
-
headerDrag: false,
|
|
456
|
+
headerDrag: () => false,
|
|
478
457
|
rowClassName: () => '',
|
|
479
|
-
colResizable: false,
|
|
458
|
+
colResizable: () => false,
|
|
480
459
|
colMinWidth: 10,
|
|
481
460
|
bordered: true,
|
|
482
461
|
autoResize: true,
|
|
@@ -686,7 +665,7 @@ const sortSwitchOrder: Order[] = [null, 'desc', 'asc'];
|
|
|
686
665
|
* ]
|
|
687
666
|
* ```
|
|
688
667
|
*/
|
|
689
|
-
const tableHeaders = shallowRef<PrivateStkTableColumn<
|
|
668
|
+
const tableHeaders = shallowRef<PrivateStkTableColumn<PrivateRowDT>[][]>([]);
|
|
690
669
|
|
|
691
670
|
/**
|
|
692
671
|
* 用于计算多级表头的tableHeaders。模拟rowSpan 位置的辅助数组。用于计算固定列。
|
|
@@ -706,7 +685,7 @@ const tableHeaders = shallowRef<PrivateStkTableColumn<DT>[][]>([]);
|
|
|
706
685
|
* ]
|
|
707
686
|
* ```
|
|
708
687
|
*/
|
|
709
|
-
const tableHeadersForCalc = shallowRef<PrivateStkTableColumn<
|
|
688
|
+
const tableHeadersForCalc = shallowRef<PrivateStkTableColumn<PrivateRowDT>[][]>([]);
|
|
710
689
|
|
|
711
690
|
/** 最后一行的tableHeaders.内容是 props.columns 的引用集合 */
|
|
712
691
|
const tableHeaderLast = computed(() => tableHeadersForCalc.value.slice(-1)[0] || []);
|
|
@@ -904,31 +883,7 @@ watch(
|
|
|
904
883
|
|
|
905
884
|
watch(
|
|
906
885
|
() => props.dataSource,
|
|
907
|
-
val =>
|
|
908
|
-
if (!Array.isArray(val)) {
|
|
909
|
-
console.warn('invalid dataSource');
|
|
910
|
-
return;
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
let needInitVirtualScrollY = false;
|
|
914
|
-
if (dataSourceCopy.value.length !== val.length) {
|
|
915
|
-
needInitVirtualScrollY = true;
|
|
916
|
-
}
|
|
917
|
-
initDataSource(val);
|
|
918
|
-
updateMaxRowSpan();
|
|
919
|
-
// if data length is not change, not init virtual scroll
|
|
920
|
-
if (needInitVirtualScrollY) {
|
|
921
|
-
// wait for table render,initVirtualScrollY has get `dom` operation.
|
|
922
|
-
nextTick(() => initVirtualScrollY());
|
|
923
|
-
}
|
|
924
|
-
const sortColValue = sortCol.value;
|
|
925
|
-
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
926
|
-
// sort
|
|
927
|
-
const colKey = colKeyGen.value;
|
|
928
|
-
const column = tableHeaderLast.value.find(it => colKey(it) === sortColValue);
|
|
929
|
-
onColumnSort(column, false);
|
|
930
|
-
}
|
|
931
|
-
},
|
|
886
|
+
val => updateDataSource(val),
|
|
932
887
|
);
|
|
933
888
|
|
|
934
889
|
watch(
|
|
@@ -966,14 +921,14 @@ function dealDefaultSorter() {
|
|
|
966
921
|
*/
|
|
967
922
|
function dealColumns() {
|
|
968
923
|
// reset
|
|
969
|
-
const tableHeadersTemp: StkTableColumn<
|
|
970
|
-
const tableHeadersForCalcTemp: StkTableColumn<
|
|
971
|
-
let copyColumn = props.columns; // do not deep clone
|
|
924
|
+
const tableHeadersTemp: StkTableColumn<PrivateRowDT>[][] = [];
|
|
925
|
+
const tableHeadersForCalcTemp: StkTableColumn<PrivateRowDT>[][] = [];
|
|
926
|
+
let copyColumn: StkTableColumn<PrivateRowDT>[] = props.columns; // do not deep clone
|
|
972
927
|
// relative 模式下不支持sticky列。因此就放在左右两侧。
|
|
973
928
|
if (isRelativeMode.value) {
|
|
974
|
-
let leftCol: StkTableColumn<
|
|
975
|
-
let centerCol: StkTableColumn<
|
|
976
|
-
let rightCol: StkTableColumn<
|
|
929
|
+
let leftCol: StkTableColumn<PrivateRowDT>[] = [];
|
|
930
|
+
let centerCol: StkTableColumn<PrivateRowDT>[] = [];
|
|
931
|
+
let rightCol: StkTableColumn<PrivateRowDT>[] = [];
|
|
977
932
|
copyColumn.forEach(col => {
|
|
978
933
|
if (col.fixed === 'left') {
|
|
979
934
|
leftCol.push(col);
|
|
@@ -1004,8 +959,8 @@ function dealColumns() {
|
|
|
1004
959
|
* @param parentFixed 父节点固定列继承。
|
|
1005
960
|
*/
|
|
1006
961
|
function flat(
|
|
1007
|
-
arr: PrivateStkTableColumn<
|
|
1008
|
-
parent: PrivateStkTableColumn<
|
|
962
|
+
arr: PrivateStkTableColumn<PrivateRowDT>[],
|
|
963
|
+
parent: PrivateStkTableColumn<PrivateRowDT> | null,
|
|
1009
964
|
depth = 0 /* , parentFixed: 'left' | 'right' | null = null */,
|
|
1010
965
|
) {
|
|
1011
966
|
/** 所有子节点数量 */
|
|
@@ -1057,6 +1012,32 @@ function dealColumns() {
|
|
|
1057
1012
|
tableHeadersForCalc.value = tableHeadersForCalcTemp;
|
|
1058
1013
|
}
|
|
1059
1014
|
|
|
1015
|
+
function updateDataSource(val: DT[]) {
|
|
1016
|
+
if (!Array.isArray(val)) {
|
|
1017
|
+
console.warn('invalid dataSource');
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
let needInitVirtualScrollY = false;
|
|
1022
|
+
if (dataSourceCopy.value.length !== val.length) {
|
|
1023
|
+
needInitVirtualScrollY = true;
|
|
1024
|
+
}
|
|
1025
|
+
initDataSource(val);
|
|
1026
|
+
updateMaxRowSpan();
|
|
1027
|
+
// if data length is not change, not init virtual scroll
|
|
1028
|
+
if (needInitVirtualScrollY) {
|
|
1029
|
+
// wait for table render,initVirtualScrollY has get `dom` operation.
|
|
1030
|
+
nextTick(() => initVirtualScrollY());
|
|
1031
|
+
}
|
|
1032
|
+
const sortColValue = sortCol.value;
|
|
1033
|
+
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
1034
|
+
// sort
|
|
1035
|
+
const colKey = colKeyGen.value;
|
|
1036
|
+
const column = tableHeaderLast.value.find(it => colKey(it) === sortColValue);
|
|
1037
|
+
onColumnSort(column, false);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1060
1041
|
/**
|
|
1061
1042
|
* 行唯一值生成
|
|
1062
1043
|
*/
|
|
@@ -1068,7 +1049,7 @@ function rowKeyGen(row: DT | null | undefined) {
|
|
|
1068
1049
|
|
|
1069
1050
|
if (key === void 0) {
|
|
1070
1051
|
// key为undefined时,不应该高亮行。因此重新生成key
|
|
1071
|
-
key = Math.random().toString();
|
|
1052
|
+
key = Math.random().toString(36).slice(2);
|
|
1072
1053
|
}
|
|
1073
1054
|
rowKeyGenCache.set(row, key);
|
|
1074
1055
|
}
|
|
@@ -1151,7 +1132,7 @@ function onColumnSort(col: StkTableColumn<DT> | undefined | null, click = true,
|
|
|
1151
1132
|
sortOrderIndex.value = sortOrderIndex.value % 3;
|
|
1152
1133
|
|
|
1153
1134
|
let order = sortSwitchOrder[sortOrderIndex.value];
|
|
1154
|
-
const sortConfig: SortConfig<
|
|
1135
|
+
const sortConfig: SortConfig<DT> = { ...DEFAULT_SORT_CONFIG, ...props.sortConfig, ...col.sortConfig };
|
|
1155
1136
|
const { defaultSort } = sortConfig;
|
|
1156
1137
|
const colKeyGenValue = colKeyGen.value;
|
|
1157
1138
|
|
|
@@ -1178,7 +1159,7 @@ function onColumnSort(col: StkTableColumn<DT> | undefined | null, click = true,
|
|
|
1178
1159
|
}
|
|
1179
1160
|
}
|
|
1180
1161
|
}
|
|
1181
|
-
let dataSourceTemp:
|
|
1162
|
+
let dataSourceTemp: DT[] = props.dataSource.slice();
|
|
1182
1163
|
if (!props.sortRemote || options.force) {
|
|
1183
1164
|
const sortOption = col || defaultSort;
|
|
1184
1165
|
if (sortOption) {
|
package/src/StkTable/style.less
CHANGED
|
@@ -151,6 +151,12 @@
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
&.bordered-body-h {
|
|
155
|
+
tbody {
|
|
156
|
+
--bg-border-right: linear-gradient(transparent, transparent);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
154
160
|
&.stripe {
|
|
155
161
|
&:not(.vt-on) .stk-tbody-main tr:nth-child(even) {
|
|
156
162
|
background-color: var(--stripe-bgc);
|
|
@@ -18,6 +18,8 @@ export type CustomCellProps<T extends Record<string, any>> = {
|
|
|
18
18
|
* - 展开: 返回column配置
|
|
19
19
|
*/
|
|
20
20
|
expanded?: PrivateRowDT['__EXP__'];
|
|
21
|
+
/** if tree expanded */
|
|
22
|
+
treeExpanded?: PrivateRowDT['__T_EXP__']
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export type CustomHeaderCellProps<T extends Record<string, any>> = {
|
|
@@ -147,7 +149,7 @@ export type PrivateRowDT = {
|
|
|
147
149
|
* if row expanded
|
|
148
150
|
* @private
|
|
149
151
|
*/
|
|
150
|
-
__EXP__?: StkTableColumn<any
|
|
152
|
+
__EXP__?: StkTableColumn<any>;
|
|
151
153
|
/**
|
|
152
154
|
* if tree node row expanded
|
|
153
155
|
* @private
|
|
@@ -163,6 +165,11 @@ export type PrivateRowDT = {
|
|
|
163
165
|
* @private
|
|
164
166
|
*/
|
|
165
167
|
__T_LV__?: number;
|
|
168
|
+
/** expanded row */
|
|
169
|
+
__EXP_R__?: any;
|
|
170
|
+
/** expanded col */
|
|
171
|
+
__EXP_C__?: StkTableColumn<any>;
|
|
172
|
+
children?: any[]
|
|
166
173
|
};
|
|
167
174
|
|
|
168
175
|
export type SortOption<T extends Record<string, any>> = Pick<StkTableColumn<T>, 'sorter' | 'dataIndex' | 'sortField' | 'sortType'>;
|
|
@@ -239,10 +246,6 @@ export type ExpandConfig = {
|
|
|
239
246
|
height?: number;
|
|
240
247
|
};
|
|
241
248
|
|
|
242
|
-
export type ExpandedRow = PrivateRowDT & {
|
|
243
|
-
__EXPANDED_ROW__: any;
|
|
244
|
-
__EXPANDED_COL__: any;
|
|
245
|
-
};
|
|
246
249
|
|
|
247
250
|
/** drag row config */
|
|
248
251
|
export type DragRowConfig = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ShallowRef } from 'vue';
|
|
2
|
-
import { ExpandedRow, PrivateRowDT, RowKeyGen, StkTableColumn, UniqKey } from './types';
|
|
3
2
|
import { EXPANDED_ROW_KEY_PREFIX } from './const';
|
|
3
|
+
import { PrivateRowDT, RowKeyGen, StkTableColumn, UniqKey } from './types';
|
|
4
4
|
type DT = PrivateRowDT;
|
|
5
5
|
type Option<DT extends Record<string, any>> = {
|
|
6
6
|
rowKeyGen: RowKeyGen;
|
|
@@ -11,7 +11,7 @@ type Option<DT extends Record<string, any>> = {
|
|
|
11
11
|
export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
12
12
|
const expandedKey = '__EXP__';
|
|
13
13
|
|
|
14
|
-
function isExpanded(row: DT, col?: StkTableColumn<DT>
|
|
14
|
+
function isExpanded(row: DT, col?: StkTableColumn<DT>) {
|
|
15
15
|
return row?.[expandedKey] === col ? !row?.[expandedKey] : true;
|
|
16
16
|
}
|
|
17
17
|
/** click expended icon to toggle expand row */
|
|
@@ -55,7 +55,7 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const row = tempData[index];
|
|
58
|
-
const col = data?.col
|
|
58
|
+
const col = data?.col;
|
|
59
59
|
|
|
60
60
|
if (expand == null) {
|
|
61
61
|
expand = isExpanded(row, col);
|
|
@@ -63,16 +63,16 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
63
63
|
|
|
64
64
|
if (expand) {
|
|
65
65
|
// insert new expanded row
|
|
66
|
-
const newExpandRow:
|
|
66
|
+
const newExpandRow: PrivateRowDT = {
|
|
67
67
|
__ROW_K__: EXPANDED_ROW_KEY_PREFIX + rowKey,
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
__EXP_R__: row,
|
|
69
|
+
__EXP_C__: col,
|
|
70
70
|
};
|
|
71
71
|
tempData.splice(index + 1, 0, newExpandRow);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
if (row) {
|
|
75
|
-
row
|
|
75
|
+
row[expandedKey] = expand ? col : void 0;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
dataSourceCopy.value = tempData;
|
package/src/StkTable/useTree.ts
CHANGED
|
@@ -11,7 +11,8 @@ type Option<DT extends Record<string, any>> = {
|
|
|
11
11
|
|
|
12
12
|
export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
13
13
|
const { defaultExpandAll, defaultExpandKeys, defaultExpandLevel }: TreeConfig = props.treeConfig;
|
|
14
|
-
|
|
14
|
+
/** It used to check if it is first load. To execute defaultExpandXXX */
|
|
15
|
+
let isFirstLoad = true;
|
|
15
16
|
/** click expended icon to toggle expand row */
|
|
16
17
|
function toggleTreeNode(row: DT, col: any) {
|
|
17
18
|
const expand = row ? !row.__T_EXP__ : false;
|
|
@@ -82,38 +83,44 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
82
83
|
// }
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
function recursionFlat(data: DT[] | undefined, level: number, parent?: DT): DT[] {
|
|
87
|
+
if (!data) return [];
|
|
88
|
+
let result: DT[] = []
|
|
89
|
+
for (let i = 0; i < data.length; i++) {
|
|
90
|
+
const item = data[i];
|
|
91
|
+
result.push(item);
|
|
92
|
+
const isExpanded = Boolean(item.__T_EXP__);
|
|
93
|
+
setNodeExpanded(item, isExpanded, level, parent);
|
|
94
|
+
if (isFirstLoad && !isExpanded) {
|
|
95
|
+
// first load will expand all node if defaultExpandAll is true
|
|
96
|
+
if (defaultExpandAll) {
|
|
97
|
+
setNodeExpanded(item, true);
|
|
98
|
+
} else {
|
|
99
|
+
if (defaultExpandLevel && level < defaultExpandLevel) {
|
|
100
|
+
setNodeExpanded(item, true);
|
|
101
|
+
}
|
|
102
|
+
if (defaultExpandKeys?.includes(rowKeyGen(item))) {
|
|
103
|
+
setNodeExpanded(item, true);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (item.__T_EXP__) {
|
|
108
|
+
const res = recursionFlat(item.children, level + 1, item);
|
|
109
|
+
result = result.concat(res);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
|
|
85
115
|
/**
|
|
86
116
|
* 根据保存的展开状态,深度遍历,展平树形数据。
|
|
117
|
+
* en: flatten tree data by saved expand state.
|
|
87
118
|
* @param data
|
|
88
119
|
* @returns
|
|
89
120
|
*/
|
|
90
121
|
function flatTreeData(data: DT[]) {
|
|
91
|
-
const result
|
|
92
|
-
|
|
93
|
-
if (!data) return;
|
|
94
|
-
for (let i = 0; i < data.length; i++) {
|
|
95
|
-
const item = data[i];
|
|
96
|
-
result.push(item);
|
|
97
|
-
const isExpanded = Boolean(item.__T_EXP__);
|
|
98
|
-
setNodeExpanded(item, isExpanded, level, parent);
|
|
99
|
-
if (!isExpanded) {
|
|
100
|
-
if (defaultExpandAll) {
|
|
101
|
-
setNodeExpanded(item, true);
|
|
102
|
-
} else {
|
|
103
|
-
if (defaultExpandLevel && level < defaultExpandLevel) {
|
|
104
|
-
setNodeExpanded(item, true);
|
|
105
|
-
}
|
|
106
|
-
if (defaultExpandKeys?.includes(rowKeyGen(item))) {
|
|
107
|
-
setNodeExpanded(item, true);
|
|
108
|
-
}
|
|
109
|
-
if (!item.__T_EXP__) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
recursion(item.children, level + 1, item);
|
|
115
|
-
}
|
|
116
|
-
})(data, 0);
|
|
122
|
+
const result = recursionFlat(data, 0);
|
|
123
|
+
isFirstLoad = false;
|
|
117
124
|
return result;
|
|
118
125
|
}
|
|
119
126
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Ref, ShallowRef, computed, ref } from 'vue';
|
|
2
2
|
import { DEFAULT_ROW_HEIGHT, DEFAULT_TABLE_HEIGHT, DEFAULT_TABLE_WIDTH } from './const';
|
|
3
|
-
import { AutoRowHeightConfig, PrivateStkTableColumn, RowKeyGen, StkTableColumn, UniqKey } from './types';
|
|
3
|
+
import { AutoRowHeightConfig, PrivateRowDT, PrivateStkTableColumn, RowKeyGen, StkTableColumn, UniqKey } from './types';
|
|
4
4
|
import { getCalculatedColWidth } from './utils/constRefUtils';
|
|
5
5
|
|
|
6
6
|
type Option<DT extends Record<string, any>> = {
|
|
7
7
|
props: any;
|
|
8
8
|
tableContainerRef: Ref<HTMLElement | undefined>;
|
|
9
9
|
trRef: Ref<HTMLTableRowElement[] | undefined>;
|
|
10
|
-
dataSourceCopy: ShallowRef<
|
|
11
|
-
tableHeaderLast: ShallowRef<PrivateStkTableColumn<
|
|
12
|
-
tableHeaders: ShallowRef<PrivateStkTableColumn<
|
|
10
|
+
dataSourceCopy: ShallowRef<PrivateRowDT[]>;
|
|
11
|
+
tableHeaderLast: ShallowRef<PrivateStkTableColumn<PrivateRowDT>[]>;
|
|
12
|
+
tableHeaders: ShallowRef<PrivateStkTableColumn<PrivateRowDT>[][]>;
|
|
13
13
|
rowKeyGen: RowKeyGen;
|
|
14
14
|
maxRowSpan: Map<UniqKey, number>;
|
|
15
15
|
};
|
|
@@ -135,8 +135,8 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
135
135
|
const tableHeaderLastValue = tableHeaderLast.value;
|
|
136
136
|
if (virtualX_on.value) {
|
|
137
137
|
// 虚拟横向滚动,固定列要一直保持存在
|
|
138
|
-
const leftCols: PrivateStkTableColumn<
|
|
139
|
-
const rightCols: PrivateStkTableColumn<
|
|
138
|
+
const leftCols: PrivateStkTableColumn<PrivateRowDT>[] = [];
|
|
139
|
+
const rightCols: PrivateStkTableColumn<PrivateRowDT>[] = [];
|
|
140
140
|
/**
|
|
141
141
|
* 存在问题:
|
|
142
142
|
* table columns 从多到少时。比方原来的start=5,end=10,现在start=4,end=8。这时候endIndex就超出数组范围了。
|
|
@@ -176,15 +176,15 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
const getRowHeightFn = computed(() => {
|
|
179
|
-
let rowHeightFn: (row?:
|
|
179
|
+
let rowHeightFn: (row?: PrivateRowDT) => number = () => props.rowHeight || DEFAULT_ROW_HEIGHT;
|
|
180
180
|
if (props.autoRowHeight) {
|
|
181
181
|
const tempRowHeightFn = rowHeightFn;
|
|
182
|
-
rowHeightFn = (row?:
|
|
182
|
+
rowHeightFn = (row?: PrivateRowDT) => getAutoRowHeight(row) || tempRowHeightFn(row);
|
|
183
183
|
}
|
|
184
184
|
if (hasExpandCol.value) {
|
|
185
185
|
const expandedRowHeight = props.expandConfig?.height;
|
|
186
186
|
const tempRowHeightFn = rowHeightFn;
|
|
187
|
-
rowHeightFn = (row?:
|
|
187
|
+
rowHeightFn = (row?: PrivateRowDT) => (row && row.__EXP_R__ && expandedRowHeight) || tempRowHeightFn(row);
|
|
188
188
|
}
|
|
189
189
|
return rowHeightFn;
|
|
190
190
|
});
|
|
@@ -252,14 +252,14 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
252
252
|
autoRowHeightMap.clear();
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
function getAutoRowHeight(row?:
|
|
255
|
+
function getAutoRowHeight(row?: PrivateRowDT) {
|
|
256
256
|
if (!row) return;
|
|
257
257
|
const rowKey = rowKeyGen(row);
|
|
258
258
|
const storedHeight = autoRowHeightMap.get(String(rowKey));
|
|
259
259
|
if (storedHeight) {
|
|
260
260
|
return storedHeight;
|
|
261
261
|
}
|
|
262
|
-
const expectedHeight: AutoRowHeightConfig<
|
|
262
|
+
const expectedHeight: AutoRowHeightConfig<PrivateRowDT>['expectedHeight'] = props.autoRowHeight?.expectedHeight;
|
|
263
263
|
if (expectedHeight) {
|
|
264
264
|
if (typeof expectedHeight === 'function') {
|
|
265
265
|
return expectedHeight(row);
|