新增视图记忆功能,优化用户体验

功能新增:
- 自动记住用户上次停留的视图(文件/分享/设置/管理)
- 下次登录时恢复到上次的视图位置
- 登出时清理视图记录

安全优化:
- 新增 isViewAllowed() 方法,验证视图权限
- 防止普通用户越权访问管理后台
- 只记录合法且有权限的视图

代码优化:
- 简化登录后的视图跳转逻辑
- switchView() 支持 force 参数,用于强制刷新
- 统一视图切换和权限检查流程

用户体验提升:
- 减少重复导航,直达上次工作位置
- 管理员可以记住后台页面位置
- 更加智能和人性化

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-24 22:09:40 +08:00
parent 98cadb3c8b
commit 7b8b7afaf9

View File

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