87 lines
2.5 KiB
C#
87 lines
2.5 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Windows.Media;
|
|
|
|
namespace SHH.CameraDashboard
|
|
{
|
|
|
|
// 1. 单个节点的数据模型
|
|
public class ServerNode : INotifyPropertyChanged
|
|
{
|
|
private string _name = "新节点"; // 默认名称
|
|
public string Name
|
|
{
|
|
get => _name;
|
|
set { _name = value; OnPropertyChanged(); }
|
|
}
|
|
|
|
private string _ip = "127.0.0.1";
|
|
public string Ip
|
|
{
|
|
get => _ip;
|
|
set
|
|
{
|
|
if (_ip != value)
|
|
{
|
|
_ip = value;
|
|
OnPropertyChanged(); // 通知界面更新
|
|
}
|
|
}
|
|
}
|
|
|
|
private int _port = 5000;
|
|
public int Port
|
|
{
|
|
get => _port;
|
|
set
|
|
{
|
|
if (_port != value)
|
|
{
|
|
_port = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
private string _status = "未检测";
|
|
public string Status
|
|
{
|
|
get => _status;
|
|
set
|
|
{
|
|
_status = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(StatusColor)); // 状态变了,颜色也要跟着变
|
|
}
|
|
}
|
|
public Brush StatusColor
|
|
{
|
|
get
|
|
{
|
|
switch (Status)
|
|
{
|
|
case "✅ 连接成功":
|
|
return new SolidColorBrush(Color.FromRgb(78, 201, 176)); // 绿色
|
|
case "❌ 状态码异常":
|
|
return new SolidColorBrush(Color.FromRgb(255, 140, 0)); // 橙色 (警告)
|
|
case "❌ 无法连接":
|
|
return new SolidColorBrush(Color.FromRgb(244, 71, 71)); // 红色 (故障)
|
|
case "⏳ 检测中...":
|
|
return new SolidColorBrush(Color.FromRgb(86, 156, 214)); // 蓝色
|
|
default:
|
|
return new SolidColorBrush(Color.FromRgb(153, 153, 153)); // 灰色
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetResult(bool success, string msg)
|
|
{
|
|
Status = msg;
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
protected void OnPropertyChanged([CallerMemberName] string name = null)
|
|
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
|
|
} |