This commit is contained in:
Baobhan Sith
2025-04-19 19:11:32 +08:00
parent 15223d1f31
commit ce96861eb6
2 changed files with 14 additions and 6 deletions
@@ -1133,7 +1133,7 @@ const handleWheel = (event: WheelEvent) => {
<!-- 按钮移到 path-bar 外面 -->
<div class="path-actions"> <!-- 新增包裹容器 -->
<!-- 恢复使用 props.sftpManager.isLoading props.wsDeps.isConnected.value -->
<button class="toolbar-button" @click.stop="loadDirectory(currentPath)" :disabled="isLoading || !props.wsDeps.isConnected.value || isEditingPath" :title="t('fileManager.actions.refresh')"><i class="fas fa-sync-alt"></i></button>
<button class="toolbar-button" @click.stop="loadDirectory(currentPath, true)" :disabled="isLoading || !props.wsDeps.isConnected.value || isEditingPath" :title="t('fileManager.actions.refresh')"><i class="fas fa-sync-alt"></i></button> <!-- 添加 true 参数以强制刷新 -->
<!-- 恢复使用 props.sftpManager.isLoading props.wsDeps.isConnected.value -->
<button class="toolbar-button" @click.stop="handleItemClick($event, { filename: '..', longname: '..', attrs: { isDirectory: true, isFile: false, isSymbolicLink: false, size: 0, uid: 0, gid: 0, mode: 0, atime: 0, mtime: 0 } })" :disabled="isLoading || !props.wsDeps.isConnected.value || currentPath === '/' || isEditingPath" :title="t('fileManager.actions.parentDirectory')"><i class="fas fa-arrow-up"></i></button>
<!-- 修改后的搜索区域 -->
@@ -189,21 +189,29 @@ export function createSftpActionsManager(
return currentNode; // Return the final node found or created
};
const loadDirectory = (path: string) => {
const loadDirectory = (path: string, forceRefresh: boolean = false) => { // 添加 forceRefresh 参数
// *** 修改:检查文件树 ***
const targetNode = findNodeByPath(fileTree, path);
if (targetNode && targetNode.childrenLoaded) {
if (targetNode && targetNode.childrenLoaded && !forceRefresh) { // 检查 forceRefresh
console.log(`[SFTP ${instanceSessionId}] 使用文件树缓存加载目录: ${path}`);
// fileList 将通过 computed 属性更新,这里只需更新 currentPathRef
isLoading.value = false;
currentPathRef.value = path;
return; // 子节点已加载,无需请求
return; // 子节点已加载且非强制刷新,无需请求
}
// If node doesn't exist or children not loaded, proceed to fetch from backend.
// If node doesn't exist, children not loaded, or forceRefresh is true, proceed to fetch from backend.
// The onSftpReaddirSuccess handler will manage adding/updating the node in the tree.
// 如果是强制刷新且节点存在,重置其加载状态
if (forceRefresh && targetNode) {
console.log(`[SFTP ${instanceSessionId}] 强制刷新,重置节点 ${path} 的 childrenLoaded 状态`);
targetNode.childrenLoaded = false;
// 可选:如果需要立即清除旧数据,可以设置 targetNode.children = null;
// targetNode.children = null;
}
if (!isSftpReady.value) {
// 使用通知 store 显示错误
uiNotificationsStore.showError(t('fileManager.errors.sftpNotReady'), { timeout: 5000 }); // 使用 uiNotificationsStore
@@ -219,7 +227,7 @@ export function createSftpActionsManager(
return;
}
console.log(`[SFTP ${instanceSessionId}] 正在加载目录: ${path}`); // 日志改为中文
console.log(`[SFTP ${instanceSessionId}] ${forceRefresh ? '强制' : ''}加载目录: ${path}`); // 日志改为中文,并标明是否强制
isLoading.value = true;
// error.value = null; // 不再需要
currentPathRef.value = path; // 更新外部 ref