75 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
		
		
			
		
	
	
			75 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| 
								 | 
							
								@page "/manage/setting/login"
							 | 
						||
| 
								 | 
							
								@page "/manage/setting"
							 | 
						||
| 
								 | 
							
								@using Newtonsoft.Json.Linq
							 | 
						||
| 
								 | 
							
								@using log4net
							 | 
						||
| 
								 | 
							
								@layout SettingLayout
							 | 
						||
| 
								 | 
							
								<div class="main">
							 | 
						||
| 
								 | 
							
								    <div class="top-row px-4">
							 | 
						||
| 
								 | 
							
								        <RadzenButton Icon="account_circle" Style="margin-left: auto;" Click="@SaveMethod">
							 | 
						||
| 
								 | 
							
								            <ChildContent>
							 | 
						||
| 
								 | 
							
								                保存设置
							 | 
						||
| 
								 | 
							
								            </ChildContent>
							 | 
						||
| 
								 | 
							
								        </RadzenButton>
							 | 
						||
| 
								 | 
							
								    </div>
							 | 
						||
| 
								 | 
							
								    <div class="content px-4">
							 | 
						||
| 
								 | 
							
								        <RadzenCard class="rz-my-6">
							 | 
						||
| 
								 | 
							
								            <RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Start" Wrap="FlexWrap.Wrap">
							 | 
						||
| 
								 | 
							
								                <RadzenStack Orientation="Orientation.Vertical" Gap="4px">
							 | 
						||
| 
								 | 
							
								                    登录模式
							 | 
						||
| 
								 | 
							
								                    <RadzenRadioButtonList Value=@loginValue TValue="int" Change=@(args => loginValue = args)>
							 | 
						||
| 
								 | 
							
								                        <Items>
							 | 
						||
| 
								 | 
							
								                            <RadzenRadioButtonListItem Text="单人登录" Value="1" />
							 | 
						||
| 
								 | 
							
								                            <RadzenRadioButtonListItem Text="双人登录" Value="2" />
							 | 
						||
| 
								 | 
							
								                        </Items>
							 | 
						||
| 
								 | 
							
								                    </RadzenRadioButtonList>
							 | 
						||
| 
								 | 
							
								                </RadzenStack>
							 | 
						||
| 
								 | 
							
								                @*  <RadzenStack Orientation="Orientation.Vertical" Gap="4px">
							 | 
						||
| 
								 | 
							
								                    优先登录
							 | 
						||
| 
								 | 
							
								                    <RadzenRadioButtonList Value=@preValue TValue="int" Change=@(args => preValue = args)>
							 | 
						||
| 
								 | 
							
								                        <Items>
							 | 
						||
| 
								 | 
							
								                            <RadzenRadioButtonListItem Text="操作人" Value="1" />
							 | 
						||
| 
								 | 
							
								                            <RadzenRadioButtonListItem Text="审核人" Value="2" />
							 | 
						||
| 
								 | 
							
								                        </Items>
							 | 
						||
| 
								 | 
							
								                    </RadzenRadioButtonList>
							 | 
						||
| 
								 | 
							
								                </RadzenStack> *@
							 | 
						||
| 
								 | 
							
								            </RadzenStack>
							 | 
						||
| 
								 | 
							
								        </RadzenCard>
							 | 
						||
| 
								 | 
							
								    </div>
							 | 
						||
| 
								 | 
							
								</div>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@inject Microsoft.Extensions.Options.IOptions<Pojo.Config.setting> setting;
							 | 
						||
| 
								 | 
							
								@inject Microsoft.Extensions.Options.IOptions<Pojo.Config.SettingConfig> 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($"修改用户登录设置");
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |