😎优化在线用户逻辑
This commit is contained in:
parent
7650895334
commit
4344f94df7
@ -39,14 +39,15 @@ public class OnlineUserHub : Hub<IOnlineUserHub>
|
|||||||
var httpContext = Context.GetHttpContext();
|
var httpContext = Context.GetHttpContext();
|
||||||
var userId = (httpContext.User.FindFirst(ClaimConst.UserId)?.Value).ToLong();
|
var userId = (httpContext.User.FindFirst(ClaimConst.UserId)?.Value).ToLong();
|
||||||
var account = httpContext.User.FindFirst(ClaimConst.Account)?.Value;
|
var account = httpContext.User.FindFirst(ClaimConst.Account)?.Value;
|
||||||
|
if (userId < 0 || string.IsNullOrWhiteSpace(account)) return;
|
||||||
|
|
||||||
var realName = httpContext.User.FindFirst(ClaimConst.RealName)?.Value;
|
var realName = httpContext.User.FindFirst(ClaimConst.RealName)?.Value;
|
||||||
var tenantId = (httpContext.User.FindFirst(ClaimConst.TenantId)?.Value).ToLong();
|
var tenantId = (httpContext.User.FindFirst(ClaimConst.TenantId)?.Value).ToLong();
|
||||||
var loginMode = (LoginModeEnum)(httpContext.User.FindFirst(ClaimConst.LoginMode)?.Value).ToInt();
|
var loginMode = (LoginModeEnum)(httpContext.User.FindFirst(ClaimConst.LoginMode)?.Value).ToInt();
|
||||||
loginMode = loginMode == 0 ? LoginModeEnum.PC : loginMode; // 默认PC登录模式
|
loginMode = loginMode == 0 ? LoginModeEnum.PC : loginMode; // 默认PC登录模式
|
||||||
var device = httpContext.GetClientDeviceInfo().Trim();
|
var device = httpContext.GetClientDeviceInfo().Trim();
|
||||||
var ipAddress = httpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
|
var ipAddress = httpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
|
||||||
|
|
||||||
if (userId < 0 || string.IsNullOrWhiteSpace(account)) return;
|
|
||||||
var user = new SysOnlineUser
|
var user = new SysOnlineUser
|
||||||
{
|
{
|
||||||
ConnectionId = Context.ConnectionId,
|
ConnectionId = Context.ConnectionId,
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { debounce } from 'lodash-es';
|
import { debounce } from 'lodash-es';
|
||||||
import { Local, Session } from '/@/utils/storage';
|
import { Local, Session } from '/@/utils/storage';
|
||||||
import { signalR } from '/@/views/system/onlineUser/signalR';
|
// import { signalR } from '/@/views/system/onlineUser/signalR';
|
||||||
import { ElMessageBox } from 'element-plus';
|
import { ElMessageBox } from 'element-plus';
|
||||||
import { accessTokenKey, refreshAccessTokenKey } from '/@/utils/axios-utils';
|
import { accessTokenKey, refreshAccessTokenKey } from '/@/utils/axios-utils';
|
||||||
import { i18n } from '/@/i18n';
|
import { i18n } from '/@/i18n';
|
||||||
@ -113,7 +113,7 @@ class IdleTimeoutManager {
|
|||||||
const appEl = document.getElementById('app')!;
|
const appEl = document.getElementById('app')!;
|
||||||
appEl?.remove();
|
appEl?.remove();
|
||||||
// 关闭连接
|
// 关闭连接
|
||||||
signalR.stop();
|
// signalR.stop();
|
||||||
|
|
||||||
// TODO: 如果要改成调用 logout 登出接口,需要调整 clearAccessTokens 会 reload 页面的问题
|
// TODO: 如果要改成调用 logout 登出接口,需要调整 clearAccessTokens 会 reload 页面的问题
|
||||||
|
|
||||||
|
|||||||
@ -112,7 +112,7 @@ const options = useVxeTable<SysOnlineUser>(
|
|||||||
{ field: 'browser', title: t('message.list.browser'), minWidth: 160, showOverflow: 'tooltip' },
|
{ field: 'browser', title: t('message.list.browser'), minWidth: 160, showOverflow: 'tooltip' },
|
||||||
// { field: 'connectionId', title: '连接Id', minWidth: 160, showOverflow: 'tooltip', sortable: true },
|
// { field: 'connectionId', title: '连接Id', minWidth: 160, showOverflow: 'tooltip', sortable: true },
|
||||||
{ field: 'time', title: t('message.list.loginTime'), minWidth: 120, showOverflow: 'tooltip' },
|
{ field: 'time', title: t('message.list.loginTime'), minWidth: 120, showOverflow: 'tooltip' },
|
||||||
{ title: t('message.list.operation'), fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
|
{ field: 'buttons', title: t('message.list.operation'), fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// vxeGrid配置参数(此处可覆写任何参数),参考vxe-table官方文档
|
// vxeGrid配置参数(此处可覆写任何参数),参考vxe-table官方文档
|
||||||
@ -133,13 +133,16 @@ onMounted(async () => {
|
|||||||
state.localPageParam = Local.get(localPageParamKey) || state.localPageParam;
|
state.localPageParam = Local.get(localPageParamKey) || state.localPageParam;
|
||||||
// 在线用户列表
|
// 在线用户列表
|
||||||
signalR.off('OnlineUserList');
|
signalR.off('OnlineUserList');
|
||||||
signalR.on('OnlineUserList', (data: any) => {
|
signalR.on('OnlineUserList', async (data: any) => {
|
||||||
state.onlineUserList = data.userList;
|
state.onlineUserList = data.userList;
|
||||||
state.lastUserState = {
|
state.lastUserState = {
|
||||||
online: data.online,
|
online: data.online,
|
||||||
realName: data.realName,
|
realName: data.realName,
|
||||||
};
|
};
|
||||||
notificationThrottle();
|
notificationThrottle();
|
||||||
|
|
||||||
|
// // 自动查询一次
|
||||||
|
// await handleQuery();
|
||||||
});
|
});
|
||||||
// 强制下线
|
// 强制下线
|
||||||
signalR.off('ForceOffline');
|
signalR.off('ForceOffline');
|
||||||
@ -155,12 +158,12 @@ onMounted(async () => {
|
|||||||
// 通知提示节流
|
// 通知提示节流
|
||||||
const notificationThrottle = throttle(
|
const notificationThrottle = throttle(
|
||||||
function () {
|
function () {
|
||||||
// ElNotification({
|
ElNotification({
|
||||||
// title: '提示',
|
title: '提示',
|
||||||
// message: `${state.lastUserState.online ? `【${state.lastUserState.realName}】上线了` : `【${state.lastUserState.realName}】离开了`}`,
|
message: `${state.lastUserState.online ? `【${state.lastUserState.realName}】上线了` : `【${state.lastUserState.realName}】离开了`}`,
|
||||||
// type: `${state.lastUserState.online ? 'info' : 'error'}`,
|
type: `${state.lastUserState.online ? 'info' : 'error'}`,
|
||||||
// position: 'bottom-right',
|
position: 'bottom-right',
|
||||||
// });
|
});
|
||||||
},
|
},
|
||||||
3000,
|
3000,
|
||||||
{
|
{
|
||||||
@ -170,9 +173,9 @@ const notificationThrottle = throttle(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 打开页面
|
// 打开页面
|
||||||
const openDrawer = () => {
|
const openDrawer = async () => {
|
||||||
state.isVisible = true;
|
state.isVisible = true;
|
||||||
handleQuery();
|
await handleQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 查询api
|
// 查询api
|
||||||
@ -189,10 +192,10 @@ const handleQuery = async (reset = false) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 重置操作
|
// 重置操作
|
||||||
const resetQuery = () => {
|
const resetQuery = async () => {
|
||||||
state.queryParams.userName = undefined;
|
state.queryParams.userName = undefined;
|
||||||
state.queryParams.realName = undefined;
|
state.queryParams.realName = undefined;
|
||||||
handleQuery();
|
await handleQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 表格事件
|
// 表格事件
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user