LoginViewModel.cs 778 字节
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace IndustrialControl.ViewModels;

public partial class LoginViewModel : ObservableObject
{
    [ObservableProperty] private string userName = string.Empty;
    [ObservableProperty] private string password = string.Empty;
    [ObservableProperty] private bool isBusy;

    [RelayCommand]
    public async Task LoginAsync()
    {
        if (IsBusy) return; IsBusy = true;
        try
        {
            await Task.Delay(200); // mock
            await Shell.Current.GoToAsync("//Home");
        }
        catch (Exception ex)
        {
            await Application.Current.MainPage.DisplayAlert("登录失败", ex.Message, "确定");
        }
        finally { IsBusy = false; }
    }
}