添加的登录界面,使用固定账号和密码测试登录逻辑成功
This commit is contained in:
90
WorkStation.Client/ViewModels/Dialogs/LoginViewModel.cs
Normal file
90
WorkStation.Client/ViewModels/Dialogs/LoginViewModel.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using Prism.Commands;
|
||||
using Prism.Mvvm;
|
||||
using Prism.Services.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WorkStation.Client.ViewModels.Dialogs
|
||||
{
|
||||
public class LoginViewModel : BindableBase, IDialogAware
|
||||
{
|
||||
/// <summary>
|
||||
/// 弹窗标题
|
||||
/// </summary>
|
||||
public string Title => "登录界面";
|
||||
|
||||
/// <summary>
|
||||
/// 账户
|
||||
/// </summary>
|
||||
private string _account = string.Empty;
|
||||
public string Account
|
||||
{
|
||||
get => _account;
|
||||
set => SetProperty(ref _account, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
private string _password = string.Empty;
|
||||
public string Password
|
||||
{
|
||||
get => _password;
|
||||
set => SetProperty(ref _password, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于关闭窗口时,判断是否登录成功。
|
||||
/// 如果登录失败就终止当前应用。
|
||||
/// </summary>
|
||||
private bool _isSuccess = false;
|
||||
|
||||
/// <summary>
|
||||
/// 登录名利
|
||||
/// </summary>
|
||||
public DelegateCommand LoginCommand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求关闭委托
|
||||
/// </summary>
|
||||
public event Action<IDialogResult> RequestClose;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the dialog can be closed.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the dialog can be closed; otherwise, <see langword="false"/>.</returns>
|
||||
public bool CanCloseDialog()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnDialogClosed()
|
||||
{
|
||||
if (_isSuccess == false)
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
public LoginViewModel()
|
||||
{
|
||||
LoginCommand = new DelegateCommand(() =>
|
||||
{
|
||||
if (Account == "11" && Password == "22")
|
||||
{
|
||||
_isSuccess = true;
|
||||
RequestClose(new DialogResult(ButtonResult.OK));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user