@page "/manage/setting/login" @page "/manage/setting" @using Newtonsoft.Json.Linq @using log4net @layout SettingLayout
保存设置
登录模式 loginValue = args)> @* 优先登录 preValue = args)> *@
@inject Microsoft.Extensions.Options.IOptions setting; @inject Microsoft.Extensions.Options.IOptions setting; @inject NotificationService _message @code { private readonly ILog logger = LogManager.GetLogger(typeof(LoginDialog)); int loginValue = 1; // int preValue = 1; protected override void OnInitialized() { loginValue = setting.Value.loginMode; base.OnInitialized(); } //保存 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 = "提示", Detail = $"保存成功", Duration = 4000 } ); logger.Info($"修改用户登录设置"); } }