feat:新增页面退出登录的逻辑

This commit is contained in:
Roe-xin
2026-01-14 18:32:53 +08:00
parent 606f757699
commit 73a1510de4
3 changed files with 48 additions and 6 deletions

View File

@ -157,12 +157,8 @@ export function activate(context: vscode.ExtensionContext) {
try { try {
const session = await vscode.authentication.getSession("iccoder", [], { createIfNone: false }); const session = await vscode.authentication.getSession("iccoder", [], { createIfNone: false });
if (session) { if (session) {
// 通过创建新会话并清除偏好来实现登出 // 调用 authProvider 的 removeSession 方法
await vscode.authentication.getSession("iccoder", [], { await authProvider.removeSession(session.id);
clearSessionPreference: true,
forceNewSession: true
});
vscode.window.showInformationMessage("已退出登录");
} else { } else {
vscode.window.showInformationMessage("当前未登录"); vscode.window.showInformationMessage("当前未登录");
} }

View File

@ -340,6 +340,10 @@ export async function showICHelperPanel(
}); });
} }
break; break;
case "logout":
// 退出登录
vscode.commands.executeCommand("ic-coder.logout");
break;
// 处理计划操作(只做模式切换,响应已通过 submitAnswer 发送) // 处理计划操作(只做模式切换,响应已通过 submitAnswer 发送)
case "planAction": case "planAction":
if (message.action === "confirm") { if (message.action === "confirm") {

View File

@ -30,6 +30,9 @@ export function getUserInfoComponentContent(): string {
<span class="detail-label">剩余 Credits</span> <span class="detail-label">剩余 Credits</span>
<span class="detail-value" id="creditsDetail">-</span> <span class="detail-value" id="creditsDetail">-</span>
</div> </div>
<div class="logout">
<button class="logout-btn" id="logoutBtn">退出登录</button>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -180,6 +183,31 @@ export function getUserInfoComponentStyles(): string {
object-fit: contain; object-fit: contain;
border-radius: 4px; border-radius: 4px;
} }
.logout {
margin-top: 8px;
}
.logout-btn {
width: 100%;
padding: 8px 12px;
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 12px;
font-weight: 500;
transition: all 0.2s ease;
}
.logout-btn:hover {
background: var(--vscode-button-hoverBackground);
}
.logout-btn:active {
transform: scale(0.98);
}
`; `;
} }
@ -214,6 +242,12 @@ export function getUserInfoComponentScript(): string {
} }
} }
// 退出登录
function logout() {
console.log("退出登录");
vscode.postMessage({ command: 'logout' });
}
// 关闭用户详情下拉面板 // 关闭用户详情下拉面板
function closeUserDetailModal() { function closeUserDetailModal() {
const dropdown = document.getElementById('userDetailDropdown'); const dropdown = document.getElementById('userDetailDropdown');
@ -275,6 +309,14 @@ export function getUserInfoComponentScript(): string {
// 绑定下拉面板事件 // 绑定下拉面板事件
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// 绑定退出登录按钮
const logoutBtn = document.getElementById('logoutBtn');
if (logoutBtn) {
logoutBtn.addEventListener('click', () => {
logout();
});
}
// 点击页面其他地方关闭下拉面板 // 点击页面其他地方关闭下拉面板
document.addEventListener('click', (e) => { document.addEventListener('click', (e) => {
const dropdown = document.getElementById('userDetailDropdown'); const dropdown = document.getElementById('userDetailDropdown');