mirror of
https://github.com/AIDotNet/AntSK.git
synced 2026-02-17 14:06:11 +08:00
增强函数管理功能和界面优化
在 `FunDto.cs` 中添加 `Parameters` 属性及默认值,新增 `FunParameterDto` 类以描述函数参数信息。 在 `FunList.razor` 中优化函数列表显示,使用卡片组件展示按钮和参数信息。 更新 `FunList.razor.cs` 中的依赖注入属性,确保初始化为 `default!`,并简化添加函数逻辑。 在文件上传验证中添加 `_message` 的空值检查,避免空引用异常。
This commit is contained in:
@@ -8,11 +8,21 @@ namespace AntSK.Domain.Domain.Model.Fun
|
|||||||
{
|
{
|
||||||
public class FunDto
|
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 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
|
public enum FunType
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
@using AntSK.Domain.Domain.Model.Enum
|
@using AntSK.Domain.Domain.Model.Enum
|
||||||
@using AntSK.Domain.Domain.Model.Fun
|
@using AntSK.Domain.Domain.Model.Fun
|
||||||
@page "/plugins/funlist"
|
@page "/plugins/funlist"
|
||||||
@inject NavigationManager NavigationManager
|
|
||||||
@using AntSK.Services.Auth
|
@using AntSK.Services.Auth
|
||||||
@inherits AuthComponentBase
|
@inherits AuthComponentBase
|
||||||
|
|
||||||
@@ -26,16 +25,20 @@
|
|||||||
<ListItem NoFlex>
|
<ListItem NoFlex>
|
||||||
@if (string.IsNullOrEmpty(context.Name))
|
@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">
|
<Button Type="dashed" class="newButton" @onclick="AddFun">
|
||||||
<Icon Type="plus" Theme="outline" /> 创建函数
|
<Icon Type="plus" Theme="outline" /> 创建函数
|
||||||
</Button>
|
</Button>
|
||||||
<Button Type="dashed" class="newButton" @onclick="ClearFun">
|
<Button Type="dashed" class="newButton" @onclick="ClearFun">
|
||||||
<Icon Type="clear" Theme="outline" /> 清空导入函数
|
<Icon Type="clear" Theme="outline" /> 清空导入函数
|
||||||
</Button>
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<Card Hoverable Bordered Class="card" Style="max-height:247px;">
|
<Card Hoverable Bordered Class="card" Style="height:160px; overflow:hidden;">
|
||||||
<CardMeta>
|
<CardMeta>
|
||||||
<AvatarTemplate>
|
<AvatarTemplate>
|
||||||
|
|
||||||
@@ -44,10 +47,29 @@
|
|||||||
<a>@context.Name</a>
|
<a>@context.Name</a>
|
||||||
</TitleTemplate>
|
</TitleTemplate>
|
||||||
<DescriptionTemplate>
|
<DescriptionTemplate>
|
||||||
<Paragraph class="item" Ellipsis>
|
<Paragraph class="item" Ellipsis Style="margin-bottom:8px;">
|
||||||
<!--todo: Ellipsis not working-->
|
<!--todo: Ellipsis not working-->
|
||||||
@context.Description
|
@context.Description
|
||||||
</Paragraph>
|
</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>
|
</DescriptionTemplate>
|
||||||
</CardMeta>
|
</CardMeta>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -18,17 +18,17 @@ namespace AntSK.Pages.FunPage
|
|||||||
private FunDto[] _data = { };
|
private FunDto[] _data = { };
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
FunctionService _functionService { get; set; }
|
FunctionService _functionService { get; set; } = default!;
|
||||||
[Inject]
|
[Inject]
|
||||||
IServiceProvider _serviceProvider { get; set; }
|
IServiceProvider _serviceProvider { get; set; } = default!;
|
||||||
[Inject]
|
[Inject]
|
||||||
IConfirmService _confirmService { get; set; }
|
IConfirmService _confirmService { get; set; } = default!;
|
||||||
[Inject]
|
[Inject]
|
||||||
IFuns_Repositories _funs_Repositories { get; set; }
|
IFuns_Repositories _funs_Repositories { get; set; } = default!;
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
protected MessageService? _message { get; set; }
|
protected MessageService? _message { get; set; }
|
||||||
[Inject] protected ILogger<FunDto> _logger { get; set; }
|
[Inject] protected ILogger<FunDto> _logger { get; set; } = default!;
|
||||||
|
|
||||||
bool _fileVisible = false;
|
bool _fileVisible = false;
|
||||||
bool _fileConfirmLoading = false;
|
bool _fileConfirmLoading = false;
|
||||||
@@ -56,7 +56,19 @@ namespace AntSK.Pages.FunPage
|
|||||||
foreach (var func in funList)
|
foreach (var func in funList)
|
||||||
{
|
{
|
||||||
var methodInfo = _functionService.MethodInfos[func.Key];
|
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();
|
_data = list.ToArray();
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
@@ -72,9 +84,7 @@ namespace AntSK.Pages.FunPage
|
|||||||
await InitData(searchKey);
|
await InitData(searchKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AddFun() {
|
private Task AddFun() { _fileVisible = true; return Task.CompletedTask; }
|
||||||
_fileVisible = true;
|
|
||||||
}
|
|
||||||
private async Task ClearFun()
|
private async Task ClearFun()
|
||||||
{
|
{
|
||||||
var content = "清空自定义函数将会删除全部导入函数,并且需要程序重启后下次生效,如不是DLL冲突等原因不建议清空,是否要清空?";
|
var content = "清空自定义函数将会删除全部导入函数,并且需要程序重启后下次生效,如不是DLL冲突等原因不建议清空,是否要清空?";
|
||||||
@@ -97,7 +107,10 @@ namespace AntSK.Pages.FunPage
|
|||||||
_funs_Repositories.Insert(new Funs() { Id = Guid.NewGuid().ToString(), Path = file.FilePath });
|
_funs_Repositories.Insert(new Funs() { Id = Guid.NewGuid().ToString(), Path = file.FilePath });
|
||||||
_functionService.FuncLoad(file.FilePath);
|
_functionService.FuncLoad(file.FilePath);
|
||||||
}
|
}
|
||||||
_message.Info("上传成功");
|
if (_message is not null)
|
||||||
|
{
|
||||||
|
await _message.Info("上传成功");
|
||||||
|
}
|
||||||
await InitData("");
|
await InitData("");
|
||||||
_fileVisible = false;
|
_fileVisible = false;
|
||||||
}
|
}
|
||||||
@@ -119,12 +132,12 @@ namespace AntSK.Pages.FunPage
|
|||||||
{
|
{
|
||||||
if (file.Ext != ".dll")
|
if (file.Ext != ".dll")
|
||||||
{
|
{
|
||||||
_message.Error("请上传dll文件!");
|
_message?.Error("请上传dll文件!");
|
||||||
}
|
}
|
||||||
var IsLt500K = file.Size < 1024 * 1024 * 100;
|
var IsLt500K = file.Size < 1024 * 1024 * 100;
|
||||||
if (!IsLt500K)
|
if (!IsLt500K)
|
||||||
{
|
{
|
||||||
_message.Error("文件需不大于100MB!");
|
_message?.Error("文件需不大于100MB!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return IsLt500K;
|
return IsLt500K;
|
||||||
|
|||||||
Reference in New Issue
Block a user