fix: 修复移动端文件列表滑动问题

- 移除 touchstart 中的 event.preventDefault(),不再阻止默认滚动
- 添加 handleLongPressMove 方法检测手指移动
- 滑动超过 10px 时自动取消长按,允许正常滚动
- 为 grid 和 list 视图的文件项添加 @touchmove 事件

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-30 10:12:46 +08:00
parent 4332057040
commit d1c5b0c1bf
2 changed files with 35 additions and 14 deletions

View File

@@ -1216,7 +1216,7 @@
<!-- 大图标视图 --> <!-- 大图标视图 -->
<div v-else-if="fileViewMode === 'grid'" class="file-grid"> <div v-else-if="fileViewMode === 'grid'" class="file-grid">
<div v-for="file in files" :key="file.name" class="file-grid-item" @click="handleFileClick(file)" @contextmenu.prevent="showFileContextMenu(file, $event)" @touchstart="handleLongPressStart(file, $event)" @touchend="handleLongPressEnd"> <div v-for="file in files" :key="file.name" class="file-grid-item" @click="handleFileClick(file)" @contextmenu.prevent="showFileContextMenu(file, $event)" @touchstart="handleLongPressStart(file, $event)" @touchmove="handleLongPressMove($event)" @touchend="handleLongPressEnd">
<div class="file-icon"> <div class="file-icon">
<!-- 图片缩略图 --> <!-- 图片缩略图 -->
<img v-if="file.name.match(/\.(jpg|jpeg|png|gif|bmp|svg|webp)$/i) && getThumbnailUrl(file)" <img v-if="file.name.match(/\.(jpg|jpeg|png|gif|bmp|svg|webp)$/i) && getThumbnailUrl(file)"
@@ -1259,6 +1259,7 @@
@click="handleFileClick(file)" @click="handleFileClick(file)"
@contextmenu.prevent="showFileContextMenu(file, $event)" @contextmenu.prevent="showFileContextMenu(file, $event)"
@touchstart="handleLongPressStart(file, $event)" @touchstart="handleLongPressStart(file, $event)"
@touchmove="handleLongPressMove($event)"
@touchend="handleLongPressEnd" @touchend="handleLongPressEnd"
@mouseover="$event.currentTarget.style.background='#f9f9f9'" @mouseover="$event.currentTarget.style.background='#f9f9f9'"
@mouseout="$event.currentTarget.style.background='white'"> @mouseout="$event.currentTarget.style.background='white'">

View File

@@ -208,6 +208,9 @@ createApp({
// 长按检测 // 长按检测
longPressTimer: null, longPressTimer: null,
longPressStartX: 0,
longPressStartY: 0,
longPressFile: null,
// 媒体预览 // 媒体预览
showImageViewer: false, showImageViewer: false,
@@ -1434,17 +1437,19 @@ handleDragLeave(e) {
handleLongPressStart(file, event) { handleLongPressStart(file, event) {
if (file.isDirectory) return; // 文件夹不响应长按 if (file.isDirectory) return; // 文件夹不响应长按
// 阻止默认的长按行为(如文本选择) // 记录初始触摸位置,用于检测是否在滑动
event.preventDefault(); const touch = event.touches[0];
this.longPressStartX = touch.clientX;
this.longPressStartY = touch.clientY;
this.longPressFile = file;
this.longPressTimer = setTimeout(() => { this.longPressTimer = setTimeout(() => {
// 触发长按菜单 // 触发长按菜单
this.contextMenuFile = file; this.contextMenuFile = file;
// 获取触摸位置 // 使用记录的触摸位置
const touch = event.touches[0]; this.contextMenuX = this.longPressStartX;
this.contextMenuX = touch.clientX; this.contextMenuY = this.longPressStartY;
this.contextMenuY = touch.clientY;
this.showContextMenu = true; this.showContextMenu = true;
// 触摸震动反馈(如果支持) // 触摸震动反馈(如果支持)
@@ -1459,6 +1464,21 @@ handleDragLeave(e) {
}, this.longPressDuration); }, this.longPressDuration);
}, },
// 长按移动检测(移动端)- 滑动时取消长按
handleLongPressMove(event) {
if (!this.longPressTimer) return;
const touch = event.touches[0];
const moveX = Math.abs(touch.clientX - this.longPressStartX);
const moveY = Math.abs(touch.clientY - this.longPressStartY);
// 如果移动超过10px认为是滑动取消长按
if (moveX > 10 || moveY > 10) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
},
// 长按取消(移动端) // 长按取消(移动端)
handleLongPressEnd() { handleLongPressEnd() {
if (this.longPressTimer) { if (this.longPressTimer) {