diff --git a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableModelUtils.cs b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableModelUtils.cs index 644bf04b3..1ccf242a9 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableModelUtils.cs +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableModelUtils.cs @@ -11,7 +11,7 @@ namespace ThingsGateway.Gateway.Razor; public static class VariableModelUtils { static MemoryCache MemoryCache = new(); - public static object GetPropertyValue(VariableRuntime model, string fieldName) + private static object GetPropertyValue(VariableRuntime model, string fieldName) { if (model == null) { @@ -31,6 +31,7 @@ public static class VariableModelUtils return ret; } } + /// /// 获取属性方法 Lambda 表达式 /// @@ -38,7 +39,7 @@ public static class VariableModelUtils /// /// /// - public static Expression> GetPropertyValueLambda(string propertyName) where TModel : class, new() + private static Expression> GetPropertyValueLambda(string propertyName) where TModel : class, new() { var type = typeof(TModel); @@ -99,26 +100,26 @@ public static class VariableModelUtils switch (fieldName) { case nameof(VariableRuntime.Value): - return row.Value?.ToSystemTextJsonString(false) ?? string.Empty; + return row.Value?.ToSystemTextJsonString(false) ?? string.Empty; case nameof(VariableRuntime.RawValue): - return row.RawValue?.ToSystemTextJsonString(false) ?? string.Empty; + return row.RawValue?.ToSystemTextJsonString(false) ?? string.Empty; case nameof(VariableRuntime.LastSetValue): - return row.LastSetValue?.ToSystemTextJsonString(false) ?? string.Empty; + return row.LastSetValue?.ToSystemTextJsonString(false) ?? string.Empty; case nameof(VariableRuntime.ChangeTime): - return row.ChangeTime.ToString("dd-HH:mm:ss.fff"); + return row.ChangeTime.ToString("MM-dd HH:mm:ss.fff"); case nameof(VariableRuntime.CollectTime): - return row.CollectTime.ToString("dd-HH:mm:ss.fff"); + return row.CollectTime.ToString("MM-dd HH:mm:ss.fff"); case nameof(VariableRuntime.IsOnline): - return row.IsOnline.ToString(); + return row.IsOnline ? "Online" : "Offline"; case nameof(VariableRuntime.LastErrorMessage): - return row.LastErrorMessage; + return row.LastErrorMessage; case nameof(VariableRuntime.RuntimeType): - return row.RuntimeType; + return row.RuntimeType; default: var ret = VariableModelUtils.GetPropertyValue(row, fieldName); @@ -136,7 +137,7 @@ public static class VariableModelUtils } } } - return ret is string str ? str : ret?.ToString() ?? string.Empty; + return ret is string str ? str : ret?.ToString() ?? string.Empty; } } diff --git a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor deleted file mode 100644 index 6df07d544..000000000 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor +++ /dev/null @@ -1,26 +0,0 @@ -@namespace ThingsGateway.Gateway.Razor -@using System.Text.Json.Nodes -@using Microsoft.Extensions.Hosting -@using ThingsGateway.Admin.Application -@using ThingsGateway.Admin.Razor -@using ThingsGateway.Gateway.Application -@inherits ComponentDefault - - -@foreach (var col in RowContent.Columns) -{ - -
- @if(col.GetShowTips()) - { - - @VariableModelUtils.GetValue(RowContent.Row, col.GetFieldName()) - - } - else - { - @VariableModelUtils.GetValue(RowContent.Row, col.GetFieldName()) - } -
- -} diff --git a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor.cs b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor.cs deleted file mode 100644 index 132e94d39..000000000 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor.cs +++ /dev/null @@ -1,249 +0,0 @@ -//------------------------------------------------------------------------------ -// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 -// 此代码版权(除特别声明外的代码)归作者本人Diego所有 -// 源代码使用协议遵循本仓库的开源协议及附加协议 -// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway -// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway -// 使用文档:https://thingsgateway.cn/ -// QQ群:605534569 -//------------------------------------------------------------------------------ - -using System.Collections.Concurrent; - -namespace ThingsGateway.Gateway.Razor; - -public partial class VariableRow -{ - [Parameter] - public TableRowContext? RowContent { get; set; } - //private bool Disposed; - //public void Dispose() - //{ - // Disposed = true; - // timer?.SafeDispose(); - // GC.SuppressFinalize(this); - //} - //TimerX? timer; - //protected override void OnAfterRender(bool firstRender) - //{ - // if (firstRender) - // { - // timer = new TimerX(Refresh, null, 1000, 1000, "VariableRow"); - // } - // base.OnAfterRender(firstRender); - //} - - //private Task Refresh(object? state) - //{ - // if (!Disposed) - // return InvokeAsync(StateHasChanged); - // else - // return Task.CompletedTask; - //} - - protected override void OnParametersSet() - { - FixedCellClassStringCache?.Clear(); - CellClassStringCache?.Clear(); - base.OnParametersSet(); - } - - /// - /// 获得指定列头固定列样式 - /// - /// - /// - /// - protected string? GetFixedCellStyleString(ITableColumn col, int margin = 0) - { - string? ret = null; - if (col.Fixed) - { - ret = IsTail(col) ? GetRightStyle(col, margin) : GetLeftStyle(col); - } - return ret; - } - - private string? GetLeftStyle(ITableColumn col) - { - var columns = RowContent.Columns.ToList(); - var defaultWidth = 200; - var width = 0; - var start = 0; - var index = columns.IndexOf(col); - //if (GetFixedDetailRowHeaderColumn) - //{ - // width += DetailColumnWidth; - //} - //if (GetFixedMultipleSelectColumn) - //{ - // width += MultiColumnWidth; - //} - if (GetFixedLineNoColumn) - { - width += LineNoColumnWidth; - } - while (index > start) - { - var column = columns[start++]; - width += column.Width ?? defaultWidth; - } - return $"left: {width}px;"; - } - private bool GetFixedLineNoColumn = false; - - private string? GetRightStyle(ITableColumn col, int margin) - { - var columns = RowContent.Columns.ToList(); - var defaultWidth = 200; - var width = 0; - var index = columns.IndexOf(col); - - // after - while (index + 1 < columns.Count) - { - var column = columns[index++]; - width += column.Width ?? defaultWidth; - } - //if (ShowExtendButtons && FixedExtendButtonsColumn) - { - width += ExtendButtonColumnWidth; - } - - // 如果是固定表头时增加滚动条位置 - if (IsFixedHeader && (index + 1) == columns.Count) - { - width += margin; - } - return $"right: {width}px;"; - } - private bool IsFixedHeader = true; - - public int LineNoColumnWidth { get; set; } = 60; - public int ExtendButtonColumnWidth { get; set; } = 220; - - - private bool IsTail(ITableColumn col) - { - var middle = Math.Floor(RowContent.Columns.Count() * 1.0 / 2); - var index = Columns.IndexOf(col); - return middle < index; - } - private NonBlockingDictionary CellClassStringCache { get; } = new(ReferenceEqualityComparer.Instance); - - /// - /// 获得 Cell 文字样式 - /// - /// - /// - /// - /// - protected string? GetCellClassString(ITableColumn col, bool hasChildren, bool inCell) - { - if (CellClassStringCache.TryGetValue(col, out var cached)) - { - return cached; - } - else - { - bool trigger = false; - return CellClassStringCache.GetOrAdd(col, col => CssBuilder.Default("table-cell") - .AddClass(col.GetAlign().ToDescriptionString(), col.Align == Alignment.Center || col.Align == Alignment.Right) - .AddClass("is-wrap", col.GetTextWrap()) - .AddClass("is-ellips", col.GetTextEllipsis()) - .AddClass("is-tips", col.GetShowTips()) - .AddClass("is-resizable", AllowResizing) - .AddClass("is-tree", IsTree && hasChildren) - .AddClass("is-incell", inCell) -.AddClass("is-dbcell", trigger) - .AddClass(col.CssClass) - .Build()); - } - - } - - private bool AllowResizing = true; - private bool IsTree = false; - - private NonBlockingDictionary FixedCellClassStringCache { get; } = new(ReferenceEqualityComparer.Instance); - /// - /// 获得指定列头固定列样式 - /// - /// - /// - protected string? GetFixedCellClassString(ITableColumn col) - { - if (FixedCellClassStringCache.TryGetValue(col, out var cached)) - { - return cached; - } - else - { - return FixedCellClassStringCache.GetOrAdd(col, col => CssBuilder.Default() - .AddClass("fixed", col.Fixed) - .AddClass("fixed-right", col.Fixed && IsTail(col)) - .AddClass("fr", IsLastColumn(col)) - .AddClass("fl", IsFirstColumn(col)) - .Build()); - - } - - } - - - [Parameter] - public Func> ColumnsFunc { get; set; } - public List Columns => ColumnsFunc(); - - private NonBlockingDictionary LastFixedColumnCache { get; } = new(ReferenceEqualityComparer.Instance); - private bool IsLastColumn(ITableColumn col) - { - if (LastFixedColumnCache.TryGetValue(col, out var cached)) - { - return cached; - } - else - { - return LastFixedColumnCache.GetOrAdd(col, col => - { - var ret = false; - if (col.Fixed && !IsTail(col)) - { - var index = Columns.IndexOf(col) + 1; - ret = index < Columns.Count && Columns[index].Fixed == false; - } - return ret; - }); - - } - } - private NonBlockingDictionary FirstFixedColumnCache { get; } = new(ReferenceEqualityComparer.Instance); - private bool IsFirstColumn(ITableColumn col) - { - if (FirstFixedColumnCache.TryGetValue(col, out var cached)) - { - return cached; - } - else - { - return FirstFixedColumnCache.GetOrAdd(col, col => - { - var ret = false; - if (col.Fixed && IsTail(col)) - { - // 查找前一列是否固定 - var index = Columns.IndexOf(col) - 1; - if (index > 0) - { - ret = !Columns[index].Fixed; - } - } - return ret; - }); - - } - } - - - -} diff --git a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor index 43b3f4457..d187526d7 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor @@ -97,16 +97,20 @@ @foreach (var col in context.Columns) { -
+ @{ + var name = col.GetFieldName(); + var data = VariableModelUtils.GetValue(context.Row, name); + } +
@if (col.GetShowTips()) { - - @VariableModelUtils.GetValue(context.Row, col.GetFieldName()) + + @data } else { - @VariableModelUtils.GetValue(context.Row, col.GetFieldName()) + @data }
diff --git a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.cs b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.cs index 46aa20e22..2ddde9bf3 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.cs +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.cs @@ -71,7 +71,7 @@ public partial class VariableRuntimeInfo string? ret = null; if (col.Fixed) { - ret = IsTail(col,row) ? GetRightStyle(col,row, margin) : GetLeftStyle(col, row); + ret = IsTail(col, row) ? GetRightStyle(col, row, margin) : GetLeftStyle(col, row); } return ret; } @@ -135,7 +135,7 @@ public partial class VariableRuntimeInfo public int ExtendButtonColumnWidth { get; set; } = 220; - private bool IsTail(ITableColumn col,TableRowContext row) + private bool IsTail(ITableColumn col, TableRowContext row) { var middle = Math.Floor(row.Columns.Count() * 1.0 / 2); var index = Columns.IndexOf(col); @@ -145,16 +145,13 @@ public partial class VariableRuntimeInfo /// /// 获得 Cell 文字样式 /// - /// - /// - /// - /// - protected string? GetCellClassString(ITableColumn col, bool hasChildren, bool inCell) + protected string? GetCellClassString(ITableColumn col, string data, bool hasChildren, bool inCell) { - - bool trigger = false; + bool trigger = false; return CssBuilder.Default("table-cell") .AddClass(col.GetAlign().ToDescriptionString(), col.Align == Alignment.Center || col.Align == Alignment.Right) +.AddClass("green--text", data == "Online") +.AddClass("red--text", data == "Offline") .AddClass("is-wrap", col.GetTextWrap()) .AddClass("is-ellips", col.GetTextEllipsis()) .AddClass("is-tips", col.GetShowTips()) @@ -177,46 +174,46 @@ public partial class VariableRuntimeInfo { return CssBuilder.Default() .AddClass("fixed", col.Fixed) - .AddClass("fixed-right", col.Fixed && IsTail(col,row)) + .AddClass("fixed-right", col.Fixed && IsTail(col, row)) .AddClass("fr", IsLastColumn(col, row)) .AddClass("fl", IsFirstColumn(col, row)) .Build(); } - public List Columns=> table?.Columns; + public List Columns => table?.Columns; private bool IsLastColumn(ITableColumn col, TableRowContext row) { - var ret = false; - if (col.Fixed && !IsTail(col, row)) - { - var index = Columns.IndexOf(col) + 1; - ret = index < Columns.Count && Columns[index].Fixed == false; - } - return ret; - + var ret = false; + if (col.Fixed && !IsTail(col, row)) + { + var index = Columns.IndexOf(col) + 1; + ret = index < Columns.Count && Columns[index].Fixed == false; + } + return ret; + } private bool IsFirstColumn(ITableColumn col, TableRowContext row) { - - var ret = false; - if (col.Fixed && IsTail(col, row)) - { - // 查找前一列是否固定 - var index = Columns.IndexOf(col) - 1; - if (index > 0) - { - ret = !Columns[index].Fixed; - } - } - return ret; + + var ret = false; + if (col.Fixed && IsTail(col, row)) + { + // 查找前一列是否固定 + var index = Columns.IndexOf(col) - 1; + if (index > 0) + { + ret = !Columns[index].Fixed; + } + } + return ret; } #endregion #region js - + protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new { Method = nameof(TriggerStateChanged) }); private Task OnColumnVisibleChanged(string name, bool visible) diff --git a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.js b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.js index d459a22f3..ab7bdf810 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.js +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor.js @@ -72,6 +72,19 @@ export function init(id, invoke, options) { cellDiv.innerText = cellValue ?? ''; } } + if (cellValue == "Online") { + cellDiv.classList.remove('red--text'); + cellDiv.classList.add('green--text'); + } + else if (cellValue == "Offline") { + cellDiv.classList.remove('green--text'); + cellDiv.classList.add('red--text'); + } + else { + cellDiv.classList.remove('red--text'); + cellDiv.classList.remove('green--text'); + + } } //// 查找 switch