修复了待办事项在切换用户时有数据残留的问题

This commit is contained in:
jinchao 2025-05-13 09:58:11 +08:00
parent 0165c5c6ef
commit 98a1051611
2 changed files with 22 additions and 3 deletions

View File

@ -29,9 +29,8 @@ class TodoComponent extends HTMLElement {
return; return;
} }
if (this.isInitialized) { // 先清除所有数据
return; this.clearData();
}
TodoComponent.isInitializing = true; TodoComponent.isInitializing = true;
@ -1047,6 +1046,19 @@ class TodoComponent extends HTMLElement {
connectedCallback() { connectedCallback() {
this.initialize(); this.initialize();
} }
// 清除所有数据
clearData() {
this.todos = [];
this.selectedProject = null;
this.selectedSubproject = null;
this.expandedProjects = new Set();
this.users = [];
this.currentUser = null;
this.editingTodo = null;
this.isInitialized = false;
this.showCompleted = true;
}
} }
customElements.define('todo-component', TodoComponent); customElements.define('todo-component', TodoComponent);

View File

@ -413,6 +413,7 @@
localStorage.removeItem('userInfo'); localStorage.removeItem('userInfo');
// 清除所有标签页 // 清除所有标签页
tabsContainer.clearAllTabs(); tabsContainer.clearAllTabs();
// 显示退出成功提示 // 显示退出成功提示
showToast('已安全退出登录'); showToast('已安全退出登录');
@ -689,6 +690,12 @@
detail: { user: result.user } detail: { user: result.user }
}); });
document.dispatchEvent(loginSuccessEvent); document.dispatchEvent(loginSuccessEvent);
// 重新初始化todo-component
const todoComponent = document.querySelector('todo-component');
if (todoComponent) {
todoComponent.initialize();
}
} else { } else {
showToast(result.message || '登录失败,请检查用户名和密码'); showToast(result.message || '登录失败,请检查用户名和密码');
} }