|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.ComponentModel;
|
|
|
using System.Linq;
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
namespace AI.Models.Form
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 表单字段条目:schema + 当前值,用于绑定与提交
|
|
|
/// </summary>
|
|
|
public class FormFieldEntry : INotifyPropertyChanged
|
|
|
{
|
|
|
private string _currentValue = string.Empty;
|
|
|
|
|
|
public string Id { get; set; } = string.Empty;
|
|
|
public string Label { get; set; } = string.Empty;
|
|
|
/// <summary>可选描述/提示</summary>
|
|
|
public string? Description { get; set; }
|
|
|
public FormFieldType Type { get; set; }
|
|
|
public bool Required { get; set; }
|
|
|
public object? DefaultValue { get; set; }
|
|
|
public List<string>? Options { get; set; }
|
|
|
|
|
|
// ----- number -----
|
|
|
public double? Min { get; set; }
|
|
|
public double? Max { get; set; }
|
|
|
public double? Step { get; set; }
|
|
|
// ----- string -----
|
|
|
public int? MaxLength { get; set; }
|
|
|
public string? Placeholder { get; set; }
|
|
|
// ----- multi-select -----
|
|
|
public List<string>? DefaultValues { get; set; }
|
|
|
/// <summary>多选当前选中项(MultiSelect 绑定用)</summary>
|
|
|
public ObservableCollection<string> SelectedValues { get; } = new ObservableCollection<string>();
|
|
|
/// <summary>多选选项列表(用于绑定 CheckBox 列表,与 SelectedValues 同步)</summary>
|
|
|
public ObservableCollection<MultiSelectOptionItem> MultiSelectOptions { get; } = new ObservableCollection<MultiSelectOptionItem>();
|
|
|
|
|
|
/// <summary>当前输入值(绑定用,提交时按 Type 转换)</summary>
|
|
|
public string CurrentValue
|
|
|
{
|
|
|
get => _currentValue;
|
|
|
set => SetProperty(ref _currentValue, value);
|
|
|
}
|
|
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
|
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) =>
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
|
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
|
|
{
|
|
|
if (EqualityComparer<T>.Default.Equals(field, value))
|
|
|
return false;
|
|
|
field = value;
|
|
|
OnPropertyChanged(propertyName);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|