修复 动态插件属性 验证错误

This commit is contained in:
Diego
2024-12-23 15:21:42 +08:00
parent 3b22a8b170
commit b791a3eb10
4 changed files with 43 additions and 17 deletions

View File

@@ -28,15 +28,17 @@ public static class JTokenUtil
{
try
{
if (item.IsNullOrWhiteSpace())
return JValue.CreateNull();
if (bool.TryParse(item, out bool parseBool))
return new JValue(parseBool);
// 尝试解析字符串为 JToken 对象
return JToken.Parse(item);
}
catch
{
if (bool.TryParse(item, out bool parseBool))
{
return new JValue(parseBool);
}
// 解析失败时,将其转为 String 类型的 JValue
return new JValue(item);
}

View File

@@ -6,9 +6,16 @@
@using ThingsGateway.Gateway.Application
@namespace ThingsGateway.Gateway.Razor
<ValidateForm Model="Model.PluginPropertyModel.Value" @ref=Model.PluginPropertyModel.ValidateForm Id="@Model.Id.ToString()">
<EditorFormObject class="p-2" Items=PluginPropertyEditorItems AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=250 Model="Model.PluginPropertyModel.Value" @key=Model.PluginPropertyModel.Value.GetType().TypeHandle.Value>
<ValidateForm Model="Model.PluginPropertyModel.Value"
@key=@($"DeviceEditValidateForm{Model.Id}{Model.PluginPropertyModel.Value.GetType().TypeHandle.Value}")
@ref=Model.PluginPropertyModel.ValidateForm
Id=@($"DeviceEditValidateForm{Model.Id}{Model.PluginPropertyModel.Value.GetType().TypeHandle.Value}")
>
<EditorFormObject class="p-2" Items=PluginPropertyEditorItems AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=250 Model="Model.PluginPropertyModel.Value" @key=@($"DeviceEditEditorFormObject{Model.Id}{Model.PluginPropertyModel.Value.GetType().TypeHandle.Value}")
>
<FieldItems>
@if (Model.PluginPropertyModel.Value is BusinessPropertyWithCacheIntervalScript businessProperty)

View File

@@ -241,13 +241,26 @@ else
<Select SkipValidate IsVirtualize @bind-Value="@ChoiceBusinessDeviceId" Items="@BusinessDevices" ShowSearch="true" ShowLabel="false" />
</div>
<div class="col-12 col-md-4">
<Button OnClick="() => RefreshBusinessPropertyClickAsync(ChoiceBusinessDeviceId)">@Localizer["RefreshBusinessProperty"]</Button>
<Button OnClick="async() =>{
await RefreshBusinessPropertyClickAsync(ChoiceBusinessDeviceId);
foreach (var item in Model.VariablePropertyModels)
{
if(item.Value!=null)
{
item.Value.ValidateForm=null;
}
}
}">@Localizer["RefreshBusinessProperty"]</Button>
</div>
</div>
@if (Model.VariablePropertyModels != null)
{
@foreach (var item in Model.VariablePropertyModels)
@foreach (var a in Model.VariablePropertyModels)
{
var item = a;
var custom = VariablePropertyRenderFragments.TryGetValue(item.Key, out var renderFragment);
if (!custom)
@@ -256,6 +269,7 @@ else
if (has)
{
<Card IsShadow=true class="m-2 flex-fill" Color="Color.Primary">
<HeaderTemplate>
@{
@@ -266,20 +280,23 @@ else
</div>
<Button OnClick=@((a)=>
{
Model.VariablePropertyModels.Remove(item.Key);
}) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fas fa-delete-left") />
{
Model.VariablePropertyModels.Remove(item.Key);
}) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fas fa-delete-left") />
</HeaderTemplate>
<BodyTemplate>
<ValidateForm Model="item.Value.Value" Id=@((item.Key+Model.Id).ToString()) @ref=item.Value.ValidateForm>
<EditorFormObject class="p-2" Items=items AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=250 Model="item.Value.Value" @key=item.Value.Value.GetType().TypeHandle.Value>
<ValidateForm Model="item.Value.Value" @ref=item.Value.ValidateForm
@key=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")
Id=@($"VariableEditValidateForm{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
</EditorFormObject>
</ValidateForm>
</BodyTemplate>
<EditorFormObject class="p-2" Items=items AutoGenerateAllItem="false" RowType=RowType.Inline ItemsPerRow=2 ShowLabelTooltip=true LabelWidth=250 Model="item.Value.Value" @key=@($"VariableEditEditorFormObject{item.Key}{Model.Id}{item.Value.Value.GetType().TypeHandle.Value}")>
</EditorFormObject>
</ValidateForm>
</BodyTemplate>
</Card>
}
}

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>7.2.0.85</Version>
<Version>7.2.0.86</Version>
</PropertyGroup>
<ItemGroup>