diff --git a/src/views/reorganize/FileBrowserView.vue b/src/views/reorganize/FileBrowserView.vue index 8f2add83..ca771508 100644 --- a/src/views/reorganize/FileBrowserView.vue +++ b/src/views/reorganize/FileBrowserView.vue @@ -36,17 +36,38 @@ const path: Ref = ref() // 下载目录列表 const downloadDirectories = ref([]) +// 计算公共路径 +function findCommonPath(paths: string[]): string { + if (!paths || paths.length === 0) return '' + if (paths.length === 1) return paths[0] + const normalizedPaths = paths.map(path => path.replace(/\\/g, '/')) + const splitPaths = normalizedPaths.map(path => path.split('/')) + let commonParts: string[] = [] + for (let i = 0; i < splitPaths[0].length; i++) { + const part = splitPaths[0][i] + if (splitPaths.every(pathParts => pathParts[i] === part)) { + commonParts.push(part) + } else { + break + } + } + let commonPath = commonParts.join('/') + if (commonPath.includes(':')) { + commonPath = commonPath.replace('/', '\\') + } + if (!commonPath.endsWith('/')) { + commonPath += '/' + } + return commonPath.length > 0 ? commonPath : paths[0][0] === '/' ? '/' : '' +} + // 查询下载目录 async function loadDownloadDirectories() { try { const result: { [key: string]: any } = await api.get('system/setting/DownloadDirectories') if (result.success && result.data?.value) { downloadDirectories.value = result.data.value - if (downloadDirectories.value.length > 0) { - path.value = downloadDirectories.value[downloadDirectories.value.length - 1].path - } else { - path.value = '/' - } + path.value = findCommonPath(downloadDirectories.value.map(item => item.path) as string[]) } } catch (error) { console.log(error)