fix: 对接登出
This commit is contained in:
@@ -10,3 +10,10 @@ export const login = (params: { phone: string; password: string }) => {
|
|||||||
data: LoginResult;
|
data: LoginResult;
|
||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const logout = () => {
|
||||||
|
return post(`/op/logout`) as Promise<{
|
||||||
|
code: number | string;
|
||||||
|
msg: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { usePermissionStore } from '@/stores/permissionStore';
|
|||||||
import { useTabsStore } from '@/stores/tabsStore';
|
import { useTabsStore } from '@/stores/tabsStore';
|
||||||
import { useUserStore } from '@/stores/userStore';
|
import { useUserStore } from '@/stores/userStore';
|
||||||
import { clearAuthDataCache } from '@/api/authCache';
|
import { clearAuthDataCache } from '@/api/authCache';
|
||||||
|
import { logout as logoutApi } from '@/api/login';
|
||||||
import router from '@/router';
|
import router from '@/router';
|
||||||
|
|
||||||
const TOKEN_KEY = 'MY_APP_AUTH_TOKEN';
|
const TOKEN_KEY = 'MY_APP_AUTH_TOKEN';
|
||||||
@@ -66,9 +67,14 @@ function createAuth() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出:清除 token → 清除菜单+权限 → 清除动态路由 → 跳转登录页
|
* 退出:调用登出接口 → 清除 token → 清除菜单+权限 → 清除动态路由 → 跳转登录页
|
||||||
*/
|
*/
|
||||||
const logout = () => {
|
const logout = async () => {
|
||||||
|
try {
|
||||||
|
await logoutApi();
|
||||||
|
} catch {
|
||||||
|
// 即使接口失败也要继续清除本地会话
|
||||||
|
}
|
||||||
clearSession();
|
clearSession();
|
||||||
router.push('/login');
|
router.push('/login');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,8 +113,6 @@ export default defineComponent({
|
|||||||
okText: '确认',
|
okText: '确认',
|
||||||
cancelText: '取消',
|
cancelText: '取消',
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
const { clearUser } = useUserStore();
|
|
||||||
clearUser();
|
|
||||||
auth.logout();
|
auth.logout();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user