8 changed files with 1079 additions and 5 deletions
@ -0,0 +1,458 @@ |
|||
using AuroraDesk.Presentation.ViewModels.Base; |
|||
using ReactiveUI; |
|||
using System.Collections.ObjectModel; |
|||
using System.Reactive; |
|||
|
|||
namespace AuroraDesk.Presentation.ViewModels.Pages; |
|||
|
|||
/// <summary>
|
|||
/// 表单类型枚举
|
|||
/// </summary>
|
|||
public enum FormType |
|||
{ |
|||
Basic, // 基础表单(垂直布局,全字段)
|
|||
Simple, // 简洁表单(水平布局,标签和输入框一行)
|
|||
Contact, // 联系表单(包含下拉框选择)
|
|||
Feedback, // 反馈表单(包含复选框)
|
|||
Register // 注册表单(两列布局)
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 表单页面 ViewModel
|
|||
/// </summary>
|
|||
public class FormPageViewModel : RoutableViewModel |
|||
{ |
|||
private bool _isFormDialogOpen; |
|||
private FormType _currentFormType = FormType.Basic; |
|||
private string _formTitle = "填写表单"; |
|||
private string _formDescription = "请填写以下信息"; |
|||
private string _name = string.Empty; |
|||
private string _email = string.Empty; |
|||
private string _phone = string.Empty; |
|||
private string _address = string.Empty; |
|||
private string _remarks = string.Empty; |
|||
private string _submitResult = string.Empty; |
|||
private string _selectedCountry = string.Empty; |
|||
private string _selectedCity = string.Empty; |
|||
private bool _agreeTerms = false; |
|||
private bool _subscribeNewsletter = false; |
|||
private bool _receiveNotifications = false; |
|||
|
|||
/// <summary>
|
|||
/// 构造函数
|
|||
/// </summary>
|
|||
/// <param name="hostScreen">宿主 Screen</param>
|
|||
public FormPageViewModel(IScreen hostScreen) : base(hostScreen, "Form") |
|||
{ |
|||
// 初始化下拉框选项
|
|||
Countries = new ObservableCollection<string> { "中国", "美国", "日本", "韩国", "英国", "德国", "法国", "其他" }; |
|||
Cities = new ObservableCollection<string> { "北京", "上海", "广州", "深圳", "杭州", "成都", "其他" }; |
|||
|
|||
ShowBasicFormCommand = ReactiveCommand.Create(() => ShowForm(FormType.Basic)); |
|||
ShowSimpleFormCommand = ReactiveCommand.Create(() => ShowForm(FormType.Simple)); |
|||
ShowContactFormCommand = ReactiveCommand.Create(() => ShowForm(FormType.Contact)); |
|||
ShowFeedbackFormCommand = ReactiveCommand.Create(() => ShowForm(FormType.Feedback)); |
|||
ShowRegisterFormCommand = ReactiveCommand.Create(() => ShowForm(FormType.Register)); |
|||
SubmitFormCommand = ReactiveCommand.Create(SubmitForm); |
|||
CancelFormCommand = ReactiveCommand.Create(CancelForm); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 是否显示表单对话框
|
|||
/// </summary>
|
|||
public bool IsFormDialogOpen |
|||
{ |
|||
get => _isFormDialogOpen; |
|||
set => this.RaiseAndSetIfChanged(ref _isFormDialogOpen, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 当前表单类型
|
|||
/// </summary>
|
|||
public FormType CurrentFormType |
|||
{ |
|||
get => _currentFormType; |
|||
set => this.RaiseAndSetIfChanged(ref _currentFormType, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 表单标题
|
|||
/// </summary>
|
|||
public string FormTitle |
|||
{ |
|||
get => _formTitle; |
|||
set => this.RaiseAndSetIfChanged(ref _formTitle, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 表单描述
|
|||
/// </summary>
|
|||
public string FormDescription |
|||
{ |
|||
get => _formDescription; |
|||
set => this.RaiseAndSetIfChanged(ref _formDescription, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 是否显示电话字段
|
|||
/// </summary>
|
|||
public bool ShowPhoneField => CurrentFormType == FormType.Basic || |
|||
CurrentFormType == FormType.Contact || |
|||
CurrentFormType == FormType.Register; |
|||
|
|||
/// <summary>
|
|||
/// 是否显示地址字段
|
|||
/// </summary>
|
|||
public bool ShowAddressField => CurrentFormType == FormType.Basic || |
|||
CurrentFormType == FormType.Register; |
|||
|
|||
/// <summary>
|
|||
/// 是否显示备注字段
|
|||
/// </summary>
|
|||
public bool ShowRemarksField => CurrentFormType == FormType.Basic || |
|||
CurrentFormType == FormType.Feedback; |
|||
|
|||
/// <summary>
|
|||
/// 是否使用水平布局(标签和输入框在一行)
|
|||
/// </summary>
|
|||
public bool UseHorizontalLayout => CurrentFormType == FormType.Simple; |
|||
|
|||
/// <summary>
|
|||
/// 是否使用两列布局
|
|||
/// </summary>
|
|||
public bool UseTwoColumnLayout => CurrentFormType == FormType.Register; |
|||
|
|||
/// <summary>
|
|||
/// 是否显示下拉框字段
|
|||
/// </summary>
|
|||
public bool ShowComboBoxFields => CurrentFormType == FormType.Contact; |
|||
|
|||
/// <summary>
|
|||
/// 是否显示复选框字段
|
|||
/// </summary>
|
|||
public bool ShowCheckBoxFields => CurrentFormType == FormType.Feedback; |
|||
|
|||
/// <summary>
|
|||
/// 国家列表
|
|||
/// </summary>
|
|||
public ObservableCollection<string> Countries { get; } |
|||
|
|||
/// <summary>
|
|||
/// 城市列表
|
|||
/// </summary>
|
|||
public ObservableCollection<string> Cities { get; } |
|||
|
|||
/// <summary>
|
|||
/// 选中的国家
|
|||
/// </summary>
|
|||
public string SelectedCountry |
|||
{ |
|||
get => _selectedCountry; |
|||
set => this.RaiseAndSetIfChanged(ref _selectedCountry, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 选中的城市
|
|||
/// </summary>
|
|||
public string SelectedCity |
|||
{ |
|||
get => _selectedCity; |
|||
set => this.RaiseAndSetIfChanged(ref _selectedCity, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 同意条款
|
|||
/// </summary>
|
|||
public bool AgreeTerms |
|||
{ |
|||
get => _agreeTerms; |
|||
set => this.RaiseAndSetIfChanged(ref _agreeTerms, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 订阅 newsletter
|
|||
/// </summary>
|
|||
public bool SubscribeNewsletter |
|||
{ |
|||
get => _subscribeNewsletter; |
|||
set => this.RaiseAndSetIfChanged(ref _subscribeNewsletter, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 接收通知
|
|||
/// </summary>
|
|||
public bool ReceiveNotifications |
|||
{ |
|||
get => _receiveNotifications; |
|||
set => this.RaiseAndSetIfChanged(ref _receiveNotifications, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 姓名
|
|||
/// </summary>
|
|||
public string Name |
|||
{ |
|||
get => _name; |
|||
set => this.RaiseAndSetIfChanged(ref _name, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 邮箱
|
|||
/// </summary>
|
|||
public string Email |
|||
{ |
|||
get => _email; |
|||
set => this.RaiseAndSetIfChanged(ref _email, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 电话
|
|||
/// </summary>
|
|||
public string Phone |
|||
{ |
|||
get => _phone; |
|||
set => this.RaiseAndSetIfChanged(ref _phone, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 地址
|
|||
/// </summary>
|
|||
public string Address |
|||
{ |
|||
get => _address; |
|||
set => this.RaiseAndSetIfChanged(ref _address, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 备注
|
|||
/// </summary>
|
|||
public string Remarks |
|||
{ |
|||
get => _remarks; |
|||
set => this.RaiseAndSetIfChanged(ref _remarks, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 提交结果
|
|||
/// </summary>
|
|||
public string SubmitResult |
|||
{ |
|||
get => _submitResult; |
|||
set => this.RaiseAndSetIfChanged(ref _submitResult, value); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 显示基础表单命令
|
|||
/// </summary>
|
|||
public ReactiveCommand<Unit, Unit> ShowBasicFormCommand { get; } |
|||
|
|||
/// <summary>
|
|||
/// 显示简洁表单命令
|
|||
/// </summary>
|
|||
public ReactiveCommand<Unit, Unit> ShowSimpleFormCommand { get; } |
|||
|
|||
/// <summary>
|
|||
/// 显示联系表单命令
|
|||
/// </summary>
|
|||
public ReactiveCommand<Unit, Unit> ShowContactFormCommand { get; } |
|||
|
|||
/// <summary>
|
|||
/// 显示反馈表单命令
|
|||
/// </summary>
|
|||
public ReactiveCommand<Unit, Unit> ShowFeedbackFormCommand { get; } |
|||
|
|||
/// <summary>
|
|||
/// 显示注册表单命令
|
|||
/// </summary>
|
|||
public ReactiveCommand<Unit, Unit> ShowRegisterFormCommand { get; } |
|||
|
|||
/// <summary>
|
|||
/// 提交表单命令
|
|||
/// </summary>
|
|||
public ReactiveCommand<Unit, Unit> SubmitFormCommand { get; } |
|||
|
|||
/// <summary>
|
|||
/// 取消表单命令
|
|||
/// </summary>
|
|||
public ReactiveCommand<Unit, Unit> CancelFormCommand { get; } |
|||
|
|||
private void ShowForm(FormType formType) |
|||
{ |
|||
// 重置表单数据
|
|||
Name = string.Empty; |
|||
Email = string.Empty; |
|||
Phone = string.Empty; |
|||
Address = string.Empty; |
|||
Remarks = string.Empty; |
|||
SelectedCountry = string.Empty; |
|||
SelectedCity = string.Empty; |
|||
AgreeTerms = false; |
|||
SubscribeNewsletter = false; |
|||
ReceiveNotifications = false; |
|||
SubmitResult = string.Empty; |
|||
|
|||
// 设置表单类型
|
|||
CurrentFormType = formType; |
|||
|
|||
// 根据表单类型设置标题和描述
|
|||
switch (formType) |
|||
{ |
|||
case FormType.Basic: |
|||
FormTitle = "基础表单"; |
|||
FormDescription = "垂直布局,标签在上输入框在下"; |
|||
break; |
|||
case FormType.Simple: |
|||
FormTitle = "简洁表单"; |
|||
FormDescription = "水平布局,标签和输入框在同一行"; |
|||
break; |
|||
case FormType.Contact: |
|||
FormTitle = "联系表单"; |
|||
FormDescription = "包含下拉框选择国家/城市"; |
|||
break; |
|||
case FormType.Feedback: |
|||
FormTitle = "反馈表单"; |
|||
FormDescription = "包含复选框选项"; |
|||
break; |
|||
case FormType.Register: |
|||
FormTitle = "注册表单"; |
|||
FormDescription = "两列布局,充分利用空间"; |
|||
break; |
|||
} |
|||
|
|||
// 触发所有属性更新
|
|||
this.RaisePropertyChanged(nameof(ShowPhoneField)); |
|||
this.RaisePropertyChanged(nameof(ShowAddressField)); |
|||
this.RaisePropertyChanged(nameof(ShowRemarksField)); |
|||
this.RaisePropertyChanged(nameof(UseHorizontalLayout)); |
|||
this.RaisePropertyChanged(nameof(UseTwoColumnLayout)); |
|||
this.RaisePropertyChanged(nameof(ShowComboBoxFields)); |
|||
this.RaisePropertyChanged(nameof(ShowCheckBoxFields)); |
|||
|
|||
// 显示对话框
|
|||
IsFormDialogOpen = true; |
|||
} |
|||
|
|||
private void SubmitForm() |
|||
{ |
|||
// 验证必填字段
|
|||
if (string.IsNullOrWhiteSpace(Name)) |
|||
{ |
|||
SubmitResult = "错误:姓名不能为空"; |
|||
return; |
|||
} |
|||
|
|||
if (string.IsNullOrWhiteSpace(Email)) |
|||
{ |
|||
SubmitResult = "错误:邮箱不能为空"; |
|||
return; |
|||
} |
|||
|
|||
// 简单的邮箱格式验证
|
|||
if (!Email.Contains("@") || !Email.Contains(".")) |
|||
{ |
|||
SubmitResult = "错误:邮箱格式不正确"; |
|||
return; |
|||
} |
|||
|
|||
// 根据表单类型验证特定字段
|
|||
if (CurrentFormType == FormType.Contact || CurrentFormType == FormType.Register) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(Phone)) |
|||
{ |
|||
SubmitResult = "错误:电话不能为空"; |
|||
return; |
|||
} |
|||
} |
|||
|
|||
if (CurrentFormType == FormType.Register) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(Address)) |
|||
{ |
|||
SubmitResult = "错误:地址不能为空"; |
|||
return; |
|||
} |
|||
} |
|||
|
|||
if (CurrentFormType == FormType.Feedback) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(Remarks)) |
|||
{ |
|||
SubmitResult = "错误:反馈内容不能为空"; |
|||
return; |
|||
} |
|||
if (!AgreeTerms) |
|||
{ |
|||
SubmitResult = "错误:必须同意服务条款"; |
|||
return; |
|||
} |
|||
} |
|||
|
|||
if (CurrentFormType == FormType.Contact) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(SelectedCountry)) |
|||
{ |
|||
SubmitResult = "错误:请选择国家"; |
|||
return; |
|||
} |
|||
if (string.IsNullOrWhiteSpace(SelectedCity)) |
|||
{ |
|||
SubmitResult = "错误:请选择城市"; |
|||
return; |
|||
} |
|||
} |
|||
|
|||
// 关闭对话框
|
|||
IsFormDialogOpen = false; |
|||
|
|||
// 显示提交结果
|
|||
var formTypeName = CurrentFormType switch |
|||
{ |
|||
FormType.Basic => "基础表单", |
|||
FormType.Simple => "简洁表单", |
|||
FormType.Contact => "联系表单", |
|||
FormType.Feedback => "反馈表单", |
|||
FormType.Register => "注册表单", |
|||
_ => "表单" |
|||
}; |
|||
|
|||
var result = $"[{formTypeName}] 提交成功!\n姓名:{Name}\n邮箱:{Email}"; |
|||
if (ShowPhoneField && !string.IsNullOrWhiteSpace(Phone)) |
|||
{ |
|||
result += $"\n电话:{Phone}"; |
|||
} |
|||
if (ShowAddressField && !string.IsNullOrWhiteSpace(Address)) |
|||
{ |
|||
result += $"\n地址:{Address}"; |
|||
} |
|||
if (ShowComboBoxFields) |
|||
{ |
|||
if (!string.IsNullOrWhiteSpace(SelectedCountry)) |
|||
{ |
|||
result += $"\n国家:{SelectedCountry}"; |
|||
} |
|||
if (!string.IsNullOrWhiteSpace(SelectedCity)) |
|||
{ |
|||
result += $"\n城市:{SelectedCity}"; |
|||
} |
|||
} |
|||
if (ShowRemarksField && !string.IsNullOrWhiteSpace(Remarks)) |
|||
{ |
|||
result += $"\n备注:{Remarks}"; |
|||
} |
|||
if (ShowCheckBoxFields) |
|||
{ |
|||
result += $"\n同意条款:{(AgreeTerms ? "是" : "否")}"; |
|||
result += $"\n订阅邮件:{(SubscribeNewsletter ? "是" : "否")}"; |
|||
result += $"\n接收通知:{(ReceiveNotifications ? "是" : "否")}"; |
|||
} |
|||
|
|||
SubmitResult = result; |
|||
} |
|||
|
|||
private void CancelForm() |
|||
{ |
|||
IsFormDialogOpen = false; |
|||
SubmitResult = "已取消提交"; |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,389 @@ |
|||
<reactive:ReactiveUserControl xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:vm="using:AuroraDesk.Presentation.ViewModels.Pages" |
|||
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia" |
|||
xmlns:heroicons="clr-namespace:HeroIconsAvalonia.Controls;assembly=HeroIconsAvalonia" |
|||
xmlns:reactive="using:ReactiveUI.Avalonia" |
|||
xmlns:converters="clr-namespace:AuroraDesk.Presentation.Converters;assembly=AuroraDesk.Presentation" |
|||
mc:Ignorable="d" |
|||
x:Class="AuroraDesk.Presentation.Views.Pages.FormPageView" |
|||
x:DataType="vm:FormPageViewModel"> |
|||
|
|||
<Design.DataContext> |
|||
<vm:FormPageViewModel /> |
|||
</Design.DataContext> |
|||
|
|||
<dialogHost:DialogHost IsOpen="{Binding IsFormDialogOpen}"> |
|||
<dialogHost:DialogHost.DialogContent> |
|||
<Border Background="{StaticResource BackgroundWhite}" |
|||
CornerRadius="16" |
|||
Padding="24" |
|||
Width="480" |
|||
MaxHeight="600"> |
|||
<ScrollViewer VerticalScrollBarVisibility="Auto"> |
|||
<StackPanel Spacing="18"> |
|||
<!-- 标题 --> |
|||
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="12"> |
|||
<Border Grid.Column="0" |
|||
Width="40" |
|||
Height="40" |
|||
CornerRadius="20" |
|||
Background="#3B82F6" |
|||
VerticalAlignment="Center"> |
|||
<heroicons:HeroIcon Type="DocumentText" |
|||
Width="22" |
|||
Height="22" |
|||
Foreground="White" |
|||
HorizontalAlignment="Center" |
|||
VerticalAlignment="Center"/> |
|||
</Border> |
|||
<StackPanel Grid.Column="1" Spacing="4"> |
|||
<TextBlock Text="{Binding FormTitle}" |
|||
FontSize="20" |
|||
FontWeight="SemiBold" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBlock Text="{Binding FormDescription}" |
|||
FontSize="14" |
|||
Foreground="{StaticResource SecondaryGrayDark}"/> |
|||
</StackPanel> |
|||
</Grid> |
|||
|
|||
<!-- 表单字段 --> |
|||
<StackPanel Spacing="16"> |
|||
<!-- 基础表单:垂直布局 --> |
|||
<StackPanel Spacing="16" IsVisible="{Binding UseHorizontalLayout, Converter={x:Static converters:StringConverters.BoolToVisibilityConverter}, ConverterParameter='Invert'}"> |
|||
<!-- 姓名 --> |
|||
<StackPanel Spacing="6"> |
|||
<TextBlock Text="姓名 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Name}" |
|||
Watermark="请输入姓名" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 邮箱 --> |
|||
<StackPanel Spacing="6"> |
|||
<TextBlock Text="邮箱 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Email}" |
|||
Watermark="请输入邮箱地址" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 电话 --> |
|||
<StackPanel Spacing="6" IsVisible="{Binding ShowPhoneField}"> |
|||
<TextBlock Text="电话 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Phone}" |
|||
Watermark="请输入电话号码" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 地址 --> |
|||
<StackPanel Spacing="6" IsVisible="{Binding ShowAddressField}"> |
|||
<TextBlock Text="地址 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Address}" |
|||
Watermark="请输入地址" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 备注 --> |
|||
<StackPanel Spacing="6" IsVisible="{Binding ShowRemarksField}"> |
|||
<TextBlock Text="备注 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Remarks}" |
|||
Watermark="请输入备注信息" |
|||
Padding="12,10" |
|||
AcceptsReturn="True" |
|||
TextWrapping="Wrap" |
|||
MinHeight="80" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 下拉框字段(联系表单) --> |
|||
<StackPanel Spacing="16" IsVisible="{Binding ShowComboBoxFields}"> |
|||
<StackPanel Spacing="6"> |
|||
<TextBlock Text="国家 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<ComboBox ItemsSource="{Binding Countries}" |
|||
SelectedItem="{Binding SelectedCountry}" |
|||
Padding="12,10" |
|||
FontSize="14" |
|||
PlaceholderText="请选择国家"/> |
|||
</StackPanel> |
|||
<StackPanel Spacing="6"> |
|||
<TextBlock Text="城市 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<ComboBox ItemsSource="{Binding Cities}" |
|||
SelectedItem="{Binding SelectedCity}" |
|||
Padding="12,10" |
|||
FontSize="14" |
|||
PlaceholderText="请选择城市"/> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
|
|||
<!-- 复选框字段(反馈表单) --> |
|||
<StackPanel Spacing="12" IsVisible="{Binding ShowCheckBoxFields}"> |
|||
<CheckBox Content="我已阅读并同意服务条款 *" |
|||
IsChecked="{Binding AgreeTerms}" |
|||
FontSize="14"/> |
|||
<CheckBox Content="订阅邮件通知" |
|||
IsChecked="{Binding SubscribeNewsletter}" |
|||
FontSize="14"/> |
|||
<CheckBox Content="接收系统通知" |
|||
IsChecked="{Binding ReceiveNotifications}" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
|
|||
<!-- 简洁表单:水平布局(标签和输入框在一行) --> |
|||
<StackPanel Spacing="16" IsVisible="{Binding UseHorizontalLayout}"> |
|||
<!-- 姓名 --> |
|||
<Grid ColumnDefinitions="100,*" ColumnSpacing="12"> |
|||
<TextBlock Grid.Column="0" |
|||
Text="姓名 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}" |
|||
VerticalAlignment="Center"/> |
|||
<TextBox Grid.Column="1" |
|||
Text="{Binding Name}" |
|||
Watermark="请输入姓名" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</Grid> |
|||
|
|||
<!-- 邮箱 --> |
|||
<Grid ColumnDefinitions="100,*" ColumnSpacing="12"> |
|||
<TextBlock Grid.Column="0" |
|||
Text="邮箱 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}" |
|||
VerticalAlignment="Center"/> |
|||
<TextBox Grid.Column="1" |
|||
Text="{Binding Email}" |
|||
Watermark="请输入邮箱地址" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</Grid> |
|||
</StackPanel> |
|||
|
|||
<!-- 注册表单:两列布局 --> |
|||
<Grid ColumnDefinitions="*,*" ColumnSpacing="16" RowDefinitions="Auto,Auto,Auto,Auto" |
|||
IsVisible="{Binding UseTwoColumnLayout}"> |
|||
<!-- 第一行:姓名 --> |
|||
<StackPanel Grid.Row="0" Grid.Column="0" Spacing="6"> |
|||
<TextBlock Text="姓名 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Name}" |
|||
Watermark="请输入姓名" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第一行:邮箱 --> |
|||
<StackPanel Grid.Row="0" Grid.Column="1" Spacing="6"> |
|||
<TextBlock Text="邮箱 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Email}" |
|||
Watermark="请输入邮箱地址" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第二行:电话 --> |
|||
<StackPanel Grid.Row="1" Grid.Column="0" Spacing="6"> |
|||
<TextBlock Text="电话 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Phone}" |
|||
Watermark="请输入电话号码" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第二行:地址 --> |
|||
<StackPanel Grid.Row="1" Grid.Column="1" Spacing="6"> |
|||
<TextBlock Text="地址 *" |
|||
FontSize="14" |
|||
FontWeight="Medium" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBox Text="{Binding Address}" |
|||
Watermark="请输入地址" |
|||
Padding="12,10" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
</Grid> |
|||
</StackPanel> |
|||
|
|||
<!-- 错误提示 --> |
|||
<Border Background="#FEE2E2" |
|||
BorderBrush="#FCA5A5" |
|||
BorderThickness="1" |
|||
CornerRadius="8" |
|||
Padding="12" |
|||
IsVisible="{Binding SubmitResult, Converter={x:Static converters:StringConverters.IsNotNullOrEmptyConverter}}"> |
|||
<TextBlock Text="{Binding SubmitResult}" |
|||
Foreground="#DC2626" |
|||
TextWrapping="Wrap" |
|||
FontSize="13"/> |
|||
</Border> |
|||
|
|||
<!-- 按钮 --> |
|||
<StackPanel Orientation="Horizontal" |
|||
HorizontalAlignment="Right" |
|||
Spacing="10"> |
|||
<Button Content="取消" |
|||
MinWidth="96" |
|||
Command="{Binding CancelFormCommand}"/> |
|||
<Button Content="提交" |
|||
MinWidth="96" |
|||
Command="{Binding SubmitFormCommand}" |
|||
Background="#3B82F6" |
|||
Foreground="White" |
|||
BorderThickness="0" |
|||
CornerRadius="8"/> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
</ScrollViewer> |
|||
</Border> |
|||
</dialogHost:DialogHost.DialogContent> |
|||
|
|||
<Grid RowDefinitions="Auto,Auto,*" ColumnDefinitions="*" Margin="20" Background="Transparent"> |
|||
<!-- 标题区域 --> |
|||
<StackPanel Spacing="8"> |
|||
<TextBlock Text="表单示例" |
|||
FontSize="20" |
|||
FontWeight="SemiBold" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBlock Text="点击下方不同按钮打开不同类型的表单对话框,每种表单包含不同的字段组合。" |
|||
FontSize="14" |
|||
Foreground="{StaticResource SecondaryGrayDark}"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 按钮区域 --> |
|||
<WrapPanel Grid.Row="1" |
|||
Margin="0,18,0,0" |
|||
Orientation="Horizontal"> |
|||
<Button Content="基础表单" |
|||
Padding="18,10" |
|||
Margin="0,0,12,12" |
|||
Command="{Binding ShowBasicFormCommand}" |
|||
Background="#3B82F6" |
|||
BorderBrush="Transparent" |
|||
Foreground="White" |
|||
CornerRadius="10"> |
|||
<Button.Styles> |
|||
<Style Selector="Button:pointerover"> |
|||
<Setter Property="Background" Value="#2563EB"/> |
|||
</Style> |
|||
</Button.Styles> |
|||
</Button> |
|||
<Button Content="简洁表单" |
|||
Padding="18,10" |
|||
Margin="0,0,12,12" |
|||
Command="{Binding ShowSimpleFormCommand}" |
|||
Background="#10B981" |
|||
BorderBrush="Transparent" |
|||
Foreground="White" |
|||
CornerRadius="10"> |
|||
<Button.Styles> |
|||
<Style Selector="Button:pointerover"> |
|||
<Setter Property="Background" Value="#059669"/> |
|||
</Style> |
|||
</Button.Styles> |
|||
</Button> |
|||
<Button Content="联系表单" |
|||
Padding="18,10" |
|||
Margin="0,0,12,12" |
|||
Command="{Binding ShowContactFormCommand}" |
|||
Background="#8B5CF6" |
|||
BorderBrush="Transparent" |
|||
Foreground="White" |
|||
CornerRadius="10"> |
|||
<Button.Styles> |
|||
<Style Selector="Button:pointerover"> |
|||
<Setter Property="Background" Value="#7C3AED"/> |
|||
</Style> |
|||
</Button.Styles> |
|||
</Button> |
|||
<Button Content="反馈表单" |
|||
Padding="18,10" |
|||
Margin="0,0,12,12" |
|||
Command="{Binding ShowFeedbackFormCommand}" |
|||
Background="#F59E0B" |
|||
BorderBrush="Transparent" |
|||
Foreground="White" |
|||
CornerRadius="10"> |
|||
<Button.Styles> |
|||
<Style Selector="Button:pointerover"> |
|||
<Setter Property="Background" Value="#D97706"/> |
|||
</Style> |
|||
</Button.Styles> |
|||
</Button> |
|||
<Button Content="注册表单" |
|||
Padding="18,10" |
|||
Margin="0,0,12,12" |
|||
Command="{Binding ShowRegisterFormCommand}" |
|||
Background="#EF4444" |
|||
BorderBrush="Transparent" |
|||
Foreground="White" |
|||
CornerRadius="10"> |
|||
<Button.Styles> |
|||
<Style Selector="Button:pointerover"> |
|||
<Setter Property="Background" Value="#DC2626"/> |
|||
</Style> |
|||
</Button.Styles> |
|||
</Button> |
|||
</WrapPanel> |
|||
|
|||
<!-- 结果显示区域 --> |
|||
<Border Grid.Row="2" |
|||
Margin="0,24,0,0" |
|||
Padding="16" |
|||
Background="{StaticResource BackgroundLight}" |
|||
BorderBrush="{StaticResource BorderLight}" |
|||
BorderThickness="1" |
|||
CornerRadius="8"> |
|||
<StackPanel Spacing="6"> |
|||
<TextBlock Text="提交结果" |
|||
FontSize="16" |
|||
FontWeight="SemiBold" |
|||
Foreground="{StaticResource TextPrimary}"/> |
|||
<TextBlock Text="{Binding SubmitResult, FallbackValue=尚未提交任何数据}" |
|||
TextWrapping="Wrap" |
|||
Foreground="{StaticResource TextPrimary}" |
|||
FontSize="14"/> |
|||
</StackPanel> |
|||
</Border> |
|||
</Grid> |
|||
</dialogHost:DialogHost> |
|||
</reactive:ReactiveUserControl> |
|||
|
|||
@ -0,0 +1,22 @@ |
|||
using Avalonia.Markup.Xaml; |
|||
using AuroraDesk.Presentation.ViewModels.Pages; |
|||
using ReactiveUI.Avalonia; |
|||
|
|||
namespace AuroraDesk.Presentation.Views.Pages; |
|||
|
|||
/// <summary>
|
|||
/// 表单页面视图
|
|||
/// </summary>
|
|||
public partial class FormPageView : ReactiveUserControl<FormPageViewModel> |
|||
{ |
|||
public FormPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue