6040-003分支:优化登录密码保存文件名称
This commit is contained in:
@@ -12,6 +12,7 @@ using Cowain.Base.Models.Menu;
|
||||
using Cowain.Base.ViewModels;
|
||||
using Ke.Bee.Localization.Localizer.Abstractions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Semi.Avalonia;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,6 +20,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -92,12 +94,17 @@ namespace Cowain.TestProject.ViewModels
|
||||
/// 菜单数据
|
||||
/// </summary>
|
||||
private readonly List<MenuItem> _menuItems;
|
||||
private ILogger<LoginWindowViewModel> _logger;
|
||||
private IAccountService _accountService;
|
||||
private IConfiguration _configuration;
|
||||
private string userFileName = "userdata.json";
|
||||
|
||||
public LoginWindowViewModel(MenuConfigurationContext menuContext, ILocalizer localizer, IViewNavigator viewNavigator, IAccountService accountService, IConfiguration configuration)
|
||||
public LoginWindowViewModel(MenuConfigurationContext menuContext, ILocalizer localizer, ILogger<LoginWindowViewModel> logger, IViewNavigator viewNavigator, IAccountService accountService, IConfiguration configuration)
|
||||
{
|
||||
_l = localizer;
|
||||
_logger = logger;
|
||||
string pdtName = GetProductName();
|
||||
userFileName= $"{pdtName}_userdata.json";
|
||||
_menuItems = menuContext.Menus;
|
||||
_viewNavigator = viewNavigator;
|
||||
_accountService = accountService;
|
||||
@@ -201,7 +208,7 @@ namespace Cowain.TestProject.ViewModels
|
||||
}
|
||||
private void ReadUserData()
|
||||
{
|
||||
var path = PathHelper.GetLocalFilePath("userdata.json");
|
||||
var path = PathHelper.GetLocalFilePath(userFileName);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var json = File.ReadAllText(path);
|
||||
@@ -252,12 +259,12 @@ namespace Cowain.TestProject.ViewModels
|
||||
{
|
||||
var userData = new UserData { UserName = UserName, Password = DESHelper.Encrypt(Password, "ZSL12345"), IsRemember = RememberUserName };
|
||||
var json = JsonSerializer.Serialize(userData);
|
||||
var path = PathHelper.GetLocalFilePath("userdata.json");
|
||||
var path = PathHelper.GetLocalFilePath(userFileName);
|
||||
await File.WriteAllTextAsync(path, json);
|
||||
}
|
||||
else
|
||||
{
|
||||
var path = PathHelper.GetLocalFilePath("userdata.json");
|
||||
var path = PathHelper.GetLocalFilePath(userFileName);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
@@ -285,5 +292,29 @@ namespace Cowain.TestProject.ViewModels
|
||||
app.RequestedThemeVariant = theme == ThemeVariant.Dark ? ThemeVariant.Light : ThemeVariant.Dark;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目文件中<Product>属性的值
|
||||
/// </summary>
|
||||
/// <returns>Product属性字符串,如"Cowain WCS"</returns>
|
||||
public string GetProductName()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取当前程序集(如果是其他项目,替换为对应程序集)
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
// 获取AssemblyProduct特性
|
||||
var productAttribute = assembly.GetCustomAttribute<AssemblyProductAttribute>();
|
||||
|
||||
// 返回值(为空时返回默认值)
|
||||
return productAttribute?.Product ?? "未知产品名称";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 异常处理(根据你的日志框架调整)
|
||||
_logger.LogError(ex, "读取Product属性失败");
|
||||
return "未知产品名称";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,6 @@ namespace Cowain.TestProject.ViewModels
|
||||
CultureInfo cultureInfo = menuItem?.CommandParameter is string parameter
|
||||
? new CultureInfo(parameter)
|
||||
: Thread.CurrentThread.CurrentCulture;
|
||||
//待1.24号更新后再使用
|
||||
Semi.Avalonia.SemiTheme.OverrideLocaleResources(app, cultureInfo);
|
||||
Ursa.Themes.Semi.SemiTheme.OverrideLocaleResources(app, cultureInfo);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user