feat: 完成token下拉框

This commit is contained in:
ccnetcore
2025-11-29 18:25:43 +08:00
parent ddb00879f4
commit 86555af6ce
6 changed files with 54 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Users;
using Yi.Framework.AiHub.Application.Contracts.Dtos.Token;
@@ -8,6 +9,7 @@ using Yi.Framework.AiHub.Domain.Entities;
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
using Yi.Framework.AiHub.Domain.Extensions;
using Yi.Framework.AiHub.Domain.Shared.Consts;
using Yi.Framework.Ddd.Application.Contracts;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.AiHub.Application.Services;
@@ -33,18 +35,19 @@ public class TokenService : ApplicationService
/// 获取当前用户的Token列表
/// </summary>
[HttpGet("token/list")]
public async Task<List<TokenListOutput>> GetListAsync()
public async Task<PagedResultDto<TokenGetListOutputDto>> GetListAsync([FromQuery] PagedAllResultRequestDto input)
{
RefAsync<int> total = 0;
var userId = CurrentUser.GetId();
var tokens = await _tokenRepository._DbQueryable
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.CreationTime)
.ToListAsync();
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
if (!tokens.Any())
{
return new List<TokenListOutput>();
return new PagedResultDto<TokenGetListOutputDto>();
}
// 获取尊享包模型ID列表
@@ -65,7 +68,7 @@ public class TokenService : ApplicationService
var result = tokens.Select(t =>
{
var usedQuota = usageStats.FirstOrDefault(u => u.TokenId == t.Id)?.UsedQuota ?? 0;
return new TokenListOutput
return new TokenGetListOutputDto
{
Id = t.Id,
Name = t.Name,
@@ -78,14 +81,32 @@ public class TokenService : ApplicationService
};
}).ToList();
return result;
return new PagedResultDto<TokenGetListOutputDto>(total, result);
}
[HttpGet("token/select-list")]
public async Task<List<TokenSelectListOutputDto>> GetSelectListAsync()
{
var userId = CurrentUser.GetId();
var tokens = await _tokenRepository._DbQueryable
.Where(x => x.UserId == userId)
.OrderBy(x => x.IsDisabled)
.OrderByDescending(x => x.CreationTime)
.Select(x => new TokenSelectListOutputDto
{
TokenId = x.Id,
Name = x.Name,
IsDisabled = x.IsDisabled
}).ToListAsync();
return tokens;
}
/// <summary>
/// 创建Token
/// </summary>
[HttpPost("token")]
public async Task<TokenListOutput> CreateAsync([FromBody] TokenCreateInput input)
public async Task<TokenGetListOutputDto> CreateAsync([FromBody] TokenCreateInput input)
{
var userId = CurrentUser.GetId();
@@ -111,7 +132,7 @@ public class TokenService : ApplicationService
await _tokenRepository.InsertAsync(token);
return new TokenListOutput
return new TokenGetListOutputDto
{
Id = token.Id,
Name = token.Name,
@@ -213,4 +234,4 @@ public class TokenService : ApplicationService
token.Disable();
await _tokenRepository.UpdateAsync(token);
}
}
}