From 8845d9170c82d7700dfed38eca17cefff19e7fd7 Mon Sep 17 00:00:00 2001 From: wangyuzhan Date: Fri, 21 Nov 2025 12:33:04 +0800 Subject: [PATCH] update web dataset file --- trainer_web/static/js/app.js | 13 +++++++++++-- trainer_web/train_web_ui.py | 11 +++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/trainer_web/static/js/app.js b/trainer_web/static/js/app.js index aa5d778..133e6c1 100644 --- a/trainer_web/static/js/app.js +++ b/trainer_web/static/js/app.js @@ -99,7 +99,11 @@ function confirmFileSelection() { } function navigateToParent() { - if (currentBrowsePath !== './') { + if (window.currentParentPath) { + // 使用后端提供的父目录路径(绝对路径) + browsePath(window.currentParentPath); + } else if (currentBrowsePath && currentBrowsePath !== './') { + // 回退到基于当前路径的计算 const parentPath = currentBrowsePath.includes('/') ? currentBrowsePath.substring(0, currentBrowsePath.lastIndexOf('/')) : './'; browsePath(parentPath || './'); @@ -141,7 +145,6 @@ async function browsePath(path) { try { currentBrowsePath = path; selectedFilePath = null; // 重置选中的文件路径 - document.getElementById('current-path').textContent = path; document.getElementById('selected-path').value = ''; // 清空显示 // 更新帮助文本 @@ -172,6 +175,12 @@ function renderFileList(data) { return; } + // 更新当前路径显示(使用相对路径用于显示) + document.getElementById('current-path').textContent = data.relative_path || data.current_path; + + // 存储父目录路径供导航使用 + window.currentParentPath = data.parent; + // 先显示目录,再显示文件 const directories = data.items.filter(item => item.type === 'directory'); const files = data.items.filter(item => item.type === 'file'); diff --git a/trainer_web/train_web_ui.py b/trainer_web/train_web_ui.py index 5d9043d..533c00d 100644 --- a/trainer_web/train_web_ui.py +++ b/trainer_web/train_web_ui.py @@ -371,7 +371,8 @@ def browse_files(): stat = os.stat(item_path) items.append({ 'name': item, - 'path': os.path.relpath(item_path, project_root), + 'path': item_path, # 返回绝对路径 + 'relative_path': os.path.relpath(item_path, project_root), # 同时返回相对路径用于显示 'type': 'directory' if os.path.isdir(item_path) else 'file', 'size': stat.st_size if os.path.isfile(item_path) else 0, 'modified': time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stat.st_mtime)) @@ -381,10 +382,11 @@ def browse_files(): continue return jsonify({ - 'current_path': os.path.relpath(full_path, project_root), + 'current_path': full_path, # 返回绝对路径 + 'relative_path': os.path.relpath(full_path, project_root), # 相对路径用于显示 'absolute_path': full_path, 'items': items, - 'parent': os.path.relpath(os.path.dirname(full_path), project_root) if full_path != project_root else None + 'parent': os.path.dirname(full_path) if full_path != project_root else None }) except (OSError, PermissionError) as e: return jsonify({'error': f'无法访问目录: {str(e)}', 'path': path}) @@ -394,7 +396,8 @@ def browse_files(): stat = os.stat(full_path) return jsonify({ 'name': os.path.basename(full_path), - 'path': os.path.relpath(full_path, project_root), + 'path': full_path, # 返回绝对路径 + 'relative_path': os.path.relpath(full_path, project_root), # 相对路径用于显示 'type': 'file', 'size': stat.st_size, 'modified': time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stat.st_mtime))