Skip to content

Commit

Permalink
用户管理新增用户在线查看功能
Browse files Browse the repository at this point in the history
  • Loading branch information
zhontai committed Dec 13, 2024
1 parent ba14fc2 commit c0b0d6a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using ZhonTai.Admin.Core.Configs;
using ZhonTai.Admin.Tools.Cache;
using ZhonTai.Common.Helpers;

namespace ZhonTai.Admin.Core.Extensions;

Expand All @@ -24,17 +21,17 @@ public static void AddIm(this IServiceCollection services)

ImHelper.Instance.OnSend += (s, e) =>
{
Console.WriteLine($"ImClient.SendMessage(server={e.Server},data={JsonHelper.Serialize(e.Message)})");
//Console.WriteLine($"ImClient.SendMessage(server={e.Server},data={JsonHelper.Serialize(e.Message)})");
};

ImHelper.EventBus(
t =>
{
Console.WriteLine(t.clientId + "上线了");
//Console.WriteLine(t.clientId + "上线了");
},
t =>
{
Console.WriteLine(t.clientId + "下线了");
//Console.WriteLine(t.clientId + "下线了");
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class UserGetPageOutput
/// </summary>
public bool Enabled { get; set; }

/// <summary>
/// 在线
/// </summary>
public bool Online { get; set; }

/// <summary>
/// 创建时间
/// </summary>
Expand Down
20 changes: 19 additions & 1 deletion src/modules/admin/ZhonTai.Admin/Services/User/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace ZhonTai.Admin.Services.User;
public partial class UserService : BaseService, IUserService, IDynamicApi
{
private readonly AppConfig _appConfig;
private readonly ImConfig _imConfig;
private readonly UserHelper _userHelper;
private readonly AdminLocalizer _adminLocalizer;
private readonly IUserRepository _userRep;
Expand All @@ -70,6 +71,7 @@ public partial class UserService : BaseService, IUserService, IDynamicApi

public UserService(
IOptions<AppConfig> appConfig,
IOptions<ImConfig> imConfig,
UserHelper userHelper,
AdminLocalizer adminLocalizer,
IUserRepository userRep,
Expand All @@ -88,6 +90,7 @@ Lazy<IPermissionRepository> permissionRep
)
{
_appConfig = appConfig.Value;
_imConfig = imConfig.Value;
_userHelper = userHelper;
_adminLocalizer = adminLocalizer;
_userRep = userRep;
Expand Down Expand Up @@ -180,9 +183,24 @@ public async Task<PageOutput<UserGetPageOutput>> GetPageAsync(PageInput<UserGetP
}
}

var userList = Mapper.Map<List<UserGetPageOutput>>(list);

if (_imConfig.Enable)
{
var clientIdList = ImHelper.GetClientListByOnline();

foreach (var user in userList)
{
if (clientIdList.Contains(user.Id))
{
user.Online = true;
}
}
}

var data = new PageOutput<UserGetPageOutput>()
{
List = Mapper.Map<List<UserGetPageOutput>>(list),
List = userList,
Total = total
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public WebSocketService(IOptions<ImConfig> imConfig)
/// <summary>
/// 获取websocket分区
/// </summary>
[Login]
[HttpPost]
public object PreConnect(WebSocketPreConnectInput input)
{
Expand Down
2 changes: 2 additions & 0 deletions ui/zhontai.ui.admin.vue3/src/api/admin/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5291,6 +5291,8 @@ export interface UserGetPageOutput {
isManager?: boolean
/** 启用 */
enabled?: boolean
/** 在线 */
online?: boolean
/**
* 创建时间
* @format date-time
Expand Down
7 changes: 6 additions & 1 deletion ui/zhontai.ui.admin.vue3/src/views/admin/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@

<el-card class="my-fill mt8" shadow="never">
<el-table v-loading="state.loading" :data="state.userListData" row-key="id" border>
<el-table-column prop="userName" label="账号" min-width="180" show-overflow-tooltip />
<el-table-column prop="userName" label="账号" min-width="180" show-overflow-tooltip>
<template #default="{ row }">
<el-badge :type="row.online ? 'success' : 'info'" is-dot :offset="[0, 12]"></el-badge>
{{ row.userName }}
</template>
</el-table-column>
<el-table-column prop="name" label="姓名" width="120" show-overflow-tooltip>
<template #default="{ row }"> {{ row.name }} <el-tag v-if="row.isManager" type="success">主管</el-tag> </template>
</el-table-column>
Expand Down

0 comments on commit c0b0d6a

Please sign in to comment.