@page "/manage/setting/login" @page "/manage/setting" @using Newtonsoft.Json.Linq @using log4net @layout SettingLayout
@myText.SaveSet
@myText.LoginMode loginValue = args)> @* 优先登录 preValue = args)> *@
@inject Microsoft.Extensions.Options.IOptions setting; @inject Microsoft.Extensions.Options.IOptions setting; @inject NotificationService _message @inject Toolbelt.Blazor.I18nText.I18nText I18nText; @code { private I18nText.local myText = new I18nText.local(); private readonly ILog logger = LogManager.GetLogger(typeof(LoginDialog)); int loginValue = 1; // int preValue = 1; protected override async Task OnInitializedAsync() { loginValue = setting.Value.loginMode; myText = await I18nText.GetTextTableAsync(this); base.OnInitializedAsync(); } //保存 async Task SaveMethod() { // 获取当前工作目录 string currentDirectory = Directory.GetCurrentDirectory(); // setting.Value.fridgeState = fridgeStateValue; // setting.Value.alertState = alertStateValue; // setting.Value.temperatureRange = temperatureRange; string filePath = Path.Combine(currentDirectory, "appsettings.json"); string jsonString = File.ReadAllText(filePath); var jsonNode = JObject.Parse(jsonString); jsonNode["setting"]["loginMode"] = loginValue; var options = new JsonSerializerOptions { WriteIndented = true }; File.WriteAllText(filePath, jsonNode.ToString(Newtonsoft.Json.Formatting.Indented)); _message.Notify( new NotificationMessage { Severity = NotificationSeverity.Success, Summary = myText.Tips, Detail = myText.LoginMode, Duration = 4000 } ); logger.Info($"修改用户登录设置"); } }