diff --git a/src/components/FileBrowser.vue b/src/components/FileBrowser.vue index 4bbec8ba..ff40c551 100644 --- a/src/components/FileBrowser.vue +++ b/src/components/FileBrowser.vue @@ -136,6 +136,12 @@ const sort = ref('name') // 是否显示目录树 const showDirTree = ref(false) +// 拖动分隔条相关 +const navigatorWidth = ref(280) // 初始宽度 +const isDragging = ref(false) +const dragStartX = ref(0) +const dragStartWidth = ref(0) + // 计算属性 const storagesArray = computed(() => { return props.storages?.map(item => ({ @@ -181,6 +187,58 @@ function fileListUpdated(items: FileItem[]) { fileListItems.value = items } +// 阻止选择事件 +function preventSelect(event: Event) { + event.preventDefault() + return false +} + +// 拖动分隔条相关方法 +function startDrag(event: MouseEvent) { + event.preventDefault() // 阻止默认行为 + event.stopPropagation() // 阻止事件冒泡 + + isDragging.value = true + dragStartX.value = event.clientX + dragStartWidth.value = navigatorWidth.value + + document.addEventListener('mousemove', handleDrag, { passive: false }) + document.addEventListener('mouseup', stopDrag, { passive: false }) + document.addEventListener('selectstart', preventSelect) // 阻止选择开始 + + document.body.style.cursor = 'col-resize' + document.body.style.userSelect = 'none' + ;(document.body.style as any).webkitUserSelect = 'none' // Safari兼容 + ;(document.body.style as any).mozUserSelect = 'none' // Firefox兼容 +} + +function handleDrag(event: MouseEvent) { + if (!isDragging.value) return + + event.preventDefault() // 阻止默认行为 + + const deltaX = event.clientX - dragStartX.value + const newWidth = dragStartWidth.value + deltaX + + // 设置最小和最大宽度限制 + const minWidth = 200 + const maxWidth = window.innerWidth * 0.6 + + navigatorWidth.value = Math.max(minWidth, Math.min(maxWidth, newWidth)) +} + +function stopDrag() { + isDragging.value = false + document.removeEventListener('mousemove', handleDrag) + document.removeEventListener('mouseup', stopDrag) + document.removeEventListener('selectstart', preventSelect) + + document.body.style.cursor = '' + document.body.style.userSelect = '' + ;(document.body.style as any).webkitUserSelect = '' + ;(document.body.style as any).mozUserSelect = '' +} + // 外层DIV大小控制 const scrollStyle = computed(() => { return appMode @@ -219,8 +277,14 @@ const fileListStyle = computed(() => { :items="fileListItems" :endpoints="endpoints" :axios="axios" + :style="{ width: `${navigatorWidth}px`, minWidth: `${navigatorWidth}px` }" @navigate="pathChanged" /> + +
+
+ mdi-drag-vertical +
{ :sort="sort" :listStyle="fileListStyle" :showTree="showDirTree" + :style="{ flex: 1 }" @pathchanged="pathChanged" @loading="loadingChanged" @refreshed="refreshPending = false" @@ -243,3 +308,64 @@ const fileListStyle = computed(() => { + +