140 lines
5.6 KiB
Plaintext
140 lines
5.6 KiB
Plaintext
@page "/template/register"
|
|
@using IDIS.Services
|
|
@using IDIS.Models
|
|
@using Cysharp.Threading.Tasks
|
|
@using BITKit
|
|
@inject ILogger<TemlateRegister> logger
|
|
@inject ISnackbar Snackbar
|
|
@inject IDIS_TemplateService templateService
|
|
@inject IDIS_Service service
|
|
@inherits OwningComponentBase
|
|
<MudText Typo="Typo.h3" GutterBottom="true">注册标识模板</MudText>
|
|
<MudText>在注册与更新标识之前,我们需要一个创建标识模板,然后我们可以通过创建的模板注册标识<br />
|
|
基于已选的标识模板,创建新的标识模板</MudText>
|
|
<MudGrid>
|
|
<MudItem xs="3">
|
|
<div class="d-flex flex-grow-1 gap-4 py-2">
|
|
<MudText Class="flex-1 d-flex" Typo="Typo.h6">选择标识模板</MudText>
|
|
<MudButton Class="d-flex" Variant="Variant.Outlined" OnClick="() => Refresh().Forget()">刷新</MudButton>
|
|
</div>
|
|
@if (templates.Length is 0)
|
|
{
|
|
<MudAlert Severity="Severity.Normal">模板为空</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
<MudStack>
|
|
@foreach (var item in templates)
|
|
{
|
|
<MudButton
|
|
Class="pa-2"
|
|
Variant="Variant.Outlined"
|
|
OnClick="() => SelectTemplate(item)">
|
|
@(item.Prefix)/@(item.Version)
|
|
</MudButton>
|
|
}
|
|
</MudStack>
|
|
}
|
|
</MudItem>
|
|
<MudItem xs="1">
|
|
</MudItem>
|
|
<MudItem xs="8">
|
|
<MudStack>
|
|
<MudText Typo="Typo.h6">模板信息</MudText>
|
|
<MudStack Row="true" Spacing="2">
|
|
<MudTextField @bind-Value="prefix" Label="前缀" Variant="Variant.Outlined"></MudTextField>
|
|
<MudTextField @bind-Value="version" Label="版本" Variant="Variant.Outlined"></MudTextField>
|
|
</MudStack>
|
|
|
|
<MudTextField @bind-Value="description" Label="描述" Variant="Variant.Outlined"></MudTextField>
|
|
<MudText Typo="Typo.h6">模板条目</MudText>
|
|
<MudTable Items="@items"
|
|
Hover="true"
|
|
Class="py-2"
|
|
>
|
|
<HeaderContent>
|
|
<MudTh>Name</MudTh>
|
|
<MudTh>IdType</MudTh>
|
|
<MudTh>Type</MudTh>
|
|
<MudTh>MinLength</MudTh>
|
|
<MudTh>MaxLength</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Name">@context.Name</MudTd>
|
|
<MudTd DataLabel="IdType">@context.IdType</MudTd>
|
|
<MudTd DataLabel="Type">@context.MetaData.Type</MudTd>
|
|
<MudTd DataLabel="MinLength">@context.MetaData.MinLength</MudTd>
|
|
<MudTd DataLabel="MaxLength">@context.MetaData.MaxLength</MudTd>
|
|
</RowTemplate>
|
|
<RowEditingTemplate>
|
|
<MudTd DataLabel="Name">
|
|
<MudTextField @bind-Value="@context.Name" Required />
|
|
</MudTd>
|
|
<MudTd DataLabel="IdType">
|
|
<MudTextField @bind-Value="@context.IdType" Required />
|
|
</MudTd>
|
|
<MudTd DataLabel="Type">
|
|
<MudTextField @bind-Value="@context.MetaData.Type" Required />
|
|
</MudTd>
|
|
<MudTd DataLabel="MinLength">
|
|
<MudTextField @bind-Value="@context.MetaData.MinLength" Required />
|
|
</MudTd>
|
|
<MudTd DataLabel="MaxLength">
|
|
<MudTextField @bind-Value="@context.MetaData.MaxLength" Required />
|
|
</MudTd>
|
|
</RowEditingTemplate>
|
|
</MudTable>
|
|
<div class="d-flex">
|
|
<MudButton Class="d-flex flex-grow-1" Variant="Variant.Outlined" OnClick="SaveTemplate">保存标识模板</MudButton>
|
|
<MudDivider Style="width: 1em" Vertical="true" FlexItem="true" />
|
|
<MudButton Class="d-flex" Variant="Variant.Outlined">删除标识模板</MudButton>
|
|
</div>
|
|
</MudStack>
|
|
</MudItem>
|
|
</MudGrid>
|
|
@code {
|
|
public IDIS_Template[] templates { get; set; } = Array.Empty<IDIS_Template>();
|
|
private IDIS_Template template = new IDIS_Template();
|
|
private IDIS_Template_Item[] items = new []{new IDIS_Template_Item()};
|
|
|
|
private string prefix { get; set; } = new IDIS_Template().Prefix;
|
|
private string version { get; set; }= new IDIS_Template().Version;
|
|
private string description { get; set; }= new IDIS_Template().Description;
|
|
|
|
async UniTask Refresh()
|
|
{
|
|
Snackbar.Add("正在刷新模板");
|
|
templates = await templateService.ToArrayAsync();
|
|
await InvokeAsync(StateHasChanged);
|
|
Snackbar.Add("模板刷新完成");
|
|
}
|
|
private void SelectTemplate(IDIS_Template newValue)
|
|
{
|
|
template = newValue;
|
|
prefix = template.Prefix;
|
|
version = template.Version;
|
|
description = template.Description;
|
|
items = template.Items;
|
|
}
|
|
private async void SaveTemplate()
|
|
{
|
|
var newTemplate = new IDIS_Template
|
|
{
|
|
Prefix = prefix,
|
|
Version = version,
|
|
Description = description,
|
|
Items = items
|
|
};
|
|
Snackbar.Add("正在保存模板");
|
|
try
|
|
{
|
|
await templateService.SaveAsync(newTemplate);
|
|
Snackbar.Add("模板已保存");
|
|
await Refresh();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Snackbar.Add(e.Message, Severity.Error);
|
|
}
|
|
}
|
|
} |