stk-table-vue 0.6.5 → 0.6.6
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 +1 -1
- package/lib/src/StkTable/StkTable.vue.d.ts +6 -1
- package/lib/src/StkTable/index.d.ts +1 -1
- package/lib/src/StkTable/utils/index.d.ts +7 -1
- package/lib/stk-table-vue.js +20 -13
- package/lib/style.css +2 -2
- package/package.json +1 -1
- package/src/StkTable/StkTable.vue +6 -1
- package/src/StkTable/index.ts +1 -1
- package/src/StkTable/style.less +1 -3
- package/src/StkTable/utils/index.ts +25 -14
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ declare function setSelectedCell(row?: DT, col?: StkTableColumn<DT>, option?: {
|
|
|
26
26
|
* @param option.sort 是否触发排序-默认true
|
|
27
27
|
* @param option.silent 是否禁止触发回调-默认true
|
|
28
28
|
* @param option.force 是否触发排序-默认true
|
|
29
|
+
* @return 表格数据
|
|
29
30
|
*/
|
|
30
31
|
declare function setSorter(colKey: string, order: Order, option?: {
|
|
31
32
|
sortOption?: SortOption<DT>;
|
|
@@ -42,7 +43,10 @@ declare function resetSorter(): void;
|
|
|
42
43
|
declare function scrollTo(top?: number | null, left?: number | null): void;
|
|
43
44
|
/** get current table data */
|
|
44
45
|
declare function getTableData(): any[];
|
|
45
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* get current sort info
|
|
48
|
+
* @return {{key:string,order:Order}[]}
|
|
49
|
+
*/
|
|
46
50
|
declare function getSortColumns(): {
|
|
47
51
|
key: string | number | symbol | undefined;
|
|
48
52
|
order: "desc" | "asc";
|
|
@@ -492,6 +496,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<{
|
|
|
492
496
|
col: any;
|
|
493
497
|
}): any;
|
|
494
498
|
empty?(_: {}): any;
|
|
499
|
+
customBottom?(_: {}): any;
|
|
495
500
|
}>;
|
|
496
501
|
export default _default;
|
|
497
502
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
@@ -14,6 +14,12 @@ export declare function isEmptyValue(val: any, isNumber?: boolean): boolean;
|
|
|
14
14
|
* @return targetArray 的浅拷贝
|
|
15
15
|
*/
|
|
16
16
|
export declare function insertToOrderedArray<T extends object>(sortState: SortState<T>, newItem: T, targetArray: T[], sortConfig?: SortConfig<T>): T[];
|
|
17
|
+
/**
|
|
18
|
+
* 二分查找
|
|
19
|
+
* @param searchArray 查找数组
|
|
20
|
+
* @param compareCallback 比较函数,返回 -1|0|1
|
|
21
|
+
*/
|
|
22
|
+
export declare function binarySearch(searchArray: any[], compareCallback: (midIndex: number) => number): number;
|
|
17
23
|
/**
|
|
18
24
|
* 字符串比较
|
|
19
25
|
* @param a
|
|
@@ -21,7 +27,7 @@ export declare function insertToOrderedArray<T extends object>(sortState: SortSt
|
|
|
21
27
|
* @param type 类型
|
|
22
28
|
* @param isNumber 是否是数字类型
|
|
23
29
|
* @param localeCompare 是否 使用Array.prototyshpe.localeCompare
|
|
24
|
-
* @return {
|
|
30
|
+
* @return {number} <0: a < b, 0: a = b, >0: a > b
|
|
25
31
|
*/
|
|
26
32
|
export declare function strCompare(a: string, b: string, isNumber: boolean, localeCompare?: boolean): number;
|
|
27
33
|
/**
|
package/lib/stk-table-vue.js
CHANGED
|
@@ -59,7 +59,6 @@ function insertToOrderedArray(sortState, newItem, targetArray, sortConfig = {})
|
|
|
59
59
|
sortConfig = { emptyToBottom: false, ...sortConfig };
|
|
60
60
|
let { sortType } = sortState;
|
|
61
61
|
if (!sortType) sortType = typeof newItem[dataIndex];
|
|
62
|
-
const isNumber = sortType === "number";
|
|
63
62
|
const data = [...targetArray];
|
|
64
63
|
if (!order || !data.length) {
|
|
65
64
|
data.unshift(newItem);
|
|
@@ -68,26 +67,32 @@ function insertToOrderedArray(sortState, newItem, targetArray, sortConfig = {})
|
|
|
68
67
|
if (sortConfig.emptyToBottom && isEmptyValue(newItem)) {
|
|
69
68
|
data.push(newItem);
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
let eIndex = data.length - 1;
|
|
70
|
+
const isNumber = sortType === "number";
|
|
73
71
|
const targetVal = newItem[dataIndex];
|
|
74
|
-
|
|
75
|
-
const midIndex = Math.floor((sIndex + eIndex) / 2);
|
|
72
|
+
const sIndex = binarySearch(data, (midIndex) => {
|
|
76
73
|
const midVal = data[midIndex][dataIndex];
|
|
77
74
|
const compareRes = strCompare(midVal, targetVal, isNumber, sortConfig.stringLocaleCompare);
|
|
75
|
+
return order === "asc" ? compareRes : -compareRes;
|
|
76
|
+
});
|
|
77
|
+
data.splice(sIndex, 0, newItem);
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
function binarySearch(searchArray, compareCallback) {
|
|
81
|
+
let sIndex = 0;
|
|
82
|
+
let eIndex = searchArray.length - 1;
|
|
83
|
+
while (sIndex <= eIndex) {
|
|
84
|
+
const midIndex = Math.floor((sIndex + eIndex) / 2);
|
|
85
|
+
const compareRes = compareCallback(midIndex);
|
|
78
86
|
if (compareRes === 0) {
|
|
79
87
|
sIndex = midIndex;
|
|
80
88
|
break;
|
|
81
|
-
} else if (compareRes
|
|
82
|
-
|
|
83
|
-
else eIndex = midIndex - 1;
|
|
89
|
+
} else if (compareRes < 0) {
|
|
90
|
+
sIndex = midIndex + 1;
|
|
84
91
|
} else {
|
|
85
|
-
|
|
86
|
-
else sIndex = midIndex + 1;
|
|
92
|
+
eIndex = midIndex - 1;
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
|
-
|
|
90
|
-
return data;
|
|
95
|
+
return sIndex;
|
|
91
96
|
}
|
|
92
97
|
function strCompare(a, b, isNumber, localeCompare = false) {
|
|
93
98
|
let _a = a;
|
|
@@ -2343,13 +2348,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2343
2348
|
renderSlot(_ctx.$slots, "empty", {}, () => [
|
|
2344
2349
|
_cache[7] || (_cache[7] = createTextVNode("暂无数据"))
|
|
2345
2350
|
])
|
|
2346
|
-
], 2)) : createCommentVNode("", true)
|
|
2351
|
+
], 2)) : createCommentVNode("", true),
|
|
2352
|
+
renderSlot(_ctx.$slots, "customBottom")
|
|
2347
2353
|
], 38);
|
|
2348
2354
|
};
|
|
2349
2355
|
}
|
|
2350
2356
|
});
|
|
2351
2357
|
export {
|
|
2352
2358
|
_sfc_main as StkTable,
|
|
2359
|
+
binarySearch,
|
|
2353
2360
|
insertToOrderedArray,
|
|
2354
2361
|
strCompare,
|
|
2355
2362
|
tableSort
|
package/lib/style.css
CHANGED
|
@@ -260,7 +260,7 @@
|
|
|
260
260
|
.stk-table .expand-cell{
|
|
261
261
|
cursor:pointer;
|
|
262
262
|
}
|
|
263
|
-
.stk-table .expand-cell .
|
|
263
|
+
.stk-table .expand-cell .expanded-cell-wrapper::before{
|
|
264
264
|
content:'';
|
|
265
265
|
display:inline-block;
|
|
266
266
|
margin:0 2px;
|
|
@@ -271,7 +271,7 @@
|
|
|
271
271
|
border-bottom:4px solid transparent;
|
|
272
272
|
transition:transform 0.2s ease;
|
|
273
273
|
}
|
|
274
|
-
.stk-table .expand-cell .
|
|
274
|
+
.stk-table .expand-cell .expanded-cell-wrapper > span{
|
|
275
275
|
margin-left:var(--cell-padding-x);
|
|
276
276
|
}
|
|
277
277
|
.stk-table .expand-cell.expanded .table-cell-wrapper::before{
|
package/package.json
CHANGED
|
@@ -227,6 +227,7 @@
|
|
|
227
227
|
<div v-if="(!dataSourceCopy || !dataSourceCopy.length) && showNoData" class="stk-table-no-data" :class="{ 'no-data-full': noDataFull }">
|
|
228
228
|
<slot name="empty">暂无数据</slot>
|
|
229
229
|
</div>
|
|
230
|
+
<slot name="customBottom"></slot>
|
|
230
231
|
</div>
|
|
231
232
|
</template>
|
|
232
233
|
|
|
@@ -1288,6 +1289,7 @@ function setSelectedCell(row?: DT, col?: StkTableColumn<DT>, option = { silent:
|
|
|
1288
1289
|
* @param option.sort 是否触发排序-默认true
|
|
1289
1290
|
* @param option.silent 是否禁止触发回调-默认true
|
|
1290
1291
|
* @param option.force 是否触发排序-默认true
|
|
1292
|
+
* @return 表格数据
|
|
1291
1293
|
*/
|
|
1292
1294
|
function setSorter(colKey: string, order: Order, option: { sortOption?: SortOption<DT>; force?: boolean; silent?: boolean; sort?: boolean } = {}) {
|
|
1293
1295
|
const newOption = { silent: true, sortOption: null, sort: true, ...option };
|
|
@@ -1325,7 +1327,10 @@ function getTableData() {
|
|
|
1325
1327
|
return toRaw(dataSourceCopy.value);
|
|
1326
1328
|
}
|
|
1327
1329
|
|
|
1328
|
-
/**
|
|
1330
|
+
/**
|
|
1331
|
+
* get current sort info
|
|
1332
|
+
* @return {{key:string,order:Order}[]}
|
|
1333
|
+
*/
|
|
1329
1334
|
function getSortColumns() {
|
|
1330
1335
|
const sortOrder = sortSwitchOrder[sortOrderIndex.value];
|
|
1331
1336
|
if (!sortOrder) return [];
|
package/src/StkTable/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as StkTable } from './StkTable.vue';
|
|
2
|
-
export { tableSort, insertToOrderedArray, strCompare } from './utils';
|
|
2
|
+
export { tableSort, insertToOrderedArray, strCompare, binarySearch } from './utils';
|
|
3
3
|
export type { StkTableColumn } from './types/index';
|
|
4
4
|
import './style.less';
|
package/src/StkTable/style.less
CHANGED
|
@@ -386,8 +386,7 @@
|
|
|
386
386
|
.expand-cell {
|
|
387
387
|
cursor: pointer;
|
|
388
388
|
|
|
389
|
-
|
|
390
|
-
&.expanded-cell-wrapper {
|
|
389
|
+
.expanded-cell-wrapper {
|
|
391
390
|
&::before {
|
|
392
391
|
content: '';
|
|
393
392
|
display: inline-block;
|
|
@@ -404,7 +403,6 @@
|
|
|
404
403
|
margin-left: var(--cell-padding-x)
|
|
405
404
|
}
|
|
406
405
|
}
|
|
407
|
-
}
|
|
408
406
|
|
|
409
407
|
&.expanded {
|
|
410
408
|
.table-cell-wrapper::before {
|
|
@@ -26,7 +26,6 @@ export function insertToOrderedArray<T extends object>(sortState: SortState<T>,
|
|
|
26
26
|
sortConfig = { emptyToBottom: false, ...sortConfig };
|
|
27
27
|
let { sortType } = sortState;
|
|
28
28
|
if (!sortType) sortType = typeof newItem[dataIndex] as 'number' | 'string';
|
|
29
|
-
const isNumber = sortType === 'number';
|
|
30
29
|
const data = [...targetArray];
|
|
31
30
|
|
|
32
31
|
if (!order || !data.length) {
|
|
@@ -40,31 +39,43 @@ export function insertToOrderedArray<T extends object>(sortState: SortState<T>,
|
|
|
40
39
|
data.push(newItem);
|
|
41
40
|
}
|
|
42
41
|
|
|
42
|
+
const isNumber = sortType === 'number';
|
|
43
|
+
|
|
43
44
|
// 二分插入
|
|
44
|
-
let sIndex = 0;
|
|
45
|
-
let eIndex = data.length - 1;
|
|
46
45
|
const targetVal: any = newItem[dataIndex];
|
|
47
|
-
|
|
48
|
-
// console.log(sIndex, eIndex);
|
|
49
|
-
const midIndex = Math.floor((sIndex + eIndex) / 2);
|
|
46
|
+
const sIndex = binarySearch(data, midIndex => {
|
|
50
47
|
const midVal: any = data[midIndex][dataIndex];
|
|
51
48
|
const compareRes = strCompare(midVal, targetVal, isNumber, sortConfig.stringLocaleCompare);
|
|
49
|
+
return order === 'asc' ? compareRes : -compareRes;
|
|
50
|
+
});
|
|
51
|
+
data.splice(sIndex, 0, newItem);
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 二分查找
|
|
57
|
+
* @param searchArray 查找数组
|
|
58
|
+
* @param compareCallback 比较函数,返回 -1|0|1
|
|
59
|
+
*/
|
|
60
|
+
export function binarySearch(searchArray: any[], compareCallback: (midIndex: number) => number) {
|
|
61
|
+
let sIndex = 0;
|
|
62
|
+
let eIndex = searchArray.length - 1;
|
|
63
|
+
while (sIndex <= eIndex) {
|
|
64
|
+
const midIndex = Math.floor((sIndex + eIndex) / 2);
|
|
65
|
+
const compareRes = compareCallback(midIndex);
|
|
52
66
|
if (compareRes === 0) {
|
|
53
67
|
//midVal == targetVal
|
|
54
68
|
sIndex = midIndex;
|
|
55
69
|
break;
|
|
56
|
-
} else if (compareRes
|
|
70
|
+
} else if (compareRes < 0) {
|
|
57
71
|
// midVal < targetVal
|
|
58
|
-
|
|
59
|
-
else eIndex = midIndex - 1;
|
|
72
|
+
sIndex = midIndex + 1;
|
|
60
73
|
} else {
|
|
61
74
|
//midVal > targetVal
|
|
62
|
-
|
|
63
|
-
else sIndex = midIndex + 1;
|
|
75
|
+
eIndex = midIndex - 1;
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
|
-
|
|
67
|
-
return data;
|
|
78
|
+
return sIndex;
|
|
68
79
|
}
|
|
69
80
|
/**
|
|
70
81
|
* 字符串比较
|
|
@@ -73,7 +84,7 @@ export function insertToOrderedArray<T extends object>(sortState: SortState<T>,
|
|
|
73
84
|
* @param type 类型
|
|
74
85
|
* @param isNumber 是否是数字类型
|
|
75
86
|
* @param localeCompare 是否 使用Array.prototyshpe.localeCompare
|
|
76
|
-
* @return {
|
|
87
|
+
* @return {number} <0: a < b, 0: a = b, >0: a > b
|
|
77
88
|
*/
|
|
78
89
|
export function strCompare(a: string, b: string, isNumber: boolean, localeCompare = false): number {
|
|
79
90
|
let _a: number | string = a;
|