You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.5 KiB

using System.ComponentModel;
using System.Runtime.CompilerServices;
using SparkClient.ViewModel.Configuration;
namespace SparkClient.Model.Entity;
public class AgileJsonConfigEntity
{
private readonly AlgorithmConfigVM _vm;
private readonly List<string> _keys;
public AgileJsonConfigEntity(AlgorithmConfigVM vm, List<string> keys)
{
_vm = vm;
_mode = 0;
Shape = "圆形";
Spec = _vm.GetSpecOptions(_mode).FirstOrDefault();
_keys = keys;
JsonKeys = keys;
}
private int _mode;
public int Mode
{
get => _mode;
set
{
if (_mode == value) return;
_mode = value;
OnPropertyChanged();
// 自动更新规格
Spec = _vm.GetSpecOptions(value).FirstOrDefault();
}
}
private string _spec;
public string Spec
{
get => _spec;
set => SetField(ref _spec, value);
}
private string _shape;
public string Shape
{
get => _shape;
private set => SetField(ref _shape, value);
}
private string _jsonKey;
public string JsonKey
{
get => _jsonKey;
set
{
SetField(ref _jsonKey, value);
FilterItems(value);
}
}
private string _value;
public string Value
{
get => _value;
set => SetField(ref _value, value);
}
private List<string> _jsonKeys;
public List<string> JsonKeys
{
get => _jsonKeys;
set => SetField(ref _jsonKeys, value);
}
private string GetDefaultSpec(int mode)
{
return mode switch
{
0 => "p8-p8",
1 => "p8-p8-s1",
_ => null
};
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string name = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(name);
return true;
}
private void FilterItems(string key)
{
JsonKeys.Clear();
foreach (var data in _keys)
{
if (data.ToLower().Contains(key.ToLower()))
{
JsonKeys.Add(data);
}
}
}
}