@kyfe/ks-query-table 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +35386 -7
- package/package.json +7 -5
- package/query-table.common.js.map +1 -0
- package/query-table.css +1 -0
- package/query-table.umd.js +35396 -0
- package/query-table.umd.js.map +1 -0
- package/query-table.umd.min.js +11 -0
- package/query-table.umd.min.js.map +1 -0
- package/README.md +0 -45
- package/api/index.js +0 -12
- package/assets/horizontal-back.svg +0 -1
- package/components/pe-table/cell.js +0 -184
- package/components/pe-table/collapse.js +0 -334
- package/components/pe-table/empty.vue +0 -48
- package/components/pe-table/header.js +0 -328
- package/components/pe-table/images/abnormal.png +0 -0
- package/components/pe-table/images/empty.png +0 -0
- package/components/pe-table/images/fold.svg +0 -1
- package/components/pe-table/images/sort.svg +0 -1
- package/components/pe-table/images/sorting.svg +0 -1
- package/components/pe-table/images/unfold.svg +0 -1
- package/components/pe-table/index.vue +0 -837
- package/components/pe-table/load-more.js +0 -46
- package/components/pe-table/props/index.js +0 -183
- package/components/pe-table/row.vue +0 -118
- package/components/pe-table/scrollbar.js +0 -424
- package/components/pe-table/stretch-damping.js +0 -112
- package/components/pe-table/style/cell.less +0 -89
- package/components/pe-table/style/empty.less +0 -48
- package/components/pe-table/style/header.less +0 -141
- package/components/pe-table/style/index.less +0 -88
- package/components/pe-table/style/load-more.less +0 -61
- package/components/pe-table/style/row.less +0 -6
- package/components/pe-table/table-loading.vue +0 -119
- package/components/pe-table/table-total.vue +0 -53
- package/components/pe-table/utils/animate.js +0 -80
- package/components/pe-table/utils/columns.js +0 -290
- package/components/pe-table/utils/data.js +0 -12
- package/components/pe-table/utils/fixed.js +0 -69
- package/components/pe-table/utils/formatter.js +0 -327
- package/components/pe-table/utils/render-cells.js +0 -424
- package/components/pe-table/utils/slot.js +0 -28
- package/components/pe-table/utils/tools.js +0 -84
- package/components/pe-table/utils/touch-scroll.js +0 -417
- package/components/query-table/index.vue +0 -492
- package/components/query-table/mixins/column-mixin.js +0 -102
- package/components/query-table/mixins/column-setting.js +0 -143
- package/components/query-table/mixins/data-mixin.js +0 -502
- package/components/query-table/mixins/pagination-mixin.js +0 -25
- package/components/query-table/mixins/table-fixed.js +0 -111
- package/components/query-table/mixins/table-horizontal.js +0 -119
- package/components/table-horizontal.vue +0 -99
- package/components/table-pagination.vue +0 -32
- package/components/table-settings/assets/arrpw-up.svg +0 -1
- package/components/table-settings/assets/disabled-down.svg +0 -1
- package/components/table-settings/assets/disabled-up.svg +0 -1
- package/components/table-settings/assets/down.svg +0 -1
- package/components/table-settings/assets/up.svg +0 -1
- package/components/table-settings/index.less +0 -294
- package/components/table-settings/index.vue +0 -260
- package/components/table-settings/settings.vue +0 -479
- package/components/table-settings/test.js +0 -626
- package/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
- package/components/tooltip.js +0 -124
- package/hooks/use-cache-promise.js +0 -27
- package/hooks/use-column-config.js +0 -186
- package/hooks/use-encryption.js +0 -0
- package/hooks/use-generic-search.js +0 -95
- package/store/column-store.js +0 -0
- package/styles/table.less +0 -24
- package/utils/column.js +0 -36
- package/utils/config.js +0 -12
- package/utils/encryption.js +0 -32
- package/utils/http.js +0 -1
- package/utils/localStorage.js +0 -35
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
import isFunction from 'lodash/isFunction';
|
|
2
|
-
import isNaN from 'lodash/isNaN';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 触摸滚动处理类
|
|
6
|
-
* 实现移动端触摸滚动及惯性滚动效果
|
|
7
|
-
*/
|
|
8
|
-
export class TouchScrolling {
|
|
9
|
-
/**
|
|
10
|
-
* 构造函数
|
|
11
|
-
* @param {HTMLElement} el - 需要绑定滚动效果的目标元素
|
|
12
|
-
* @param {Object} options - 配置选项
|
|
13
|
-
* @param {boolean} options.unScrollX - 是否禁用X轴滚动
|
|
14
|
-
* @param {boolean} options.unScrollY - 是否禁用Y轴滚动
|
|
15
|
-
* @param {boolean} options.isShowHorizontal - 是否显示水平滚动条
|
|
16
|
-
* @param {Function} options.handlerTouchend - 触摸结束回调函数
|
|
17
|
-
* @param {Function} options.handlerScrollEnd - 滚动结束回调函数
|
|
18
|
-
*/
|
|
19
|
-
constructor(el, options = {}) {
|
|
20
|
-
// 参数校验
|
|
21
|
-
if (!el) throw new Error('必须提供目标元素');
|
|
22
|
-
this.timer = null
|
|
23
|
-
this.isScrolling = null
|
|
24
|
-
|
|
25
|
-
// 初始化属性
|
|
26
|
-
this.el = el; // 目标DOM元素
|
|
27
|
-
this.decelerationId = null; // 减速动画ID
|
|
28
|
-
this.touchScrollState = null; // 触摸滚动状态
|
|
29
|
-
this.lastMoveTime = 0; // 上次移动时间戳
|
|
30
|
-
this.moveThrottle = 2; // 移动事件节流时间(毫秒)
|
|
31
|
-
this.touchPosition = null;
|
|
32
|
-
|
|
33
|
-
// 配置选项处理
|
|
34
|
-
this.unScrollX = !!options.unScrollX; // X轴滚动禁用状态
|
|
35
|
-
this.unScrollY = !!options.unScrollY; // Y轴滚动禁用状态
|
|
36
|
-
this.isShowHorizontal = !!options.isShowHorizontal; // 水平滚动条显示状态
|
|
37
|
-
|
|
38
|
-
// 回调函数绑定
|
|
39
|
-
this.handlerTouchStar = isFunction(options.handlerTouchStar) ? options.handlerTouchStar : null;
|
|
40
|
-
this.handlerTouchend = isFunction(options.handlerTouchend) ? options.handlerTouchend : null;
|
|
41
|
-
this.handlerTouchmove = isFunction(options.handlerTouchmove) ? options.handlerTouchmove : null;
|
|
42
|
-
this.onScrollEnd = isFunction(options.handlerScrollEnd) ? options.handlerScrollEnd : null;
|
|
43
|
-
this.handlerBeforeAnimation = isFunction(options.handlerBeforeAnimation) ? options.handlerBeforeAnimation : null;
|
|
44
|
-
|
|
45
|
-
// 绑定事件处理函数(仅绑定一次)
|
|
46
|
-
this.boundHandlers = {
|
|
47
|
-
touchstart: this.onTouchStart.bind(this),
|
|
48
|
-
touchend: this.onTouchEnd.bind(this),
|
|
49
|
-
touchmove: this.onTouchMove.bind(this),
|
|
50
|
-
touchcancel: this.onTouchCancel.bind(this),
|
|
51
|
-
pointermove: this.onPointermove.bind(this),
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// 添加事件监听
|
|
55
|
-
this.addEventListeners();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 添加事件监听器
|
|
60
|
-
*/
|
|
61
|
-
addEventListeners() {
|
|
62
|
-
const { touchstart, touchend, touchmove, touchcancel, pointermove } = this.boundHandlers;
|
|
63
|
-
this.el.addEventListener('touchstart', touchstart);
|
|
64
|
-
this.el.addEventListener('touchend', touchend);
|
|
65
|
-
this.el.addEventListener('touchmove', touchmove);
|
|
66
|
-
this.el.addEventListener('touchcancel', touchcancel);
|
|
67
|
-
this.el.addEventListener('pointermove', pointermove);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 移除事件监听器
|
|
72
|
-
*/
|
|
73
|
-
removeEventListeners() {
|
|
74
|
-
const { touchstart, touchend, touchmove } = this.boundHandlers;
|
|
75
|
-
this.el.removeEventListener('touchstart', touchstart);
|
|
76
|
-
this.el.removeEventListener('touchend', touchend);
|
|
77
|
-
this.el.removeEventListener('touchmove', touchmove);
|
|
78
|
-
this.el.removeEventListener('pointermove', pointermove);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 确保值为有效数字
|
|
83
|
-
* @param {*} value - 需要转换的值
|
|
84
|
-
* @returns {number} - 转换后的数字
|
|
85
|
-
*/
|
|
86
|
-
ensureNumeric(value) {
|
|
87
|
-
const numericValue = Number(value);
|
|
88
|
-
return isNaN(numericValue) ? 0 : numericValue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 派发滚轮事件
|
|
93
|
-
* @param {number} deltaY - Y轴滚动量
|
|
94
|
-
* @param {number} deltaX - X轴滚动量
|
|
95
|
-
*/
|
|
96
|
-
dispatchWheelEvent(deltaY, deltaX) {
|
|
97
|
-
deltaY = this.ensureNumeric(deltaY);
|
|
98
|
-
deltaX = this.ensureNumeric(deltaX);
|
|
99
|
-
|
|
100
|
-
// 无滚动量时不派发事件
|
|
101
|
-
if (!deltaY && !deltaX) {
|
|
102
|
-
// this.handlerBeforeAnimation?.(true)
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const wheelEvent = new WheelEvent('wheel', {
|
|
107
|
-
deltaY,
|
|
108
|
-
deltaX,
|
|
109
|
-
deltaMode: 0, // 像素模式
|
|
110
|
-
bubbles: true // 允许事件冒泡
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
this.el.dispatchEvent(wheelEvent);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 设置滚动属性
|
|
118
|
-
* @param {string} key - 属性名
|
|
119
|
-
* @param {*} val - 属性值
|
|
120
|
-
*/
|
|
121
|
-
setScroll(key, val) {
|
|
122
|
-
if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
123
|
-
this[key] = !!val;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 模拟惯性减速滚动效果
|
|
129
|
-
* @param {number} decelerationId - 当前减速动画ID
|
|
130
|
-
* @param {Boolean} isYAndDownToTop - Y轴并且从下至上滚动
|
|
131
|
-
*/
|
|
132
|
-
simulateDeceleratedScrolling(decelerationId, isYAndDownToTop) {
|
|
133
|
-
// 检查是否应该继续执行
|
|
134
|
-
if (!this.touchScrollState || decelerationId !== this.decelerationId) return;
|
|
135
|
-
|
|
136
|
-
// 减速效果配置常量
|
|
137
|
-
const DECELERATION_FACTOR = 0.92; // 减速因子
|
|
138
|
-
const MIN_SPEED = 0.005; // 最小速度阈值
|
|
139
|
-
const MAX_DURATION = 1000; // 最大持续时间(毫秒)
|
|
140
|
-
const Y_BOOST = 4; // Y轴初始速度增强倍数
|
|
141
|
-
const X_BOOST = 3.5; // X轴初始速度增强倍数
|
|
142
|
-
|
|
143
|
-
// 获取当前滚动量
|
|
144
|
-
let {
|
|
145
|
-
lastDeltaY: currentDeltaY,
|
|
146
|
-
lastDeltaX: currentDeltaX
|
|
147
|
-
} = this.touchScrollState;
|
|
148
|
-
|
|
149
|
-
// 无滚动量时直接触发结束
|
|
150
|
-
if (!currentDeltaY && !currentDeltaX) {
|
|
151
|
-
// 这里是为了处理没有滚动量的情况,兜底橡皮筋回弹效果。
|
|
152
|
-
// 场景:上拉到表格外部时,有概率出现 currentDeltaY = 0 && currentDeltaX = 0 的情况。
|
|
153
|
-
this.handlerBeforeAnimation?.(true)
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// 增强初始速度
|
|
158
|
-
currentDeltaY *= Y_BOOST;
|
|
159
|
-
currentDeltaX *= X_BOOST;
|
|
160
|
-
|
|
161
|
-
// 记录初始滚动方向
|
|
162
|
-
const initialDirection = {
|
|
163
|
-
y: Math.sign(currentDeltaY),
|
|
164
|
-
x: Math.sign(currentDeltaX)
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
let lastTime = performance.now(); // 上次动画帧时间
|
|
168
|
-
let elapsedTime = 0; // 已过去的时间
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 动画帧回调函数
|
|
172
|
-
* @param {number} timestamp - 当前时间戳
|
|
173
|
-
*/
|
|
174
|
-
const step = (timestamp) => {
|
|
175
|
-
// 检查是否应该继续执行
|
|
176
|
-
if (decelerationId !== this.decelerationId) return;
|
|
177
|
-
|
|
178
|
-
// 计算时间差(限制最大帧时间)
|
|
179
|
-
const deltaTime = Math.min(timestamp - lastTime, 32);
|
|
180
|
-
lastTime = timestamp;
|
|
181
|
-
elapsedTime += deltaTime;
|
|
182
|
-
|
|
183
|
-
// 计算当前减速因子
|
|
184
|
-
const progress = Math.min(1, elapsedTime / MAX_DURATION);
|
|
185
|
-
const currentFactor = DECELERATION_FACTOR * (1 - progress * 0.3);
|
|
186
|
-
const frameFactor = Math.pow(currentFactor, deltaTime / 16);
|
|
187
|
-
|
|
188
|
-
// 应用减速效果
|
|
189
|
-
currentDeltaY *= frameFactor;
|
|
190
|
-
currentDeltaX *= frameFactor;
|
|
191
|
-
|
|
192
|
-
// 确保滚动方向一致性
|
|
193
|
-
if (Math.sign(currentDeltaY) !== 0 && Math.sign(currentDeltaY) !== initialDirection.y) {
|
|
194
|
-
currentDeltaY = 0;
|
|
195
|
-
}
|
|
196
|
-
if (Math.sign(currentDeltaX) !== 0 && Math.sign(currentDeltaX) !== initialDirection.x) {
|
|
197
|
-
currentDeltaX = 0;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// 检查停止条件
|
|
201
|
-
const shouldStop =
|
|
202
|
-
(Math.abs(currentDeltaY) < MIN_SPEED && Math.abs(currentDeltaX) < MIN_SPEED * 2) ||
|
|
203
|
-
elapsedTime >= MAX_DURATION;
|
|
204
|
-
|
|
205
|
-
if (shouldStop) {
|
|
206
|
-
this.triggerScrollEnd(initialDirection);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const isBottom = this.handlerBeforeAnimation?.(isYAndDownToTop)
|
|
211
|
-
|
|
212
|
-
if (isBottom) return
|
|
213
|
-
|
|
214
|
-
// 派发滚轮事件并继续动画
|
|
215
|
-
this.dispatchWheelEvent(currentDeltaY, currentDeltaX);
|
|
216
|
-
requestAnimationFrame(step);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// 启动动画
|
|
220
|
-
requestAnimationFrame(step);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* 触发滚动结束回调
|
|
225
|
-
* @param {Object|null} direction - 滚动方向对象
|
|
226
|
-
*/
|
|
227
|
-
triggerScrollEnd(direction = null) {
|
|
228
|
-
// 如果没有提供方向,则从状态中获取
|
|
229
|
-
if (!direction && this.touchScrollState) {
|
|
230
|
-
direction = {
|
|
231
|
-
y: Math.sign(this.touchScrollState.lastDeltaY),
|
|
232
|
-
x: Math.sign(this.touchScrollState.lastDeltaX)
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
// 调用滚动结束回调(如果存在)
|
|
236
|
-
this.onScrollEnd?.(direction);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* 触摸开始事件处理
|
|
241
|
-
* @param {TouchEvent} event - 触摸事件对象
|
|
242
|
-
*/
|
|
243
|
-
onTouchStart(event) {
|
|
244
|
-
// 只处理单指触摸
|
|
245
|
-
if (event.touches.length !== 1) return;
|
|
246
|
-
this.touchPosition = this.el.getBoundingClientRect()
|
|
247
|
-
|
|
248
|
-
const touch = event.touches[0];
|
|
249
|
-
const now = performance.now();
|
|
250
|
-
|
|
251
|
-
// 初始化触摸状态
|
|
252
|
-
this.touchScrollState = {
|
|
253
|
-
startY: touch.clientY, // 起始Y坐标
|
|
254
|
-
lastY: touch.clientY, // 上次Y坐标
|
|
255
|
-
lastDeltaY: 0, // 上次Y轴变化量
|
|
256
|
-
startX: touch.clientX, // 起始X坐标
|
|
257
|
-
lastX: touch.clientX, // 上次X坐标
|
|
258
|
-
lastDeltaX: 0, // 上次X轴变化量
|
|
259
|
-
startTime: now, // 触摸开始时间
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// 使用时间戳作为减速动画ID
|
|
263
|
-
this.decelerationId = now;
|
|
264
|
-
this.lastMoveTime = now;
|
|
265
|
-
this.handlerTouchStar?.(event)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* 触摸取消事件处理
|
|
270
|
-
*/
|
|
271
|
-
onTouchCancel() {
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* 触摸结束事件处理
|
|
276
|
-
*/
|
|
277
|
-
onTouchEnd() {
|
|
278
|
-
// 检查是否有有效的触摸状态
|
|
279
|
-
if (!this.touchScrollState || !this.decelerationId) {
|
|
280
|
-
this.touchScrollState = null;
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// 获取触摸状态数据
|
|
285
|
-
const {
|
|
286
|
-
startY, lastY,
|
|
287
|
-
startX, lastX,
|
|
288
|
-
startTime
|
|
289
|
-
} = this.touchScrollState;
|
|
290
|
-
|
|
291
|
-
// 计算触摸持续时间和距离
|
|
292
|
-
const touchDuration = performance.now() - startTime;
|
|
293
|
-
const totalDeltaY = Math.abs(startY - lastY);
|
|
294
|
-
const totalDeltaX = Math.abs(startX - lastX);
|
|
295
|
-
const totalDistance = Math.max(totalDeltaY, totalDeltaX);
|
|
296
|
-
const speed = touchDuration > 0 ? totalDistance / touchDuration : 0;
|
|
297
|
-
|
|
298
|
-
// 处理触摸结束回调
|
|
299
|
-
const finalOffsetY = this.touchScrollState.lastDeltaY / 0.05;
|
|
300
|
-
this.handlerTouchend?.(finalOffsetY);
|
|
301
|
-
|
|
302
|
-
// 判断Y轴并且从下至上滚动
|
|
303
|
-
const isY = Math.sign(this.touchScrollState.lastDeltaX) === 0
|
|
304
|
-
const isDownToTop = lastY < startY
|
|
305
|
-
const isYAndDownToTop = isY && isDownToTop
|
|
306
|
-
// 根据速度决定是否应用惯性效果
|
|
307
|
-
const SPEED_THRESHOLD = 0.5; // 速度阈值
|
|
308
|
-
if (speed >= SPEED_THRESHOLD) {
|
|
309
|
-
this.simulateDeceleratedScrolling(this.decelerationId, isYAndDownToTop);
|
|
310
|
-
} else {
|
|
311
|
-
this.triggerScrollEnd();
|
|
312
|
-
this.handlerBeforeAnimation?.(isYAndDownToTop)
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// 清除触摸状态
|
|
316
|
-
this.touchScrollState = null;
|
|
317
|
-
clearTimeout(this.timer);
|
|
318
|
-
this.timer = null;
|
|
319
|
-
if (this.isScrolling) {
|
|
320
|
-
this.handlerBeforeAnimation?.(true)
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
onPointermove() {
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* 触摸移动事件处理
|
|
330
|
-
* @param {TouchEvent} event - 触摸事件对象
|
|
331
|
-
*/
|
|
332
|
-
onTouchMove(event) {
|
|
333
|
-
// 只处理单指触摸且有触摸状态的情况
|
|
334
|
-
if (!this.touchScrollState || event.touches.length !== 1) return;
|
|
335
|
-
|
|
336
|
-
// 节流处理
|
|
337
|
-
const now = performance.now();
|
|
338
|
-
if (now - this.lastMoveTime < this.moveThrottle) return;
|
|
339
|
-
this.lastMoveTime = now;
|
|
340
|
-
|
|
341
|
-
// 获取当前触摸点坐标
|
|
342
|
-
const touch = event.touches[0];
|
|
343
|
-
const currentY = touch.clientY;
|
|
344
|
-
const currentX = touch.clientX;
|
|
345
|
-
|
|
346
|
-
// 计算滚动量
|
|
347
|
-
let deltaY = this.touchScrollState.lastY - currentY;
|
|
348
|
-
let deltaX = this.touchScrollState.lastX - currentX;
|
|
349
|
-
|
|
350
|
-
// 确定主要滚动方向
|
|
351
|
-
const diffY = Math.abs(this.touchScrollState.startY - currentY);
|
|
352
|
-
const diffX = Math.abs(this.touchScrollState.startX - currentX);
|
|
353
|
-
const isVerticalScroll = (diffX - diffY) <= 0;
|
|
354
|
-
|
|
355
|
-
// 应用滚动限制
|
|
356
|
-
if (isVerticalScroll) {
|
|
357
|
-
// 判断Y轴并且从下至上滚动
|
|
358
|
-
// const isY = Math.sign(this.touchScrollState.lastDeltaX) === 0
|
|
359
|
-
// const isDownToTop = this.touchScrollState.lastY < this.touchScrollState.startY
|
|
360
|
-
// const isYAndDownToTop = isY && isDownToTop
|
|
361
|
-
// this.handlerBeforeAnimation?.(true)
|
|
362
|
-
// 垂直滚动处理
|
|
363
|
-
if (this.unScrollY && !this.isShowHorizontal) {
|
|
364
|
-
this.updateTouchState(currentY, currentX, 0, 0);
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
deltaX = 0; // 垂直滚动时忽略水平移动
|
|
368
|
-
} else {
|
|
369
|
-
// 水平滚动处理
|
|
370
|
-
deltaY = 0; // 水平滚动时忽略垂直移动
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// 阻止默认行为并派发滚轮事件
|
|
374
|
-
event.preventDefault();
|
|
375
|
-
this.dispatchWheelEvent(deltaY, deltaX);
|
|
376
|
-
this.updateTouchState(currentY, currentX, deltaY, deltaX);
|
|
377
|
-
|
|
378
|
-
// 清除之前的定时器
|
|
379
|
-
clearTimeout(this.timer);
|
|
380
|
-
this.timer = null;
|
|
381
|
-
// 标记为正在滑动
|
|
382
|
-
this.isScrolling = true;
|
|
383
|
-
// 设置新的定时器
|
|
384
|
-
this.timer = setTimeout(() => {
|
|
385
|
-
this.isScrolling = false;
|
|
386
|
-
this.touchScrollState = null;
|
|
387
|
-
this.handlerBeforeAnimation?.(true);
|
|
388
|
-
}, 150); // 150ms 内没有新的 touchmove 事件则认为停止
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* 更新触摸状态
|
|
393
|
-
* @param {number} y - 当前Y坐标
|
|
394
|
-
* @param {number} x - 当前X坐标
|
|
395
|
-
* @param {number} deltaY - Y轴滚动量
|
|
396
|
-
* @param {number} deltaX - X轴滚动量
|
|
397
|
-
*/
|
|
398
|
-
updateTouchState(y, x, deltaY, deltaX) {
|
|
399
|
-
if (!this.touchScrollState) return;
|
|
400
|
-
|
|
401
|
-
// 更新触摸状态
|
|
402
|
-
this.touchScrollState.lastY = y;
|
|
403
|
-
this.touchScrollState.lastDeltaY = deltaY;
|
|
404
|
-
this.touchScrollState.lastX = x;
|
|
405
|
-
this.touchScrollState.lastDeltaX = deltaX;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* 销毁方法,清理资源
|
|
410
|
-
*/
|
|
411
|
-
destroy() {
|
|
412
|
-
this.removeEventListeners(); // 移除事件监听
|
|
413
|
-
this.touchScrollState = null; // 清除触摸状态
|
|
414
|
-
cancelAnimationFrame(this.decelerationId); // 取消动画帧
|
|
415
|
-
this.decelerationId = null; // 清除动画ID
|
|
416
|
-
}
|
|
417
|
-
}
|