diff --git a/frontend/app.js b/frontend/app.js index 2e7e288..51fcf77 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -790,6 +790,7 @@ handleDragLeave(e) { this.token = null; localStorage.removeItem('token'); localStorage.removeItem('user'); + localStorage.removeItem('lastView'); this.showResendVerify = false; this.resendVerifyEmail = ''; @@ -820,28 +821,21 @@ handleDragLeave(e) { // 启动定期检查用户配置 this.startProfileSync(); - // 管理员跳转到管理后台 - if (this.user.is_admin) { - this.currentView = 'admin'; - } - // 普通用户:根据存储权限决定跳转 - else { - // 如果用户可以使用本地存储,直接加载文件 - if (this.storagePermission === 'local_only' || this.storagePermission === 'user_choice') { - this.loadFiles('/'); - } - // 如果仅SFTP模式,需要检查是否配置了SFTP - else if (this.storagePermission === 'sftp_only') { - if (this.user.has_ftp_config) { - this.loadFiles('/'); - } else { - this.currentView = 'settings'; - } - } else { - // 默认加载文件 - this.loadFiles('/'); - } + // 读取上次停留的视图(需合法才生效) + const savedView = localStorage.getItem('lastView'); + let targetView = null; + if (savedView && this.isViewAllowed(savedView)) { + targetView = savedView; + } else if (this.user.is_admin) { + targetView = 'admin'; + } else if (this.storagePermission === 'sftp_only' && !this.user.has_ftp_config) { + targetView = 'settings'; + } else { + targetView = 'files'; } + + // 强制切换到目标视图并加载数据 + this.switchView(targetView, true); } }, @@ -1155,7 +1149,7 @@ handleDragLeave(e) { ? `/${file.name}` : `${this.currentPath}/${file.name}`; - // SFTP存储且配置了HTTP下载URL,使用HTTP直接访问 + // SFTP存储且配置了HTTP下载URL,使用HTTP直接访问;否则使用API下载 if (file.httpDownloadUrl) { return file.httpDownloadUrl; } @@ -1914,10 +1908,23 @@ handleDragLeave(e) { this.showSftpConfigModal = false; }, + // 检查视图权限 + isViewAllowed(view) { + if (!this.isLoggedIn) return false; + const commonViews = ['files', 'shares', 'settings']; + if (view === 'admin') { + return !!(this.user && this.user.is_admin); + } + return commonViews.includes(view); + }, + // 切换视图并自动刷新数据 - switchView(view) { + switchView(view, force = false) { + if (this.isLoggedIn && !this.isViewAllowed(view)) { + return; + } // 如果已经在当前视图,不重复刷新 - if (this.currentView === view) { + if (!force && this.currentView === view) { return; } @@ -2321,6 +2328,11 @@ handleDragLeave(e) { // 普通用户进入设置页面时加载SFTP配置 this.loadFtpConfig(); } + + // 记住最后停留的视图(需合法且已登录) + if (this.isLoggedIn && this.isViewAllowed(newView)) { + localStorage.setItem('lastView', newView); + } } } }).mount('#app');