From 576c5207b7afd147f7905feec0ff8d36fff9e37e Mon Sep 17 00:00:00 2001 From: "2248356998 qq.com" <2248356998@qq.com> Date: Thu, 16 Oct 2025 15:52:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20js=E5=88=B7=E6=96=B0=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E8=A1=A8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variable/VariableModelUtils.cs | 55 +- .../Variable/VariableRow.razor | 22 +- .../Variable/VariableRow.razor.cs | 474 ++++++++---------- .../Variable/VariableRowHelpers.cs | 60 --- .../Variable/VariableRuntimeInfo.razor | 6 +- .../Variable/VariableRuntimeInfo.razor.cs | 61 +-- .../Variable/VariableRuntimeInfo.razor.js | 65 +-- 7 files changed, 336 insertions(+), 407 deletions(-) delete mode 100644 src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRowHelpers.cs 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 483f66a4f..8bd6dd263 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableModelUtils.cs +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableModelUtils.cs @@ -1,6 +1,7 @@ using ThingsGateway.NewLife.Caching; +using ThingsGateway.NewLife.Json.Extension; -namespace ThingsGateway.NewLife; +namespace ThingsGateway.Gateway.Razor; public static class VariableModelUtils { @@ -25,4 +26,56 @@ public static class VariableModelUtils return ret; } } + + public static string GetValue(VariableRuntime row, string fieldName) + { + switch (fieldName) + { + case nameof(VariableRuntime.Value): + return row.Value?.ToSystemTextJsonString() ?? string.Empty; + case nameof(VariableRuntime.RawValue): + return row.RawValue?.ToSystemTextJsonString() ?? string.Empty; + case nameof(VariableRuntime.LastSetValue): + return row.LastSetValue?.ToSystemTextJsonString() ?? string.Empty; + case nameof(VariableRuntime.ChangeTime): + return row.ChangeTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); + + case nameof(VariableRuntime.CollectTime): + return row.CollectTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); + + case nameof(VariableRuntime.IsOnline): + return row.IsOnline.ToString(); + + case nameof(VariableRuntime.LastErrorMessage): + return row.LastErrorMessage; + + + case nameof(VariableRuntime.RuntimeType): + return row.RuntimeType; + default: + + var ret = VariableModelUtils.GetPropertyValue(row, fieldName); + + if (ret != null) + { + var t = ret.GetType(); + if (t.IsEnum) + { + // 如果是枚举这里返回 枚举的描述信息 + var itemName = ret.ToString(); + if (!string.IsNullOrEmpty(itemName)) + { + ret = Utility.GetDisplayName(t, itemName); + } + } + } + return ret is string str ? str : ret?.ToString() ?? string.Empty; + } + } + + internal static Alignment GetAlign(this ITableColumn col) => col.Align ?? Alignment.None; + internal static bool GetTextWrap(this ITableColumn col) => col.TextWrap ?? false; + internal static bool GetShowTips(this ITableColumn col) => col.ShowTips ?? false; + + internal static bool GetTextEllipsis(this ITableColumn col) => col.TextEllipsis ?? false; } diff --git a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor index 5a24d8b56..6df07d544 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor @@ -1,4 +1,4 @@ -@* @namespace ThingsGateway.Gateway.Razor +@namespace ThingsGateway.Gateway.Razor @using System.Text.Json.Nodes @using Microsoft.Extensions.Hosting @using ThingsGateway.Admin.Application @@ -9,12 +9,18 @@ @foreach (var col in RowContent.Columns) { - - - @GetValue(col, RowContent.Row) - + +
+ @if(col.GetShowTips()) + { + + @VariableModelUtils.GetValue(RowContent.Row, col.GetFieldName()) + + } + else + { + @VariableModelUtils.GetValue(RowContent.Row, col.GetFieldName()) + } +
} - *@ \ No newline at end of file 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 index a4f8e7589..441ea983c 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor.cs +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRow.razor.cs @@ -1,279 +1,249 @@ -////------------------------------------------------------------------------------ -//// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 -//// 此代码版权(除特别声明外的代码)归作者本人Diego所有 -//// 源代码使用协议遵循本仓库的开源协议及附加协议 -//// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway -//// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway -//// 使用文档:https://thingsgateway.cn/ -//// QQ群:605534569 -////------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 +// 此代码版权(除特别声明外的代码)归作者本人Diego所有 +// 源代码使用协议遵循本仓库的开源协议及附加协议 +// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway +// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway +// 使用文档:https://thingsgateway.cn/ +// QQ群:605534569 +//------------------------------------------------------------------------------ -//using System.Collections.Concurrent; +using System.Collections.Concurrent; -//using ThingsGateway.NewLife.Threading; +namespace ThingsGateway.Gateway.Razor; -//using TouchSocket.Core; +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); + //} -//namespace ThingsGateway.Gateway.Razor; + //private Task Refresh(object? state) + //{ + // if (!Disposed) + // return InvokeAsync(StateHasChanged); + // else + // return Task.CompletedTask; + //} -//public partial class VariableRow : IDisposable -//{ -// [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); -// } + protected override void OnParametersSet() + { + FixedCellClassStringCache?.Clear(); + CellClassStringCache?.Clear(); + base.OnParametersSet(); + } -// private Task Refresh(object? state) -// { -// if (!Disposed) -// return InvokeAsync(StateHasChanged); -// else -// return Task.CompletedTask; -// } + /// + /// 获得指定列头固定列样式 + /// + /// + /// + /// + protected string? GetFixedCellStyleString(ITableColumn col, int margin = 0) + { + string? ret = null; + if (col.Fixed) + { + ret = IsTail(col) ? GetRightStyle(col, margin) : GetLeftStyle(col); + } + return ret; + } -// protected override void OnParametersSet() -// { -// FixedCellClassStringCache?.Clear(); -// CellClassStringCache?.Clear(); -// base.OnParametersSet(); -// } -// /// -// /// 获得 指定单元格数据方法 -// /// -// /// -// /// -// /// -// protected static RenderFragment GetValue(ITableColumn col, VariableRuntime item) => builder => -// { -// if (col.Template != null) -// { -// builder.AddContent(0, col.Template(item)); -// } -// else if (col.ComponentType == typeof(ColorPicker)) -// { -// // 自动化处理 ColorPicker 组件 -// builder.AddContent(10, col.RenderColor(item)); -// } -// else -// { -// builder.AddContent(20, col.RenderValue(item)); -// } -// }; + 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; -// // internal static string? GetDoubleClickCellClassString(bool trigger) => CssBuilder.Default() -// //.AddClass("is-dbcell", trigger) -// //.Build(); + private string? GetRightStyle(ITableColumn col, int margin) + { + var columns = RowContent.Columns.ToList(); + var defaultWidth = 200; + var width = 0; + var index = columns.IndexOf(col); -// /// -// /// 获得指定列头固定列样式 -// /// -// /// -// /// -// /// -// protected string? GetFixedCellStyleString(ITableColumn col, int margin = 0) -// { -// string? ret = null; -// if (col.Fixed) -// { -// ret = IsTail(col) ? GetRightStyle(col, margin) : GetLeftStyle(col); -// } -// return ret; -// } + // after + while (index + 1 < columns.Count) + { + var column = columns[index++]; + width += column.Width ?? defaultWidth; + } + //if (ShowExtendButtons && FixedExtendButtonsColumn) + { + width += ExtendButtonColumnWidth; + } -// 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; + // 如果是固定表头时增加滚动条位置 + if (IsFixedHeader && (index + 1) == columns.Count) + { + width += margin; + } + return $"right: {width}px;"; + } + private bool IsFixedHeader = true; -// 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; + 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); + 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()); -// } + /// + /// 获得 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 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()); + 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(col.GetFieldName()) + .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(); + [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 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; -// }); + } + } + 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/VariableRowHelpers.cs b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRowHelpers.cs deleted file mode 100644 index ff68c8271..000000000 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRowHelpers.cs +++ /dev/null @@ -1,60 +0,0 @@ -////------------------------------------------------------------------------------ -//// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充 -//// 此代码版权(除特别声明外的代码)归作者本人Diego所有 -//// 源代码使用协议遵循本仓库的开源协议及附加协议 -//// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway -//// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway -//// 使用文档:https://thingsgateway.cn/ -//// QQ群:605534569 -////------------------------------------------------------------------------------ - -//namespace ThingsGateway.Gateway.Razor; - -//internal static class VariableRowHelpers -//{ -// internal static Alignment GetAlign(this ITableColumn col) => col.Align ?? Alignment.None; -// internal static bool GetTextWrap(this ITableColumn col) => col.TextWrap ?? false; -// internal static bool GetShowTips(this ITableColumn col) => col.ShowTips ?? false; - - -// internal static RenderFragment RenderColor(this ITableColumn col, TItem item) => builder => -// { -// var val = GetItemValue(col, item); -// var v = val?.ToString() ?? "#000"; -// var style = $"background-color: {v};"; -// builder.OpenElement(0, "div"); -// builder.AddAttribute(1, "class", "is-color"); -// builder.AddAttribute(2, "style", style); -// builder.CloseElement(); -// }; -// internal static object? GetItemValue(this ITableColumn col, TItem item) -// { -// var fieldName = col.GetFieldName(); -// object? ret; -// if (item is IDynamicObject dynamicObject) -// { -// ret = dynamicObject.GetValue(fieldName); -// } -// else -// { -// ret = Utility.GetPropertyValue(item, fieldName); - -// if (ret != null) -// { -// var t = ret.GetType(); -// if (t.IsEnum) -// { -// // 如果是枚举这里返回 枚举的描述信息 -// var itemName = ret.ToString(); -// if (!string.IsNullOrEmpty(itemName)) -// { -// ret = Utility.GetDisplayName(t, itemName); -// } -// } -// } -// } -// return ret; -// } -// internal static bool GetTextEllipsis(this ITableColumn col) => col.TextEllipsis ?? false; - -//} \ No newline at end of file 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 4121baba4..b5b8e6016 100644 --- a/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor +++ b/src/Gateway/ThingsGateway.Gateway.Razor/Pages/GatewayMonitorPage/Variable/VariableRuntimeInfo.razor @@ -12,6 +12,8 @@ -@* + - *@ + @if ((AuthorizeButton("导出"))) 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 1eaebfdc9..7b3754212 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 @@ -16,7 +16,6 @@ using ThingsGateway.Admin.Application; using ThingsGateway.Admin.Razor; using ThingsGateway.DB; using ThingsGateway.Extension.Generic; -using ThingsGateway.NewLife; using ThingsGateway.NewLife.Json.Extension; namespace ThingsGateway.Gateway.Razor; @@ -62,7 +61,10 @@ public partial class VariableRuntimeInfo public ToastService? ToastService { get; set; } #region js - + private List ColumnsFunc() + { + return table.Columns; + } protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new { Method = nameof(TriggerStateChanged) }); private Task OnColumnVisibleChanged(string name, bool visible) @@ -97,60 +99,7 @@ public partial class VariableRuntimeInfo foreach (var col in _cachedFields) { var fieldName = col.GetFieldName(); - switch (fieldName) - { - case nameof(VariableRuntime.Value): - list.Add(new(fieldName, row.Value?.ToSystemTextJsonString() ?? string.Empty)); - break; - case nameof(VariableRuntime.RawValue): - list.Add(new(fieldName, row.RawValue?.ToSystemTextJsonString() ?? string.Empty)); - break; - case nameof(VariableRuntime.LastSetValue): - list.Add(new(fieldName, row.LastSetValue?.ToSystemTextJsonString() ?? string.Empty)); - break; - case nameof(VariableRuntime.ChangeTime): - list.Add(new(fieldName, row.ChangeTime.ToString("yyyy-MM-dd HH:mm:ss.fff"))); - break; - - case nameof(VariableRuntime.CollectTime): - list.Add(new(fieldName, row.CollectTime.ToString("yyyy-MM-dd HH:mm:ss.fff"))); - break; - - case nameof(VariableRuntime.IsOnline): - list.Add(new(fieldName, row.IsOnline.ToString())); - break; - - case nameof(VariableRuntime.LastErrorMessage): - list.Add(new(fieldName, row.LastErrorMessage)); - break; - - - case nameof(VariableRuntime.RuntimeType): - list.Add(new(fieldName, row.RuntimeType)); - break; - - default: - - var ret = VariableModelUtils.GetPropertyValue(row, fieldName); - - if (ret != null) - { - var t = ret.GetType(); - if (t.IsEnum) - { - // 如果是枚举这里返回 枚举的描述信息 - var itemName = ret.ToString(); - if (!string.IsNullOrEmpty(itemName)) - { - ret = Utility.GetDisplayName(t, itemName); - } - } - } - - list.Add(new(fieldName, ret is string str ? str : ret?.ToString() ?? string.Empty)); - break; - } - + list.Add(new(fieldName, VariableModelUtils.GetValue(row,fieldName))); } return list; 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 499a23381..786927ec7 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 @@ -41,45 +41,54 @@ if (!cell) continue; // 查找 tooltip span - var tooltipSpan = cell.querySelector('.bb-tooltip'); - if (tooltipSpan) { - tooltipSpan.innerText = cellValue ?? ''; // 更新显示文字 - tooltipSpan.setAttribute('data-bs-original-title', cellValue ?? ''); // 同步 tooltip 提示 - continue; - } + var cellDiv = cell.querySelector('.table-cell'); + if (cellDiv) { + var tooltipSpan = cell.querySelector('.bb-tooltip'); + if (tooltipSpan) { - // 查找 switch - var switchDiv = cell.querySelector('.switch'); - if (switchDiv) { - if (cellValue === true || cellValue === "on" || cellValue === "True" || cellValue === "true") { - switchDiv.classList.add('is-checked'); - switchDiv.classList.add('enable'); - switchDiv.classList.remove('is-unchecked'); - switchDiv.classList.remove('disabled'); + tooltipSpan.innerText = cellValue ?? ''; // 更新显示文字 + tooltipSpan.setAttribute('data-bs-original-title', cellValue ?? ''); // 同步 tooltip 提示 + continue; - switchDiv.querySelectorAll('span')[0].classList.add('border-success'); - switchDiv.querySelectorAll('span')[0].classList.add('bg-success'); - } else { - switchDiv.classList.remove('is-checked'); - switchDiv.classList.remove('enable'); - switchDiv.classList.add('is-unchecked'); - switchDiv.classList.add('disabled'); - - switchDiv.querySelectorAll('span')[0].classList.remove('border-success'); - switchDiv.querySelectorAll('span')[0].classList.remove('bg-success'); } - continue; + else { + cellDiv.innerText = cellValue ?? ''; + } } - // 默认情况(普通单元格) - getCellByClass(row, cellName).innerText = cellValue; + + //// 查找 switch + //var switchDiv = cell.querySelector('.switch'); + //if (switchDiv) { + // if (cellValue === true || cellValue === "on" || cellValue === "True" || cellValue === "true") { + // switchDiv.classList.add('is-checked'); + // switchDiv.classList.add('enable'); + // switchDiv.classList.remove('is-unchecked'); + // switchDiv.classList.remove('disabled'); + + // switchDiv.querySelectorAll('span')[0].classList.add('border-success'); + // switchDiv.querySelectorAll('span')[0].classList.add('bg-success'); + + // } else { + // switchDiv.classList.remove('is-checked'); + // switchDiv.classList.remove('enable'); + // switchDiv.classList.add('is-unchecked'); + // switchDiv.classList.add('disabled'); + + // switchDiv.querySelectorAll('span')[0].classList.remove('border-success'); + // switchDiv.querySelectorAll('span')[0].classList.remove('bg-success'); + // } + // continue; + //} + //// 默认情况(普通单元格) + //getCellByClass(row, cellName).innerText = cellValue; } } } - , 1000) //1000ms刷新一次 + , 500) //1000ms刷新一次 }