✨ 新增视图记忆功能,优化用户体验
功能新增: - 自动记住用户上次停留的视图(文件/分享/设置/管理) - 下次登录时恢复到上次的视图位置 - 登出时清理视图记录 安全优化: - 新增 isViewAllowed() 方法,验证视图权限 - 防止普通用户越权访问管理后台 - 只记录合法且有权限的视图 代码优化: - 简化登录后的视图跳转逻辑 - switchView() 支持 force 参数,用于强制刷新 - 统一视图切换和权限检查流程 用户体验提升: - 减少重复导航,直达上次工作位置 - 管理员可以记住后台页面位置 - 更加智能和人性化 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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('/');
|
||||
// 读取上次停留的视图(需合法才生效)
|
||||
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 {
|
||||
this.currentView = 'settings';
|
||||
}
|
||||
} else {
|
||||
// 默认加载文件
|
||||
this.loadFiles('/');
|
||||
}
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user