修复: 添加自动同步用户配置功能,解决管理员修改权限后用户不自动更新的问题

- 添加profileCheckInterval属性用于存储定时器ID
- 修改loadUserProfile()函数,检测存储配置变更并通知用户
- 新增startProfileSync()方法,每30秒自动检查配置更新
- 新增stopProfileSync()方法,停止定期检查
- 在登录和页面加载时启动定期检查
- 在登出时停止定期检查
- 当管理员修改用户存储权限或类型时,用户会收到Toast通知并自动刷新文件列表

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
WanWanYun
2025-11-12 09:25:17 +08:00
parent 175087c894
commit 28beee695a

View File

@@ -168,7 +168,10 @@ createApp({
totalUserQuotas: 0, totalUserQuotas: 0,
totalUserUsed: 0, totalUserUsed: 0,
totalUsers: 0 totalUsers: 0
} },
// 定期检查用户配置更新的定时器
profileCheckInterval: null
}; };
}, },
@@ -292,6 +295,8 @@ handleDragLeave(e) {
console.log('[登录] 存储权限:', this.storagePermission, '存储类型:', this.storageType); console.log('[登录] 存储权限:', this.storagePermission, '存储类型:', this.storageType);
// 启动定期检查用户配置
this.startProfileSync();
// 管理员直接跳转到管理后台 // 管理员直接跳转到管理后台
if (this.user.is_admin) { if (this.user.is_admin) {
this.currentView = 'admin'; this.currentView = 'admin';
@@ -597,6 +602,9 @@ handleDragLeave(e) {
this.token = null; this.token = null;
localStorage.removeItem('token'); localStorage.removeItem('token');
localStorage.removeItem('user'); localStorage.removeItem('user');
// 停止定期检查
this.stopProfileSync();
}, },
// 检查本地存储的登录状态 // 检查本地存储的登录状态
@@ -620,6 +628,8 @@ handleDragLeave(e) {
// 加载最新的用户信息(异步更新) // 加载最新的用户信息(异步更新)
this.loadUserProfile(); this.loadUserProfile();
// 启动定期检查用户配置
this.startProfileSync();
// 管理员跳转到管理后台 // 管理员跳转到管理后台
if (this.user.is_admin) { if (this.user.is_admin) {
this.currentView = 'admin'; this.currentView = 'admin';
@@ -1471,17 +1481,64 @@ handleDragLeave(e) {
if (response.data.success && response.data.user) { if (response.data.success && response.data.user) {
const user = response.data.user; const user = response.data.user;
// 检测存储配置是否被管理员更改
const oldStorageType = this.storageType;
const oldStoragePermission = this.storagePermission;
const newStorageType = user.current_storage_type || 'sftp';
const newStoragePermission = user.storage_permission || 'sftp_only';
// 更新本地数据
this.localQuota = user.local_storage_quota || 0; this.localQuota = user.local_storage_quota || 0;
this.localUsed = user.local_storage_used || 0; this.localUsed = user.local_storage_used || 0;
this.storagePermission = user.storage_permission || 'sftp_only'; this.storagePermission = newStoragePermission;
this.storageType = user.current_storage_type || 'sftp'; this.storageType = newStorageType;
// 如果存储类型被管理员更改,通知用户并重新加载文件
if (oldStorageType !== newStorageType || oldStoragePermission !== newStoragePermission) {
console.log('[存储配置更新] 旧类型:', oldStorageType, '新类型:', newStorageType);
console.log('[存储配置更新] 旧权限:', oldStoragePermission, '新权限:', newStoragePermission);
this.showToast('info', '存储配置已更新', `管理员已将您的存储方式更改为${newStorageType === 'local' ? '本地存储' : 'SFTP存储'}`);
// 如果当前在文件页面,重新加载文件列表
if (this.currentView === 'files') {
await this.loadFiles(this.currentPath);
}
}
} }
} catch (error) { } catch (error) {
console.error('加载用户资料失败:', error); console.error('加载用户资料失败:', error);
} }
}, },
// 用户切换存储方式 // 启动定期检查用户配置
startProfileSync() {
// 清除已有的定时器
if (this.profileCheckInterval) {
clearInterval(this.profileCheckInterval);
}
// 每30秒检查一次用户配置是否有更新
this.profileCheckInterval = setInterval(() => {
if (this.isLoggedIn && this.token) {
this.loadUserProfile();
}
}, 30000); // 30秒
console.log('[配置同步] 已启动定期检查30秒间隔');
},
// 停止定期检查
stopProfileSync() {
if (this.profileCheckInterval) {
clearInterval(this.profileCheckInterval);
this.profileCheckInterval = null;
console.log('[配置同步] 已停止定期检查');
}
},
// 用户切换存储方式
async switchStorage(type) { async switchStorage(type) {
// 检查是否尝试切换到SFTP但未配置 // 检查是否尝试切换到SFTP但未配置
if (type === 'sftp' && !this.user.has_ftp_config) { if (type === 'sftp' && !this.user.has_ftp_config) {