Files
ThingsGateway/framework/ThingsGateway.Blazor/Page/CollectDevicePage.razor
Kimdiego2098 13be91e78b 2.0.0
2023-08-07 15:09:53 +08:00

304 lines
13 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@*
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://diego2098.gitee.io/thingsgateway-docs/
// QQ群605534569
//------------------------------------------------------------------------------
*@
@page "/gatewayconfig/collectdevice"
@namespace ThingsGateway.Blazor
@using System.Linq.Expressions;
@using BlazorComponent;
@using Mapster;
@using Masa.Blazor
@using Masa.Blazor.Presets;
@using System.IO;
@using Microsoft.AspNetCore.Authorization;
@using ThingsGateway.Admin.Blazor.Core;
@using ThingsGateway.Admin.Blazor;
@using ThingsGateway.Application;
@inject ICollectDeviceService CollectDeviceService
@attribute [Authorize]
@inherits BaseComponentBase
@inject UserResoures UserResoures
@inject IDriverPluginService DriverPluginService
@layout MainLayout
@using ThingsGateway.Admin.Core;
@if (IsMobile)
{
@GetAppDataTable()
}
else
{
<MRow>
<MCol Md=2 Cols="12">
<MCard Class="ma-2" Height=@("100%")>
<MCardTitle>
<MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_searchName"
Outlined Label=@typeof(CollectDevice).GetDescription(nameof(CollectDevice.DeviceGroup)) />
</MCardTitle>
<MTreeview
Style=@($"height: calc(100vh - {BlazorResourceConst.DefaultHeight+100}px);overflow-y:auto")
Dense TItem="string" TKey="string" ActiveChanged=@(async a=>
{
if(search.DeviceGroup!=a.FirstOrDefault())
{
search.DeviceGroup=a.FirstOrDefault();
await DatatableQueryAsync();
}
} )
Items="_deviceGroups" ItemText="r=>r" ItemChildren="r=>null"
Search="@_searchName"
Activatable ItemKey=@(r=>r)>
<LabelContent>
<span title=@context.Item>
@context.Item
</span>
</LabelContent>
</MTreeview>
</MCard>
</MCol>
<MCol Md=10 Cols="12">
@GetAppDataTable()
</MCol>
</MRow>
}
<ImportExcel @ref=ImportExcel Import="SaveDeviceImportAsync" Preview="DeviceImportAsync" />
@code {
RenderFragment GetAppDataTable()
{
RenderFragment renderFragment =
@<AppDataTable @ref="_datatable"
StyleString=@($"height: calc(100vh - {BlazorResourceConst.DefaultHeight+10}px)")
TItem="CollectDevice" SearchItem="CollectDevicePageInput"
AddItem="CollectDeviceAddInput" EditItem="CollectDeviceEditInput"
IsMenuOperTemplate=false SearchModel="@search"
QueryCallAsync="QueryCallAsync" AddCallAsync="AddCallAsync"
EditCallAsync="EditCallAsync" DeleteCallAsync="DeleteCallAsync"
IsShowDetailButton
IsShowQueryButton
IsShowAddButton=@UserResoures.IsHasButtonWithRole("gatewaycollectdeviceadd")
IsShowDeleteButton=@UserResoures.IsHasButtonWithRole("gatewaycollectdevicedelete")
IsShowEditButton=@UserResoures.IsHasButtonWithRole("gatewaycollectdeviceedit")>
<AddTemplate>
@GetRenderFragment(context)
</AddTemplate>
<EditTemplate>
@GetRenderFragment(context)
</EditTemplate>
<SearchTemplate>
<MTextField Dense
Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.Name"
Clearable
Outlined
Label=@context.Description(x => x.Name) />
<MTextField Dense
Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.PluginName"
Clearable
Outlined
Label=@context.Description(x => x.PluginName) />
<MTextField Dense
Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.DeviceGroup"
Clearable
Outlined
Label=@context.Description(x => x.DeviceGroup) />
</SearchTemplate>
<OtherToolbarTemplate>
<MMenu OffsetY
Context="menu">
<ActivatorContent>
<MButton @attributes="@menu.Attrs" Color="primary"
Class="my-1 mx-2 ">
复制
<AppChevronDown></AppChevronDown>
</MButton>
</ActivatorContent>
<ChildContent>
<MList>
<MListItem OnClick="()=>CopyDeviceAsync(context)">复制设备</MListItem>
<MListItem OnClick="()=>CopyDevAndVarAsync(context)">复制设备及设备下变量</MListItem>
</MList>
</ChildContent>
</MMenu>
<MMenu OffsetY
Context="menu">
<ActivatorContent>
<MButton @attributes="@menu.Attrs" Color="primary"
Class="my-1 mx-2 ">
导出
<AppChevronDown></AppChevronDown>
</MButton>
</ActivatorContent>
<ChildContent>
<MList>
<MListItem OnClick="()=>DownExportAsync()">导出全部</MListItem>
<MListItem OnClick="()=>DownExportAsync(search)">导出搜索项</MListItem>
</MList>
</ChildContent>
</MMenu>
<MButton Disabled=@(!UserResoures.IsHasButtonWithRole("gatewaycollectdeviceedit")) Class="my-1 mx-2" OnClick="()=>{ ImportExcel.Step=1; ImportExcel.IsShowImport=true;}" Color="primary">
导入
</MButton>
</OtherToolbarTemplate>
<ItemColTemplate>
@switch (context.Header.Value)
{
case nameof(context.Item.Enable):
<EnableChip Value="context.Item.Enable">
</EnableChip>
break;
case nameof(context.Item.PluginId):
<span title=@context.Value>
@(
DriverPluginService.GetNameById(context.Item.PluginId)
)
</span>
break;
default:
@if (context.Header.CellClass?.Contains("text-truncate") == true)
{
<span title=@context.Value>
@context.Value
</span>
}
else
{
@context.Value
}
break;
}
</ItemColTemplate>
</AppDataTable>
;
return renderFragment;
}
}
@code {
RenderFragment GetRenderFragment(CollectDeviceAddInput context)
{
RenderFragment renderFragment =
@<div>
<MTabs @bind-Value="tab">
<MTab Value="1" Style="height:50px;"> 基本信息 </MTab>
<MTab Value="2"> 扩展属性</MTab>
</MTabs>
<MTabsItems Value="tab">
<MTabItem Value="1">
@if (tab == 1)
{
<MCard Flat Class="ma-2">
<MSubheader Class="mt-4 font-weight-black"> @(context.Description(x => x.Name)) </MSubheader>
<MTextField Dense Outlined HideDetails="@("auto")" @bind-Value=@context.Name />
<MSubheader Class="mt-4 font-weight-black"> @(context.Description(x => x.Description)) </MSubheader>
<MTextField Dense Outlined HideDetails="@("auto")" @bind-Value=@context.Description />
<MSubheader Class="mt-4 font-weight-black"> @(context.Description(x => x.DeviceGroup)) </MSubheader>
<MTextField Dense Outlined HideDetails="@("auto")" @bind-Value=@context.DeviceGroup />
<MSubheader Class="mt-4 font-weight-black"> @(typeof(CollectDeviceRunTime).GetDescription(nameof(CollectDeviceRunTime.PluginName))) </MSubheader>
<MCascader Value="context.PluginId" Class="mt-3 mr-3" Clearable TValue=long TItem="DriverPluginCategory"
ValueChanged=@(async a=>await DriverValueChangedAsync(context,a))
Items="DriverPlugins" ItemText="u => u.Name" ItemValue="u => u.Id" ItemChildren="u => u.Children"
MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })"
ShowAllLevels="false" HideDetails="@("auto")" Height="30" Dense>
</MCascader>
<MSubheader Class="mt-4 font-weight-black"> @(context.Description(x => x.Enable)) </MSubheader>
<MSwitch @bind-Value=@context.Enable />
<MSubheader Class="mt-4 font-weight-black"> @(context.Description(x => x.IsLogOut)) </MSubheader>
<MSwitch @bind-Value=@context.IsLogOut />
<MSubheader Class="mt-4 font-weight-black"> @(context.Description(x => x.IsRedundant)) </MSubheader>
<MSwitch @bind-Value=@context.IsRedundant />
<MSubheader Class="font-weight-black"> @context.Description(x=>x.RedundantDeviceId) </MSubheader>
<MSelect Class="mr-3" @bind-Value=@context.RedundantDeviceId Outlined
Items=@(CollectDevices)
MenuProps="@(props => { props.Bottom = true; props.OffsetY = true; })"
ItemText=@((u) =>u.Name) ItemValue=@(u =>u.Id)
ItemDisabled="u => (u.PluginId!=context.PluginId||u.Id==context.Id)"
HideDetails=@("auto") Height="30" Dense>
</MSelect>
</MCard>
}
</MTabItem>
<MTabItem Value="2">
@if (tab == 2)
{
<MCard Flat Class="ma-2">
<MButton Class="my-3" OnClick=@(async() =>
{
if(context.PluginId>0)
{
context.DevicePropertys= GetDriverProperties(context.PluginId,context.Id);
}
else
{
await PopupService.EnqueueSnackbarAsync("需选择驱动",AlertTypes.Error);
}
}
) Color="primary">
刷新设备属性
</MButton>
@if (context.DevicePropertys != null)
{
@foreach (var item in context.DevicePropertys)
{
<MSubheader Class="mt-4 font-weight-black"> @item.Description </MSubheader>
<MTooltip Disabled=@(item.Remark==null||item.Remark?.IsNullOrEmpty()==true) Bottom Context="tip">
<ActivatorContent>
<MTextField Type="@(item.PropertyName.Contains("Password") ? "password" : "text")" @attributes="@tip.Attrs" Dense Outlined HideDetails="@("auto")" @bind-Value=@item.Value />
</ActivatorContent>
<ChildContent>
<span>@item.Remark</span>
</ChildContent>
</MTooltip>
}
}
</MCard>
}
</MTabItem>
</MTabsItems>
</div>
;
return renderFragment;
}
}