Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat: Implement logout functionality with API integration

wizardchen30a711ea2f48
diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue
index 97e626b83..913b27c75 100644
--- a/frontend/src/components/UserMenu.vue
+++ b/frontend/src/components/UserMenu.vue
@@ -47,11 +47,13 @@
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUIStore } from '@/stores/ui'
+import { useAuthStore } from '@/stores/auth'
import { MessagePlugin } from 'tdesign-vue-next'
-import { getCurrentUser } from '@/api/auth'
+import { getCurrentUser, logout as logoutApi } from '@/api/auth'
const router = useRouter()
const uiStore = useUIStore()
+const authStore = useAuthStore()
const menuRef = ref<HTMLElement>()
const menuVisible = ref(false)
@@ -99,11 +101,19 @@ const handleSettings = () => {
}
// 注销
-const handleLogout = () => {
+const handleLogout = async () => {
menuVisible.value = false
- // 清理本地存储
- localStorage.removeItem('WeKnora_token')
+ try {
+ // 调用后端API注销
+ await logoutApi()
+ } catch (error) {
+ // 即使API调用失败,也继续执行本地清理
+ console.error('注销API调用失败:', error)
+ }
+
+ // 清理所有状态和本地存储
+ authStore.logout()
MessagePlugin.success('已退出登录')
diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue
index 4fb84d81e..4cd9a29ae 100644
--- a/frontend/src/components/menu.vue
+++ b/frontend/src/components/menu.vue
@@ -57,7 +57,7 @@
@click="gotopage(subitem.path)">
<i v-if="currentSecondpath == subitem.path" class="dot"></i>
<span class="submenu_title"
- :style="currentSecondpath == subitem.path ? 'margin-left:14px;max-width:160px;' : 'margin-left:18px;max-width:173px;'">
+ :style="currentSecondpath == subitem.path ? 'margin-left:14px;max-width:160px;' : 'margin-left:18px;max-width:185px;'">
{{ subitem.title }}
</span>
<t-dropdown
@@ -93,6 +93,7 @@ import { onMounted, watch, computed, ref, reactive, nextTick } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { getSessionsList, delSession } from "@/api/chat/index";
import { getKnowledgeBaseById, listKnowledgeBases, uploadKnowledgeFile } from '@/api/knowledge-base';
+import { logout as logoutApi } from '@/api/auth';
import { kbFileTypeVerification } from '@/utils/index';
import { useMenuStore } from '@/stores/menu';
import { useAuthStore } from '@/stores/auth';
@@ -550,7 +551,16 @@ const gotopage = async (path: string) => {
pathPrefix.value = path;
// 处理退出登录
if (path === 'logout') {
+ try {
+ // 调用后端API注销
+ await logoutApi();
+ } catch (error) {
+ // 即使API调用失败,也继续执行本地清理
+ console.error('注销API调用失败:', error);
+ }
+ // 清理所有状态和本地存储
authStore.logout();
+ MessagePlugin.success('已退出登录');
router.push('/login');
return;
} else {
@@ -830,7 +840,7 @@ watch(() => route.params.kbId, () => {
.submenu_item_p {
height: 44px;
- padding: 4px 8px 4px 0px;
+ padding: 4px 0px 4px 0px;
box-sizing: border-box;
}