Browse Source

feat: 去掉右上角的“退出”按钮以及事件

zhangwl 1 month ago
parent
commit
c49cc3dfb9
1 changed files with 42 additions and 43 deletions
  1. 42 43
      chat-ai-ui-main/src/components/Header.vue

+ 42 - 43
chat-ai-ui-main/src/components/Header.vue

@@ -1,54 +1,53 @@
 <script setup lang="ts">
 import { useUserStore } from '../stores/user';
 import { useChatStore } from '../stores/chat';
-import { useRouter } from 'vue-router';
 import robotImage from '../assets/robot.png';
-import axios from 'axios';
+
 
 const userStore = useUserStore();
 const chatStore = useChatStore();
-const router = useRouter();
-
-const logout = async () => {
-
-  if (!userStore.userId) {
-    userStore.logout();
-    router.push('/');
-    return;
-  }
-
-  try {
-    // 修正axios参数顺序:post(url, data, config)
-    const response = await axios.post(
-      `${import.meta.env.VITE_API_URL}/users/logout`,
-      {}, // 空的请求体
-      {
-        headers: {
-          'Authorization': `Bearer ${userStore.userId}`,
-          'Content-Type': 'application/json'
-        }
-      }
-    );
-
-    console.log('退出接口响应:', response.data);
-
-    // 清除用户状态
-    userStore.logout();
-
-    // 跳转到首页或登录页
-    router.push('/');
-
-    console.log('退出登录成功');
-  } catch (error: any) {
-    console.error('退出登录失败:', error);
-    console.error('状态码:', error.response?.status);
-    console.error('错误详情:', error.response?.data);
+// const router = useRouter();
 
-    // 即使后端调用失败,也要清除本地数据
-    userStore.logout();
-    router.push('/');
-  }
-};
+// const logout = async () => {
+//
+//   if (!userStore.userId) {
+//     userStore.logout();
+//     router.push('/');
+//     return;
+//   }
+//
+//   try {
+//     // 修正axios参数顺序:post(url, data, config)
+//     const response = await axios.post(
+//       `${import.meta.env.VITE_API_URL}/users/logout`,
+//       {}, // 空的请求体
+//       {
+//         headers: {
+//           'Authorization': `Bearer ${userStore.userId}`,
+//           'Content-Type': 'application/json'
+//         }
+//       }
+//     );
+//
+//     console.log('退出接口响应:', response.data);
+//
+//     // 清除用户状态
+//     userStore.logout();
+//
+//     // 跳转到首页或登录页
+//     router.push('/');
+//
+//     console.log('退出登录成功');
+//   } catch (error: any) {
+//     console.error('退出登录失败:', error);
+//     console.error('状态码:', error.response?.status);
+//     console.error('错误详情:', error.response?.data);
+//
+//     // 即使后端调用失败,也要清除本地数据
+//     userStore.logout();
+//     router.push('/');
+//   }
+// };
 </script>
 
 <template>