这是基于vue-vben-admin 模板适用于abp vNext的前端管理项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.3 KiB

/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { Notification as NotificationInfo } from '@abp/notifications';
import { onMounted, onUnmounted } from 'vue';
import { useAbpStore, useEventBus } from '@abp/core';
import { NotificationNames, useNotifications } from '@abp/notifications';
import { Modal } from 'ant-design-vue';
import { useAuthStore } from '#/store';
export function useSessions() {
const authStore = useAuthStore();
const abpStore = useAbpStore();
const { subscribe, unSubscribe } = useEventBus();
const { register, release } = useNotifications();
function _register() {
subscribe(NotificationNames.SessionExpiration, _onSessionExpired);
register();
}
function _release() {
unSubscribe(NotificationNames.SessionExpiration, _onSessionExpired);
release();
}
/** 处理会话过期事件 */
function _onSessionExpired(event?: NotificationInfo) {
const { data, title, message } = event!;
const sessionId = data.SessionId;
if (sessionId === abpStore.application?.currentUser?.sessionId) {
_release();
Modal.confirm({
iconType: 'warning',
title,
content: message,
centered: true,
afterClose: () => {
authStore.logout();
},
});
}
}
onMounted(_register);
onUnmounted(_release);
}