增强函数管理功能和界面优化

在 `FunDto.cs` 中添加 `Parameters` 属性及默认值,新增 `FunParameterDto` 类以描述函数参数信息。
在 `FunList.razor` 中优化函数列表显示,使用卡片组件展示按钮和参数信息。
更新 `FunList.razor.cs` 中的依赖注入属性,确保初始化为 `default!`,并简化添加函数逻辑。
在文件上传验证中添加 `_message` 的空值检查,避免空引用异常。
This commit is contained in:
zyxucp
2025-09-01 20:57:12 +08:00
parent 49b67ce3eb
commit 16303d7d92
3 changed files with 72 additions and 27 deletions

View File

@@ -8,11 +8,21 @@ namespace AntSK.Domain.Domain.Model.Fun
{
public class FunDto
{
public string Name { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; }
public string Description { get; set; } = string.Empty;
public FunType FunType { get; set; }
// 函数参数信息(用于前端展示)
public List<FunParameterDto> Parameters { get; set; } = new();
}
public class FunParameterDto
{
public string Name { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
}
public enum FunType

View File

@@ -3,7 +3,6 @@
@using AntSK.Domain.Domain.Model.Enum
@using AntSK.Domain.Domain.Model.Fun
@page "/plugins/funlist"
@inject NavigationManager NavigationManager
@using AntSK.Services.Auth
@inherits AuthComponentBase
@@ -26,16 +25,20 @@
<ListItem NoFlex>
@if (string.IsNullOrEmpty(context.Name))
{
<Card Hoverable Bordered Class="card" Style="height:160px; display:flex; align-items:center; justify-content:center;">
<div style="display:flex; gap:12px; flex-wrap:wrap; justify-content:center;">
<Button Type="dashed" class="newButton" @onclick="AddFun">
<Icon Type="plus" Theme="outline" /> 创建函数
</Button>
<Button Type="dashed" class="newButton" @onclick="ClearFun">
<Icon Type="clear" Theme="outline" /> 清空导入函数
</Button>
</div>
</Card>
}
else
{
<Card Hoverable Bordered Class="card" Style="max-height:247px;">
<Card Hoverable Bordered Class="card" Style="height:160px; overflow:hidden;">
<CardMeta>
<AvatarTemplate>
@@ -44,10 +47,29 @@
<a>@context.Name</a>
</TitleTemplate>
<DescriptionTemplate>
<Paragraph class="item" Ellipsis>
<Paragraph class="item" Ellipsis Style="margin-bottom:8px;">
<!--todo: Ellipsis not working-->
@context.Description
</Paragraph>
@if (context.Parameters?.Count > 0)
{
<div style="margin-top:8px; max-height:140px; overflow:auto; padding-right:4px;">
<span style="font-weight:600;">参数:</span>
<ul style="margin: 6px 0 0 18px; padding:0;">
@foreach (var p in context.Parameters)
{
<li style="list-style: disc;">
<span style="color:#3b3b3b">@p.Name</span>
<span style="color:#999"> (@p.Type)</span>
@if (!string.IsNullOrWhiteSpace(p.Description))
{
<span style="color:#666"> - @p.Description</span>
}
</li>
}
</ul>
</div>
}
</DescriptionTemplate>
</CardMeta>
</Card>

View File

@@ -18,17 +18,17 @@ namespace AntSK.Pages.FunPage
private FunDto[] _data = { };
[Inject]
FunctionService _functionService { get; set; }
FunctionService _functionService { get; set; } = default!;
[Inject]
IServiceProvider _serviceProvider { get; set; }
IServiceProvider _serviceProvider { get; set; } = default!;
[Inject]
IConfirmService _confirmService { get; set; }
IConfirmService _confirmService { get; set; } = default!;
[Inject]
IFuns_Repositories _funs_Repositories { get; set; }
IFuns_Repositories _funs_Repositories { get; set; } = default!;
[Inject]
protected MessageService? _message { get; set; }
[Inject] protected ILogger<FunDto> _logger { get; set; }
[Inject] protected ILogger<FunDto> _logger { get; set; } = default!;
bool _fileVisible = false;
bool _fileConfirmLoading = false;
@@ -56,7 +56,19 @@ namespace AntSK.Pages.FunPage
foreach (var func in funList)
{
var methodInfo = _functionService.MethodInfos[func.Key];
list.Add(new FunDto() { Name = func.Key, Description = methodInfo.Description });
var paramDtos = methodInfo.Parameters?.Select(p => new FunParameterDto
{
Name = p.ParameterName ?? string.Empty,
Type = (p.ParameterType?.IsClass ?? false) ? "object" : (p.ParameterType?.Name ?? "string"),
Description = p.Description ?? string.Empty
}).ToList() ?? new List<FunParameterDto>();
list.Add(new FunDto()
{
Name = func.Key,
Description = methodInfo.Description,
Parameters = paramDtos
});
}
_data = list.ToArray();
await InvokeAsync(StateHasChanged);
@@ -72,9 +84,7 @@ namespace AntSK.Pages.FunPage
await InitData(searchKey);
}
private async Task AddFun() {
_fileVisible = true;
}
private Task AddFun() { _fileVisible = true; return Task.CompletedTask; }
private async Task ClearFun()
{
var content = "清空自定义函数将会删除全部导入函数并且需要程序重启后下次生效如不是DLL冲突等原因不建议清空是否要清空";
@@ -97,7 +107,10 @@ namespace AntSK.Pages.FunPage
_funs_Repositories.Insert(new Funs() { Id = Guid.NewGuid().ToString(), Path = file.FilePath });
_functionService.FuncLoad(file.FilePath);
}
_message.Info("上传成功");
if (_message is not null)
{
await _message.Info("上传成功");
}
await InitData("");
_fileVisible = false;
}
@@ -119,12 +132,12 @@ namespace AntSK.Pages.FunPage
{
if (file.Ext != ".dll")
{
_message.Error("请上传dll文件!");
_message?.Error("请上传dll文件!");
}
var IsLt500K = file.Size < 1024 * 1024 * 100;
if (!IsLt500K)
{
_message.Error("文件需不大于100MB!");
_message?.Error("文件需不大于100MB!");
}
return IsLt500K;