From 039752419bd0260f3d44ad40d9267b4e58dea44f Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 13 May 2025 19:33:04 +0800 Subject: [PATCH] Add User Card and Logout Button to Sidebar (#1405) * feat: add user card and logout button to sidebar Co-Authored-By: Junyan Qin * feat: add test code to set dummy values in localStorage Co-Authored-By: Junyan Qin * style: fix formatting issues in HomeSidebar.tsx Co-Authored-By: Junyan Qin * style: fix whitespace in HomeSidebar.tsx Co-Authored-By: Junyan Qin * perf: styles of logout button * fix: lint errors * fix: lint errors --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Junyan Qin --- .../home-sidebar/HomeSidebar.module.css | 14 +++++-- .../components/home-sidebar/HomeSidebar.tsx | 42 ++++++++++++------- web/src/app/login/page.tsx | 1 + 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/web/src/app/home/components/home-sidebar/HomeSidebar.module.css b/web/src/app/home/components/home-sidebar/HomeSidebar.module.css index c1ac4ff8..5cf2a505 100644 --- a/web/src/app/home/components/home-sidebar/HomeSidebar.module.css +++ b/web/src/app/home/components/home-sidebar/HomeSidebar.module.css @@ -8,6 +8,7 @@ align-items: flex-start; justify-content: space-between; padding-block: 1rem; + padding-left: 0.4rem; user-select: none; /* box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.1); */ } @@ -54,13 +55,18 @@ flex-direction: column; align-items: center; justify-content: center; - gap: 0.5rem; + gap: 0.8rem; +} + +.sidebarItemsContainer { + display: flex; + flex-direction: column; + gap: 0.8rem; } .sidebarChildContainer { width: 9rem; height: 3rem; - margin: 0.8rem 0; padding-left: 1.6rem; font-size: 1rem; border-radius: 12px; @@ -70,6 +76,7 @@ justify-content: flex-start; cursor: pointer; gap: 0.5rem; + /* background-color: aqua; */ } .sidebarSelected { @@ -90,11 +97,12 @@ .sidebarBottomContainer { width: 100%; - height: 100px; display: flex; flex-direction: column; align-items: center; justify-content: center; + margin-top: auto; + padding-bottom: 1rem; } .sidebarBottomChildContainer { diff --git a/web/src/app/home/components/home-sidebar/HomeSidebar.tsx b/web/src/app/home/components/home-sidebar/HomeSidebar.tsx index d9752c3a..ff3edc47 100644 --- a/web/src/app/home/components/home-sidebar/HomeSidebar.tsx +++ b/web/src/app/home/components/home-sidebar/HomeSidebar.tsx @@ -30,6 +30,10 @@ export default function HomeSidebar({ useEffect(() => { console.log('HomeSidebar挂载完成'); initSelect(); + if (!localStorage.getItem('token')) { + localStorage.setItem('token', 'test-token'); + localStorage.setItem('userEmail', 'test@example.com'); + } return () => console.log('HomeSidebar卸载'); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -77,6 +81,12 @@ export default function HomeSidebar({ } } + function handleLogout() { + localStorage.removeItem('token'); + localStorage.removeItem('userEmail'); + window.location.href = '/login'; + } + return (
@@ -97,7 +107,7 @@ export default function HomeSidebar({
{/* 菜单列表,后期可升级成配置驱动 */} -
+
{sidebarConfigList.map((config) => { return (
- {/* {}} - isSelected={false} - icon={ - - - - } - name="系统设置" - /> */} { // open docs.langbot.app @@ -154,6 +150,22 @@ export default function HomeSidebar({ } name="帮助文档" /> + { + handleLogout(); + }} + isSelected={false} + icon={ + + + + } + name="退出登录" + />
); diff --git a/web/src/app/login/page.tsx b/web/src/app/login/page.tsx index 297f8b83..8eb4dd54 100644 --- a/web/src/app/login/page.tsx +++ b/web/src/app/login/page.tsx @@ -82,6 +82,7 @@ export default function Login() { .authUser(username, password) .then((res) => { localStorage.setItem('token', res.token); + localStorage.setItem('userEmail', username); console.log('login success: ', res); router.push('/home'); toast.success('登录成功');