登出功能实现

This commit is contained in:
xiaowang
2026-02-24 14:12:27 +08:00
parent f4f45a6d43
commit cd805632ad
+24 -3
View File
@@ -95,7 +95,8 @@ import {
BellOutlined,
QuestionCircleOutlined
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { message, Modal } from 'ant-design-vue'
import { authApi } from '@/api/auth'
const router = useRouter()
@@ -169,8 +170,28 @@ const handleMenuClick = (key: string) => {
// 处理退出登录
const handleLogout = () => {
console.log('退出登录被点击')
message.success('已退出登录')
Modal.confirm({
title: '确认退出登录',
content: '确定要退出登录吗?',
okText: '确定',
cancelText: '取消',
onOk: async () => {
try {
await authApi.logout()
} catch (error) {
console.error('登出接口调用失败:', error)
} finally {
// 清除本地存储的token
localStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
sessionStorage.removeItem('accessToken')
message.success('已退出登录')
// 跳转到登录页面
router.push('/auth')
}
}
})
}
// 处理设置图标点击