bug: 退出登录
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
* @desc 当前用户
|
||||
*/
|
||||
import { defaultSuccess, defaultError, http } from '@/plugins/axios';
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import { defaultSuccess, defaultError, http } from '@/plugins/axios'
|
||||
import type { AxiosResponse } from 'axios'
|
||||
export default async function (
|
||||
success: (data: auth.AuthUser) => void = defaultSuccess,
|
||||
fail: (error: { code: string; error?: string }) => void = defaultError,
|
||||
success: (data: auth.AuthUser) => void = defaultSuccess,
|
||||
fail: (error: { code: string; error?: string }) => void = defaultError,
|
||||
): Promise<void> {
|
||||
return http({
|
||||
method: 'get',
|
||||
url: `/auth/current-user`,
|
||||
})
|
||||
.then((data: AxiosResponse<auth.AuthUser, unknown>) => {
|
||||
success(data.data);
|
||||
})
|
||||
.catch((error: { code: string; error?: string }) => fail(error));
|
||||
return http({
|
||||
method: 'get',
|
||||
url: `/auth/current-user`,
|
||||
})
|
||||
.then((data: AxiosResponse<auth.AuthUser, unknown>) => {
|
||||
success(data.data)
|
||||
})
|
||||
.catch((error: { code: string; error?: string }) => fail(error))
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
import { config } from '@/settings/application'
|
||||
import { MenuInfo } from 'ant-design-vue/es/menu/src/interface'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import api from '@/api'
|
||||
const t = useI18n()
|
||||
const user = useUserStore()
|
||||
|
||||
@@ -85,7 +86,9 @@
|
||||
icon: createVNode(ExclamationCircleOutlined),
|
||||
content: createVNode('div', { style: 'color:red;' }, '确定退出系统吗?'),
|
||||
onOk() {
|
||||
user.logout()
|
||||
api.authApi.auth.logout(() => {
|
||||
user.logout()
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -101,7 +101,6 @@ export const routes: Array<RouteRecordRaw> = [
|
||||
|
||||
const getNewRouter = () => {
|
||||
// TODO 用户store判断是否登录,登录就返回过滤的,没有登录就返回全量
|
||||
|
||||
return createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
|
||||
@@ -18,6 +18,12 @@ export const useUserStore = defineStore('user', {
|
||||
isAdmin(state) {
|
||||
return state.roles.includes('admin')
|
||||
},
|
||||
isLogin(state) {
|
||||
return state.token && state.refreshToken
|
||||
},
|
||||
getPermission(state) {
|
||||
return state.permissions
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
refreshUserInfo(user: auth.AuthUser) {
|
||||
|
||||
Reference in New Issue
Block a user