登出功能实现
This commit is contained in:
@@ -95,7 +95,8 @@ import {
|
|||||||
BellOutlined,
|
BellOutlined,
|
||||||
QuestionCircleOutlined
|
QuestionCircleOutlined
|
||||||
} from '@ant-design/icons-vue'
|
} 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()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -169,8 +170,28 @@ const handleMenuClick = (key: string) => {
|
|||||||
|
|
||||||
// 处理退出登录
|
// 处理退出登录
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
console.log('退出登录被点击')
|
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('已退出登录')
|
message.success('已退出登录')
|
||||||
|
// 跳转到登录页面
|
||||||
|
router.push('/auth')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理设置图标点击
|
// 处理设置图标点击
|
||||||
|
|||||||
Reference in New Issue
Block a user