stk-table-vue 0.6.8 → 0.6.10
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 +201 -211
- package/lib/src/StkTable/StkTable.vue.d.ts +140 -129
- package/lib/src/StkTable/const.d.ts +2 -0
- package/lib/stk-table-vue.js +158 -154
- package/lib/style.css +11 -2
- package/package.json +74 -74
- package/src/StkTable/StkTable.vue +1541 -1515
- package/src/StkTable/components/DragHandle.vue +9 -9
- package/src/StkTable/components/SortIcon.vue +6 -6
- package/src/StkTable/const.ts +37 -34
- package/src/StkTable/index.ts +4 -4
- package/src/StkTable/style.less +553 -557
- package/src/StkTable/types/highlightDimOptions.ts +26 -26
- package/src/StkTable/types/index.ts +239 -239
- package/src/StkTable/useAutoResize.ts +91 -91
- package/src/StkTable/useColResize.ts +216 -213
- package/src/StkTable/useFixedCol.ts +148 -142
- package/src/StkTable/useFixedStyle.ts +75 -76
- package/src/StkTable/useGetFixedColPosition.ts +65 -64
- package/src/StkTable/useHighlight.ts +318 -318
- package/src/StkTable/useKeyboardArrowScroll.ts +106 -106
- package/src/StkTable/useThDrag.ts +102 -102
- package/src/StkTable/useTrDrag.ts +118 -118
- package/src/StkTable/useVirtualScroll.ts +447 -449
- package/src/StkTable/utils/constRefUtils.ts +29 -29
- package/src/StkTable/utils/index.ts +212 -212
- package/src/StkTable/utils/useTriggerRef.ts +33 -33
- package/src/VirtualTree.vue +622 -622
- package/src/VirtualTreeSelect.vue +367 -367
- package/src/vite-env.d.ts +10 -10
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import { Ref, onBeforeUnmount, onMounted, watch } from 'vue';
|
|
2
|
-
|
|
3
|
-
type Options = {
|
|
4
|
-
props: any;
|
|
5
|
-
tableContainerRef: Ref<HTMLElement | undefined>;
|
|
6
|
-
initVirtualScroll: () => void;
|
|
7
|
-
/** 防抖延时 */
|
|
8
|
-
debounceMs: number;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* 窗口变化自动重置虚拟滚动
|
|
12
|
-
* @param param0
|
|
13
|
-
*/
|
|
14
|
-
export function useAutoResize({ tableContainerRef, initVirtualScroll, props, debounceMs }: Options) {
|
|
15
|
-
let resizeObserver: ResizeObserver | null = null;
|
|
16
|
-
let isObserved = false;
|
|
17
|
-
watch(
|
|
18
|
-
() => props.virtual,
|
|
19
|
-
v => {
|
|
20
|
-
if (v) initResizeObserver();
|
|
21
|
-
else removeResizeObserver();
|
|
22
|
-
},
|
|
23
|
-
);
|
|
24
|
-
watch(
|
|
25
|
-
() => props.virtualX,
|
|
26
|
-
v => {
|
|
27
|
-
if (v) initResizeObserver();
|
|
28
|
-
else removeResizeObserver();
|
|
29
|
-
},
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
onMounted(() => {
|
|
33
|
-
if (props.virtual || props.virtualX) {
|
|
34
|
-
initResizeObserver();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
onBeforeUnmount(() => {
|
|
39
|
-
removeResizeObserver();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function initResizeObserver() {
|
|
43
|
-
if (isObserved) {
|
|
44
|
-
removeResizeObserver();
|
|
45
|
-
}
|
|
46
|
-
if (window.ResizeObserver) {
|
|
47
|
-
if (!tableContainerRef.value) {
|
|
48
|
-
const watchDom = watch(
|
|
49
|
-
() => tableContainerRef,
|
|
50
|
-
() => {
|
|
51
|
-
initResizeObserver();
|
|
52
|
-
watchDom();
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
resizeObserver = new ResizeObserver(resizeCallback);
|
|
58
|
-
resizeObserver.observe(tableContainerRef.value);
|
|
59
|
-
} else {
|
|
60
|
-
window.addEventListener('resize', resizeCallback);
|
|
61
|
-
}
|
|
62
|
-
isObserved = true;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function removeResizeObserver() {
|
|
66
|
-
if (!isObserved) return;
|
|
67
|
-
if (resizeObserver) {
|
|
68
|
-
resizeObserver.disconnect();
|
|
69
|
-
resizeObserver = null;
|
|
70
|
-
} else {
|
|
71
|
-
window.removeEventListener('resize', resizeCallback);
|
|
72
|
-
}
|
|
73
|
-
isObserved = false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let debounceTime = 0;
|
|
77
|
-
function resizeCallback() {
|
|
78
|
-
if (debounceTime) {
|
|
79
|
-
window.clearTimeout(debounceTime);
|
|
80
|
-
}
|
|
81
|
-
debounceTime = window.setTimeout(() => {
|
|
82
|
-
if (props.autoResize) {
|
|
83
|
-
initVirtualScroll();
|
|
84
|
-
if (typeof props.autoResize === 'function') {
|
|
85
|
-
props.autoResize();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
debounceTime = 0;
|
|
89
|
-
}, debounceMs);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
1
|
+
import { Ref, onBeforeUnmount, onMounted, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
type Options = {
|
|
4
|
+
props: any;
|
|
5
|
+
tableContainerRef: Ref<HTMLElement | undefined>;
|
|
6
|
+
initVirtualScroll: () => void;
|
|
7
|
+
/** 防抖延时 */
|
|
8
|
+
debounceMs: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 窗口变化自动重置虚拟滚动
|
|
12
|
+
* @param param0
|
|
13
|
+
*/
|
|
14
|
+
export function useAutoResize({ tableContainerRef, initVirtualScroll, props, debounceMs }: Options) {
|
|
15
|
+
let resizeObserver: ResizeObserver | null = null;
|
|
16
|
+
let isObserved = false;
|
|
17
|
+
watch(
|
|
18
|
+
() => props.virtual,
|
|
19
|
+
v => {
|
|
20
|
+
if (v) initResizeObserver();
|
|
21
|
+
else removeResizeObserver();
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
watch(
|
|
25
|
+
() => props.virtualX,
|
|
26
|
+
v => {
|
|
27
|
+
if (v) initResizeObserver();
|
|
28
|
+
else removeResizeObserver();
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
onMounted(() => {
|
|
33
|
+
if (props.virtual || props.virtualX) {
|
|
34
|
+
initResizeObserver();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
onBeforeUnmount(() => {
|
|
39
|
+
removeResizeObserver();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function initResizeObserver() {
|
|
43
|
+
if (isObserved) {
|
|
44
|
+
removeResizeObserver();
|
|
45
|
+
}
|
|
46
|
+
if (window.ResizeObserver) {
|
|
47
|
+
if (!tableContainerRef.value) {
|
|
48
|
+
const watchDom = watch(
|
|
49
|
+
() => tableContainerRef,
|
|
50
|
+
() => {
|
|
51
|
+
initResizeObserver();
|
|
52
|
+
watchDom();
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
resizeObserver = new ResizeObserver(resizeCallback);
|
|
58
|
+
resizeObserver.observe(tableContainerRef.value);
|
|
59
|
+
} else {
|
|
60
|
+
window.addEventListener('resize', resizeCallback);
|
|
61
|
+
}
|
|
62
|
+
isObserved = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function removeResizeObserver() {
|
|
66
|
+
if (!isObserved) return;
|
|
67
|
+
if (resizeObserver) {
|
|
68
|
+
resizeObserver.disconnect();
|
|
69
|
+
resizeObserver = null;
|
|
70
|
+
} else {
|
|
71
|
+
window.removeEventListener('resize', resizeCallback);
|
|
72
|
+
}
|
|
73
|
+
isObserved = false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let debounceTime = 0;
|
|
77
|
+
function resizeCallback() {
|
|
78
|
+
if (debounceTime) {
|
|
79
|
+
window.clearTimeout(debounceTime);
|
|
80
|
+
}
|
|
81
|
+
debounceTime = window.setTimeout(() => {
|
|
82
|
+
if (props.autoResize) {
|
|
83
|
+
initVirtualScroll();
|
|
84
|
+
if (typeof props.autoResize === 'function') {
|
|
85
|
+
props.autoResize();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
debounceTime = 0;
|
|
89
|
+
}, debounceMs);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,213 +1,216 @@
|
|
|
1
|
-
import { ComputedRef, Ref, ShallowRef, computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
|
2
|
-
import { StkTableColumn, UniqKey } from './types';
|
|
3
|
-
import { getCalculatedColWidth } from './utils/constRefUtils';
|
|
4
|
-
|
|
5
|
-
type ColResizeState<DT extends Record<string, any>> = {
|
|
6
|
-
/** 当前被拖动的列*/
|
|
7
|
-
currentCol: StkTableColumn<DT> | null;
|
|
8
|
-
/** 最后一个叶子列 */
|
|
9
|
-
lastCol: StkTableColumn<DT> | null;
|
|
10
|
-
/** 鼠标按下开始位置 */
|
|
11
|
-
startX: number;
|
|
12
|
-
/** 鼠标按下时鼠标对于表格的偏移量 */
|
|
13
|
-
startOffsetTableX: 0;
|
|
14
|
-
/** 是否反向计算,true:左增右减。false:左减右增 */
|
|
15
|
-
revertMoveX: boolean;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type Params<DT extends Record<string, any>> = {
|
|
19
|
-
props: any;
|
|
20
|
-
emits: any;
|
|
21
|
-
tableContainerRef: Ref<HTMLElement | undefined>;
|
|
22
|
-
tableHeaderLast: ShallowRef<StkTableColumn<DT>[]>;
|
|
23
|
-
colResizeIndicatorRef: Ref<HTMLElement | undefined>;
|
|
24
|
-
colKeyGen: ComputedRef<(p: any) => UniqKey>;
|
|
25
|
-
fixedCols: Ref<StkTableColumn<DT>[]>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/** 列宽拖动 */
|
|
29
|
-
export function useColResize<DT extends Record<string, any>>({
|
|
30
|
-
tableContainerRef,
|
|
31
|
-
tableHeaderLast,
|
|
32
|
-
colResizeIndicatorRef,
|
|
33
|
-
props,
|
|
34
|
-
emits,
|
|
35
|
-
colKeyGen,
|
|
36
|
-
fixedCols,
|
|
37
|
-
}: Params<DT>) {
|
|
38
|
-
/** 列宽是否在拖动 */
|
|
39
|
-
const isColResizing = ref(false);
|
|
40
|
-
|
|
41
|
-
/** 列宽调整状态 */
|
|
42
|
-
let colResizeState: ColResizeState<DT> = {
|
|
43
|
-
currentCol: null,
|
|
44
|
-
lastCol: null,
|
|
45
|
-
startX: 0,
|
|
46
|
-
startOffsetTableX: 0,
|
|
47
|
-
revertMoveX: false,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/** 是否可拖动 */
|
|
51
|
-
const colResizeOn = computed(() => {
|
|
52
|
-
if (Object.prototype.toString.call(props.colResizable) === '[object Object]') {
|
|
53
|
-
return (col: StkTableColumn<DT>) => !props.colResizable.disabled(col);
|
|
54
|
-
}
|
|
55
|
-
return () => props.colResizable;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
onMounted(() => {
|
|
59
|
-
initColResizeEvent();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
onBeforeUnmount(() => {
|
|
63
|
-
clearColResizeEvent();
|
|
64
|
-
});
|
|
65
|
-
/** 初始化列宽拖动事件 */
|
|
66
|
-
function initColResizeEvent() {
|
|
67
|
-
window.addEventListener('mousemove', onThResizeMouseMove);
|
|
68
|
-
window.addEventListener('mouseup', onThResizeMouseUp);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** 清除列宽拖动事件 */
|
|
72
|
-
function clearColResizeEvent() {
|
|
73
|
-
window.removeEventListener('mousemove', onThResizeMouseMove);
|
|
74
|
-
window.removeEventListener('mouseup', onThResizeMouseUp);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 拖动开始
|
|
79
|
-
* @param e
|
|
80
|
-
* @param col 当前列配置
|
|
81
|
-
* @param leftHandle 是否是左侧的拖动条
|
|
82
|
-
*/
|
|
83
|
-
function onThResizeMouseDown(e: MouseEvent, col: StkTableColumn<DT>, leftHandle = false) {
|
|
84
|
-
if (!tableContainerRef.value) return;
|
|
85
|
-
e.stopPropagation();
|
|
86
|
-
e.preventDefault();
|
|
87
|
-
const { clientX } = e;
|
|
88
|
-
const { scrollLeft, scrollTop } = tableContainerRef.value;
|
|
89
|
-
const { left } = tableContainerRef.value.getBoundingClientRect();
|
|
90
|
-
const tableHeaderLastValue = tableHeaderLast.value;
|
|
91
|
-
let revertMoveX = false;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
style
|
|
134
|
-
style.
|
|
135
|
-
style.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
e.
|
|
146
|
-
|
|
147
|
-
const {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
colResizeIndicatorRef.value
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
style
|
|
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
|
-
|
|
1
|
+
import { ComputedRef, Ref, ShallowRef, computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
|
2
|
+
import { StkTableColumn, UniqKey } from './types';
|
|
3
|
+
import { getCalculatedColWidth } from './utils/constRefUtils';
|
|
4
|
+
|
|
5
|
+
type ColResizeState<DT extends Record<string, any>> = {
|
|
6
|
+
/** 当前被拖动的列*/
|
|
7
|
+
currentCol: StkTableColumn<DT> | null;
|
|
8
|
+
/** 最后一个叶子列 */
|
|
9
|
+
lastCol: StkTableColumn<DT> | null;
|
|
10
|
+
/** 鼠标按下开始位置 */
|
|
11
|
+
startX: number;
|
|
12
|
+
/** 鼠标按下时鼠标对于表格的偏移量 */
|
|
13
|
+
startOffsetTableX: 0;
|
|
14
|
+
/** 是否反向计算,true:左增右减。false:左减右增 */
|
|
15
|
+
revertMoveX: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type Params<DT extends Record<string, any>> = {
|
|
19
|
+
props: any;
|
|
20
|
+
emits: any;
|
|
21
|
+
tableContainerRef: Ref<HTMLElement | undefined>;
|
|
22
|
+
tableHeaderLast: ShallowRef<StkTableColumn<DT>[]>;
|
|
23
|
+
colResizeIndicatorRef: Ref<HTMLElement | undefined>;
|
|
24
|
+
colKeyGen: ComputedRef<(p: any) => UniqKey>;
|
|
25
|
+
fixedCols: Ref<StkTableColumn<DT>[]>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** 列宽拖动 */
|
|
29
|
+
export function useColResize<DT extends Record<string, any>>({
|
|
30
|
+
tableContainerRef,
|
|
31
|
+
tableHeaderLast,
|
|
32
|
+
colResizeIndicatorRef,
|
|
33
|
+
props,
|
|
34
|
+
emits,
|
|
35
|
+
colKeyGen,
|
|
36
|
+
fixedCols,
|
|
37
|
+
}: Params<DT>) {
|
|
38
|
+
/** 列宽是否在拖动 */
|
|
39
|
+
const isColResizing = ref(false);
|
|
40
|
+
|
|
41
|
+
/** 列宽调整状态 */
|
|
42
|
+
let colResizeState: ColResizeState<DT> = {
|
|
43
|
+
currentCol: null,
|
|
44
|
+
lastCol: null,
|
|
45
|
+
startX: 0,
|
|
46
|
+
startOffsetTableX: 0,
|
|
47
|
+
revertMoveX: false,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** 是否可拖动 */
|
|
51
|
+
const colResizeOn = computed(() => {
|
|
52
|
+
if (Object.prototype.toString.call(props.colResizable) === '[object Object]') {
|
|
53
|
+
return (col: StkTableColumn<DT>) => !props.colResizable.disabled(col);
|
|
54
|
+
}
|
|
55
|
+
return () => props.colResizable;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
onMounted(() => {
|
|
59
|
+
initColResizeEvent();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
onBeforeUnmount(() => {
|
|
63
|
+
clearColResizeEvent();
|
|
64
|
+
});
|
|
65
|
+
/** 初始化列宽拖动事件 */
|
|
66
|
+
function initColResizeEvent() {
|
|
67
|
+
window.addEventListener('mousemove', onThResizeMouseMove);
|
|
68
|
+
window.addEventListener('mouseup', onThResizeMouseUp);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 清除列宽拖动事件 */
|
|
72
|
+
function clearColResizeEvent() {
|
|
73
|
+
window.removeEventListener('mousemove', onThResizeMouseMove);
|
|
74
|
+
window.removeEventListener('mouseup', onThResizeMouseUp);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 拖动开始
|
|
79
|
+
* @param e
|
|
80
|
+
* @param col 当前列配置
|
|
81
|
+
* @param leftHandle 是否是左侧的拖动条
|
|
82
|
+
*/
|
|
83
|
+
function onThResizeMouseDown(e: MouseEvent, col: StkTableColumn<DT>, leftHandle = false) {
|
|
84
|
+
if (!tableContainerRef.value) return;
|
|
85
|
+
e.stopPropagation();
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
const { clientX } = e;
|
|
88
|
+
const { scrollLeft, scrollTop } = tableContainerRef.value;
|
|
89
|
+
const { left } = tableContainerRef.value.getBoundingClientRect();
|
|
90
|
+
const tableHeaderLastValue = tableHeaderLast.value;
|
|
91
|
+
let revertMoveX = false;
|
|
92
|
+
const colKey = colKeyGen.value;
|
|
93
|
+
/** 列下标 */
|
|
94
|
+
const colIndex = tableHeaderLastValue.findIndex(it => colKey(it) === colKey(col));
|
|
95
|
+
const fixedIndex = fixedCols.value.indexOf(col);
|
|
96
|
+
/** 是否正在被固定 */
|
|
97
|
+
const isFixed = fixedIndex !== -1;
|
|
98
|
+
|
|
99
|
+
if (leftHandle) {
|
|
100
|
+
// 左侧拖动条
|
|
101
|
+
if (isFixed && col.fixed === 'right') {
|
|
102
|
+
// 对于固定右侧的列,拖动左侧的把,需要反向计算
|
|
103
|
+
revertMoveX = true;
|
|
104
|
+
} else {
|
|
105
|
+
// 取上一列
|
|
106
|
+
if (colIndex - 1 >= 0) {
|
|
107
|
+
col = tableHeaderLastValue[colIndex - 1];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// 右侧拖动条
|
|
112
|
+
if (isFixed && col.fixed === 'right') {
|
|
113
|
+
// 对于固定右侧的列,拖动右侧的把,需要拖动下一固定的列
|
|
114
|
+
revertMoveX = true;
|
|
115
|
+
col = fixedCols.value[fixedIndex + 1] || col;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const offsetTableX = clientX - left + scrollLeft;
|
|
120
|
+
|
|
121
|
+
// 记录拖动状态
|
|
122
|
+
isColResizing.value = true;
|
|
123
|
+
Object.assign(colResizeState, {
|
|
124
|
+
currentCol: col,
|
|
125
|
+
lastCol: findLastChildCol(col),
|
|
126
|
+
startX: clientX,
|
|
127
|
+
startOffsetTableX: offsetTableX,
|
|
128
|
+
revertMoveX,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// 展示指示线,更新其位置
|
|
132
|
+
if (colResizeIndicatorRef.value) {
|
|
133
|
+
const style = colResizeIndicatorRef.value.style;
|
|
134
|
+
style.display = 'block';
|
|
135
|
+
style.left = offsetTableX + 'px';
|
|
136
|
+
style.top = scrollTop + 'px';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {MouseEvent} e
|
|
142
|
+
*/
|
|
143
|
+
function onThResizeMouseMove(e: MouseEvent) {
|
|
144
|
+
if (!isColResizing.value) return;
|
|
145
|
+
e.stopPropagation();
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
const { lastCol, startX, startOffsetTableX } = colResizeState;
|
|
148
|
+
const { clientX } = e;
|
|
149
|
+
let moveX = clientX - startX;
|
|
150
|
+
const currentColWidth = getCalculatedColWidth(lastCol);
|
|
151
|
+
const minWidth = lastCol?.minWidth ?? props.colMinWidth;
|
|
152
|
+
// 移动量不小于最小列宽
|
|
153
|
+
if (currentColWidth + moveX < minWidth) {
|
|
154
|
+
moveX = -currentColWidth;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const offsetTableX = startOffsetTableX + moveX;
|
|
158
|
+
if (!colResizeIndicatorRef.value) return;
|
|
159
|
+
colResizeIndicatorRef.value.style.left = offsetTableX + 'px';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {MouseEvent} e
|
|
164
|
+
*/
|
|
165
|
+
function onThResizeMouseUp(e: MouseEvent) {
|
|
166
|
+
if (!isColResizing.value) return;
|
|
167
|
+
const { startX, lastCol, revertMoveX } = colResizeState;
|
|
168
|
+
const { clientX } = e;
|
|
169
|
+
const moveX = revertMoveX ? startX - clientX : clientX - startX;
|
|
170
|
+
|
|
171
|
+
// 移动量不小于最小列宽
|
|
172
|
+
let width = getCalculatedColWidth(lastCol) + moveX;
|
|
173
|
+
if (width < props.colMinWidth) width = props.colMinWidth;
|
|
174
|
+
|
|
175
|
+
const colKey = colKeyGen.value;
|
|
176
|
+
|
|
177
|
+
const curCol = tableHeaderLast.value.find(it => colKey(it) === colKey(lastCol));
|
|
178
|
+
if (!curCol) return;
|
|
179
|
+
curCol.width = width + 'px';
|
|
180
|
+
|
|
181
|
+
emits('update:columns', props.columns.slice());
|
|
182
|
+
emits('col-resize', { ...curCol });
|
|
183
|
+
|
|
184
|
+
// 隐藏指示线
|
|
185
|
+
if (colResizeIndicatorRef.value) {
|
|
186
|
+
const style = colResizeIndicatorRef.value.style;
|
|
187
|
+
style.display = 'none';
|
|
188
|
+
style.left = '0';
|
|
189
|
+
style.top = '0';
|
|
190
|
+
}
|
|
191
|
+
// 清除拖动状态
|
|
192
|
+
isColResizing.value = false;
|
|
193
|
+
colResizeState = {
|
|
194
|
+
currentCol: null,
|
|
195
|
+
lastCol: null,
|
|
196
|
+
startX: 0,
|
|
197
|
+
startOffsetTableX: 0,
|
|
198
|
+
revertMoveX: false,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**获取最后一个叶子 */
|
|
203
|
+
function findLastChildCol(column: StkTableColumn<DT> | null) {
|
|
204
|
+
if (column?.children?.length) {
|
|
205
|
+
const lastChild = column.children.at(-1) as StkTableColumn<DT>;
|
|
206
|
+
return findLastChildCol(lastChild);
|
|
207
|
+
}
|
|
208
|
+
return column;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
colResizeOn,
|
|
213
|
+
isColResizing,
|
|
214
|
+
onThResizeMouseDown,
|
|
215
|
+
};
|
|
216
|
+
}
|