| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using HandyControl.Controls;
- using LogoForceTestApp.Core;
- using LogoForceTestApp.Core.Mvvm;
- using LogoForceTestApp.Modules.MainModule.Models;
- using LogoForceTestApp.Modules.MainModule.Views;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- namespace LogoForceTestApp.Modules.MainModule.ViewModels
- {
- public class LoginPageViewModel : RegionViewModelBase
- {
- public string Password { get; set; }
- public List<Role> Roles { get; set; }
- public DelegateCommand GoBackCommand { get; set; }
- public DelegateCommand LoginCommand { get; set; }
- public Role UserRole { get; set; }
- public LoginPageViewModel(IRegionManager regionManager,IEventAggregator eventAggregator) : base(regionManager)
- {
- Roles = new List<Role>();
- foreach (Role item in Enum.GetValues(typeof(Role)))
- {
- Roles.Add(item);
- }
- GoBackCommand = new DelegateCommand(GoBack);
- LoginCommand = new DelegateCommand(Login);
- _eventAggregator = eventAggregator;
- }
- private void Login()
- {
- if (string.IsNullOrWhiteSpace(Password))
- {
- Growl.Warning($"{nameof(Password)}不能为空");
- }
- if (Password == "123456")
- {
- CurrentUser.CurrentUserName = UserRole.ToString();
- Growl.Info($"{UserRole}登录成功");
- _eventAggregator.GetEvent<LoginSuccessEvent>().Publish(true);
- if (CurrentUser.CurrentUserName == "Admin")//(CurrentUser.CurrentUserName== "Engineer" || CurrentUser.CurrentUserName=="Admin")
- {
- GoBack();
- }
- else
- {
- RegionManager.RequestNavigate(RegionNames.ContentRegion, nameof(MainPage));
- }
- }
- else
- {
- Growl.Warning($"{UserRole}登录失败:密码错误");
- CurrentUser.CurrentUserName = string.Empty;
- _eventAggregator.GetEvent<LoginSuccessEvent>().Publish(false);
- }
- }
- private IRegionNavigationJournal _regionNavigationJournal;
- private readonly IEventAggregator _eventAggregator;
- private void GoBack()
- {
- _regionNavigationJournal?.GoBack();
- }
- public override void OnNavigatedFrom(NavigationContext navigationContext)
- {
- base.OnNavigatedFrom(navigationContext);
- }
- public override void OnNavigatedTo(NavigationContext navigationContext)
- {
- _regionNavigationJournal = navigationContext.NavigationService.Journal;
- }
- }
- }
|