feat: token 下拉列表支持可选是否包含默认项

为 GetSelectListAsync 接口新增 includeDefault 查询参数,允许调用方控制是否返回“默认”选项,默认保持原有行为。
This commit is contained in:
ccnetcore
2026-01-03 14:39:17 +08:00
parent 3447e2dc5d
commit 5bb7dfb7cd

View File

@@ -26,6 +26,7 @@ public class TokenService : ApplicationService
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
private readonly ISqlSugarRepository<UsageStatisticsAggregateRoot> _usageStatisticsRepository;
private readonly ModelManager _modelManager;
public TokenService(
ISqlSugarRepository<TokenAggregateRoot> tokenRepository,
ISqlSugarRepository<UsageStatisticsAggregateRoot> usageStatisticsRepository,
@@ -90,7 +91,7 @@ public class TokenService : ApplicationService
}
[HttpGet("token/select-list")]
public async Task<List<TokenSelectListOutputDto>> GetSelectListAsync()
public async Task<List<TokenSelectListOutputDto>> GetSelectListAsync([FromQuery] bool? includeDefault = true)
{
var userId = CurrentUser.GetId();
var tokens = await _tokenRepository._DbQueryable
@@ -104,12 +105,16 @@ public class TokenService : ApplicationService
IsDisabled = x.IsDisabled
}).ToListAsync();
tokens.Insert(0,new TokenSelectListOutputDto
if (includeDefault == true)
{
TokenId = Guid.Empty,
Name = "默认",
IsDisabled = false
});
tokens.Insert(0, new TokenSelectListOutputDto
{
TokenId = Guid.Empty,
Name = "默认",
IsDisabled = false
});
}
return tokens;
}