添加的登录界面,使用固定账号和密码测试登录逻辑成功

This commit is contained in:
2025-07-05 14:05:59 +08:00
parent ad6b36018a
commit a3996dad99
24 changed files with 426 additions and 49 deletions

View File

@ -0,0 +1,20 @@
<prism:PrismApplication
x:Class="WorkStation.Client.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WorkStation.Client"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<materialDesign:BundledTheme
BaseTheme="Light"
PrimaryColor="DeepPurple"
SecondaryColor="Lime" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</prism:PrismApplication>

View File

@ -0,0 +1,37 @@
using Prism.Ioc;
using Prism.Services.Dialogs;
using System.Windows;
using WorkStation.Client.ViewModels.Dialogs;
using WorkStation.Client.Views;
using WorkStation.Client.Views.Dialogs;
namespace WorkStation.Client
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void OnInitialized()
{
var dialogService = Container.Resolve<IDialogService>();
dialogService.ShowDialog("LoginView", result =>
{
if (result.Result == ButtonResult.OK)
{
base.OnInitialized();
}
});
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterDialog<LoginView, LoginViewModel>();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

View 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));
}
});
}
}
}

View File

@ -1,6 +1,6 @@
using Prism.Mvvm; using Prism.Mvvm;
namespace WorkStationClient.ViewModels namespace WorkStation.Client.ViewModels
{ {
public class MainWindowViewModel : BindableBase public class MainWindowViewModel : BindableBase
{ {

View File

@ -0,0 +1,47 @@
<UserControl
x:Class="WorkStation.Client.Views.Dialogs.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WorkStation.Client.Views.Dialogs"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.5*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Image
Grid.Column="0"
Margin="10"
Source="/Images/LoginImage.png" />
<StackPanel
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock
HorizontalAlignment="Center"
FontSize="50"
Text="登录" />
<TextBlock
FontSize="20"
Text="账号" />
<TextBox
Width="200"
Margin="5"
Text="{Binding Account}" />
<TextBlock
FontSize="20"
Text="密码" />
<TextBox
Width="200"
Margin="5"
Text="{Binding Password}" />
<Button
Command="{Binding LoginCommand}"
Content="登录" />
</StackPanel>
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WorkStation.Client.Views.Dialogs
{
/// <summary>
/// Interaction logic for LoginView.xaml
/// </summary>
public partial class LoginView : UserControl
{
public LoginView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,13 @@
<Window
x:Class="WorkStation.Client.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
Title="{Binding Title}"
Width="525"
Height="350"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid>
<Button />
</Grid>
</Window>

View File

@ -1,6 +1,6 @@
using System.Windows; using System.Windows;
namespace WorkStationClient.Views namespace WorkStation.Client.Views
{ {
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml

View File

@ -5,6 +5,13 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="Images\LoginImage.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignThemes" Version="5.2.1" />
<PackageReference Include="Prism.DryIoc" Version="8.1.97" /> <PackageReference Include="Prism.DryIoc" Version="8.1.97" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="Images\LoginImage.png" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace WorkStation.Server.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View File

@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54136",
"sslPort": 44341
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5153",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7029;http://localhost:5153",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,13 @@
namespace WorkStation.Server
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
@WorkStation.Server_HostAddress = http://localhost:5153
GET {{WorkStation.Server_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -0,0 +1,7 @@
namespace WorkStation.Share
{
public class Class1
{
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -1,9 +1,13 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.14.36221.1 d17.14 VisualStudioVersion = 17.14.36221.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkStationClient", "WorkStationClient\WorkStationClient.csproj", "{B3D9EF99-5FA3-4533-91FE-2A107E81C4A0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkStation.Share", "WorkStation.Share\WorkStation.Share.csproj", "{427790B0-1AD5-4F27-B528-99767140BFBC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkStation.Client", "WorkStation.Client\WorkStation.Client.csproj", "{52C6BEFE-0576-4885-8E98-4A53C63282ED}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkStation.Server", "WorkStation.Server\WorkStation.Server.csproj", "{9486DBEA-0AFC-4611-8739-421BBD92DBC1}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -11,10 +15,18 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B3D9EF99-5FA3-4533-91FE-2A107E81C4A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {427790B0-1AD5-4F27-B528-99767140BFBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3D9EF99-5FA3-4533-91FE-2A107E81C4A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {427790B0-1AD5-4F27-B528-99767140BFBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3D9EF99-5FA3-4533-91FE-2A107E81C4A0}.Release|Any CPU.ActiveCfg = Release|Any CPU {427790B0-1AD5-4F27-B528-99767140BFBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3D9EF99-5FA3-4533-91FE-2A107E81C4A0}.Release|Any CPU.Build.0 = Release|Any CPU {427790B0-1AD5-4F27-B528-99767140BFBC}.Release|Any CPU.Build.0 = Release|Any CPU
{52C6BEFE-0576-4885-8E98-4A53C63282ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52C6BEFE-0576-4885-8E98-4A53C63282ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52C6BEFE-0576-4885-8E98-4A53C63282ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52C6BEFE-0576-4885-8E98-4A53C63282ED}.Release|Any CPU.Build.0 = Release|Any CPU
{9486DBEA-0AFC-4611-8739-421BBD92DBC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9486DBEA-0AFC-4611-8739-421BBD92DBC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9486DBEA-0AFC-4611-8739-421BBD92DBC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9486DBEA-0AFC-4611-8739-421BBD92DBC1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,9 +0,0 @@
<prism:PrismApplication x:Class="WorkStationClient.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WorkStationClient"
xmlns:prism="http://prismlibrary.com/" >
<Application.Resources>
</Application.Resources>
</prism:PrismApplication>

View File

@ -1,22 +0,0 @@
using System.Windows;
using Prism.Ioc;
using WorkStationClient.Views;
namespace WorkStationClient
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
}
}
}

View File

@ -1,10 +0,0 @@
<Window x:Class="WorkStationClient.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="350" Width="525" >
<Grid>
<ContentControl prism:RegionManager.RegionName="ContentRegion" />
</Grid>
</Window>