Skip to content

Commit 9786fd4

Browse files
committed
优化设置解锁密码的流程
1 parent 13486b1 commit 9786fd4

File tree

11 files changed

+198
-215
lines changed

11 files changed

+198
-215
lines changed

src/ComputerLock/Components/ResetPassword.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
</DialogContent>
2121
<DialogActions>
2222
<MudButton Color="Color.Primary"
23+
FullWidth="true"
24+
Variant="Variant.Filled"
2325
OnClick="Submit">
2426
@(Lang["Save"])
2527
</MudButton>

src/ComputerLock/Components/SetPassword.razor

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
<MudPasswordField @bind-Value="@_password"
2-
Class="mt-6"
3-
Variant="Variant.Text"
4-
Label="@(Lang["SetPasswordInput"])"
5-
IconSize="Size.Small" />
1+
<MudDialog>
2+
<DialogContent>
3+
<MudPaper Width="350px" Elevation="0">
4+
<MudPasswordField @bind-Value="@_password"
5+
Variant="Variant.Text"
6+
Label="@(Lang["SetPasswordInput"])"
7+
IconSize="Size.Small" />
8+
</MudPaper>
9+
</DialogContent>
10+
<DialogActions>
11+
<MudButton Color="Color.Primary"
12+
FullWidth="true"
13+
Variant="Variant.Filled"
14+
OnClick="Submit">
15+
@(Lang["SetPasswordFinished"])
16+
</MudButton>
17+
</DialogActions>
18+
</MudDialog>
619

7-
<MudButton Class="mt-4"
8-
FullWidth="true"
9-
Variant="Variant.Filled"
10-
Color="Color.Primary"
11-
OnClick="SavePasswordAsync">@(Lang["SetPasswordFinished"])</MudButton>
12-
13-
<MudAlert Class="mt-6"
14-
Severity="Severity.Normal"
15-
Style="opacity:0.5"
16-
Icon="@Icons.Material.Filled.Face5"
17-
Dense="true">@(Lang["DefaultPasswordTip"])</MudAlert>
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
namespace ComputerLock.Components;
1+
using DialogResult = MudBlazor.DialogResult;
2+
3+
namespace ComputerLock.Components;
24
public partial class SetPassword
35
{
6+
[CascadingParameter]
7+
private IMudDialogInstance MudDialog { get; set; } = default!;
8+
49
[Inject]
510
private IStringLocalizer<Lang> Lang { get; set; } = default!;
611

@@ -9,15 +14,12 @@ public partial class SetPassword
914

1015
private string _password = "";
1116

12-
[Parameter]
13-
public EventCallback<string> PasswordSetFinished { get; set; }
14-
1517
protected override async Task OnInitializedAsync()
1618
{
1719
await base.OnInitializedAsync();
1820
}
1921

20-
private async Task SavePasswordAsync()
22+
private void Submit()
2123
{
2224
if (_password.IsEmpty())
2325
{
@@ -26,6 +28,7 @@ private async Task SavePasswordAsync()
2628
}
2729

2830
var password = JiuLing.CommonLibs.Security.MD5Utils.GetStringValueToLower(_password);
29-
await PasswordSetFinished.InvokeAsync(password);
31+
MudDialog.Close(DialogResult.Ok(password));
32+
Snackbar.Add(Lang["SaveOk"], Severity.Success);
3033
}
3134
}

src/ComputerLock/Configuration/AppSettings.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ public void Initialize(HotkeyTools hotkeyTools)
6161
public LangEnum Lang { get; set; } = LangEnum.zh;
6262

6363
/// <summary>
64-
/// 默认密码 1
64+
/// 解锁密码
6565
/// </summary>
66-
public string Password { get; set; } = "c4ca4238a0b923820dcc509a6f75849b";
67-
68-
/// <summary>
69-
/// 初始密码已修改
70-
/// </summary>
71-
public bool IsPasswordChanged { get; set; } = false;
66+
public string Password { get; set; } = "";
7267

7368
/// <summary>
7469
/// 锁屏快捷键

src/ComputerLock/Pages/Index.razor

Lines changed: 125 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,142 @@
11
@page "/"
22
@using ComputerLock.Enums
3-
@using JiuLing.CommonLibs.ExtensionMethods
43

54
<style>
65
.dialog-blurry {
76
backdrop-filter: blur(10px);
87
}
98
</style>
109

11-
@if (!AppSettings.IsPasswordChanged)
12-
{
13-
<SetPassword PasswordSetFinished="OnPasswordSetFinishedAsync"></SetPassword>
14-
}
15-
else
16-
{
17-
<MudSwitch @bind-Value="@(AppSettings.LockOnStartup)"
18-
@bind-Value:after="SaveSettings"
19-
Label="@(Lang["LockOnStartup"])"
20-
Color="Color.Primary" />
21-
22-
<MudTooltip Text="@(Lang["DisableWindowsRemark"])" Placement="Placement.Bottom">
23-
<MudSwitch @bind-Value="@(AppSettings.IsDisableWindowsLock)"
24-
@bind-Value:after="SaveSettings"
25-
Label="@(Lang["DisableWindowsLock"])"
26-
Color="Color.Primary" />
27-
</MudTooltip>
10+
<MudSwitch @bind-Value="@(AppSettings.LockOnStartup)"
11+
@bind-Value:after="SaveSettings"
12+
Label="@(Lang["LockOnStartup"])"
13+
Color="Color.Primary" />
2814

29-
<MudSwitch @bind-Value="@(AppSettings.IsHideMouseCursor)"
15+
<MudTooltip Text="@(Lang["DisableWindowsRemark"])" Placement="Placement.Bottom">
16+
<MudSwitch @bind-Value="@(AppSettings.IsDisableWindowsLock)"
3017
@bind-Value:after="SaveSettings"
31-
Label="@(Lang["HideMouseCursor"])"
18+
Label="@(Lang["DisableWindowsLock"])"
3219
Color="Color.Primary" />
33-
34-
<MudSwitch @bind-Value="@(AppSettings.LockAnimation)"
35-
@bind-Value:after="SaveSettings"
36-
Label="@(Lang["LockAnimation"])"
37-
Color="Color.Primary" />
38-
39-
<MudNumericField T="int"
40-
Label="@(Lang["AutoLock"])"
41-
Value="@(AppSettings.AutoLockMinute)"
42-
Margin="Margin.Dense"
43-
Min="0"
44-
Variant="Variant.Outlined"
45-
ValueChanged="AutoLockChanged">
46-
</MudNumericField>
47-
48-
<HotkeyInput Title="@(Lang["LockHotkey"])"
49-
Hotkey="@(AppSettings.LockHotkeyString)"
50-
OnHotkeySet="SetLockHotkey"
51-
OnHotkeyClear="ClearLockHotkey" />
52-
53-
<MudToggleGroup @bind-Value="@(AppSettings.ScreenUnlockMethod)"
54-
@bind-Value:after="SaveSettings"
55-
T="ScreenUnlockMethods"
56-
SelectionMode="SelectionMode.SingleSelection"
57-
Class="mt-2"
58-
Color="Color.Primary"
59-
Size="Size.Small"
60-
CheckMark
61-
FixedContent>
62-
<MudToggleItem Value="@(ScreenUnlockMethods.Password)" Text="@(Lang["PasswordUnlock"])" />
63-
<MudToggleItem Value="@(ScreenUnlockMethods.Hotkey)" Text="@(Lang["HotkeyUnlock"])" />
64-
</MudToggleGroup>
65-
66-
<MudPaper Elevation="0" Height="210px">
67-
68-
@if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Password)
69-
{
70-
<div class="d-flex align-center">
71-
<MudSwitch @bind-Value="@(AppSettings.EnablePasswordBox)"
72-
@bind-Value:after="SaveSettings"
73-
Label="@(Lang["EnablePasswordBox"])"
74-
Color="Color.Primary" />
75-
@if (!AppSettings.EnablePasswordBox)
76-
{
77-
<MudChip T="string"
78-
Label="true"
79-
Icon="@Icons.Material.Filled.WarningAmber"
80-
IconColor="Color.Primary"
81-
DisableRipple="true"
82-
Size="Size.Small">
83-
@(Lang["EnablePasswordBoxTips"])
84-
</MudChip>
85-
}
86-
</div>
87-
88-
<MudSwitch @bind-Value="@(AppSettings.IsHidePasswordWindow)"
20+
</MudTooltip>
21+
22+
<MudSwitch @bind-Value="@(AppSettings.IsHideMouseCursor)"
23+
@bind-Value:after="SaveSettings"
24+
Label="@(Lang["HideMouseCursor"])"
25+
Color="Color.Primary" />
26+
27+
<MudSwitch @bind-Value="@(AppSettings.LockAnimation)"
28+
@bind-Value:after="SaveSettings"
29+
Label="@(Lang["LockAnimation"])"
30+
Color="Color.Primary" />
31+
32+
<MudNumericField T="int"
33+
Label="@(Lang["AutoLock"])"
34+
Value="@(AppSettings.AutoLockMinute)"
35+
Margin="Margin.Dense"
36+
Min="0"
37+
Variant="Variant.Outlined"
38+
ValueChanged="AutoLockChanged">
39+
</MudNumericField>
40+
41+
<HotkeyInput Title="@(Lang["LockHotkey"])"
42+
Hotkey="@(AppSettings.LockHotkeyString)"
43+
OnHotkeySet="SetLockHotkey"
44+
OnHotkeyClear="ClearLockHotkey" />
45+
46+
<MudToggleGroup @bind-Value="@(AppSettings.ScreenUnlockMethod)"
47+
@bind-Value:after="SaveSettings"
48+
T="ScreenUnlockMethods"
49+
SelectionMode="SelectionMode.SingleSelection"
50+
Class="mt-2"
51+
Color="Color.Primary"
52+
Size="Size.Small"
53+
CheckMark
54+
FixedContent>
55+
<MudToggleItem Value="@(ScreenUnlockMethods.Password)" Text="@(Lang["PasswordUnlock"])" />
56+
<MudToggleItem Value="@(ScreenUnlockMethods.Hotkey)" Text="@(Lang["HotkeyUnlock"])" />
57+
</MudToggleGroup>
58+
59+
<MudPaper Elevation="0" Height="210px">
60+
61+
@if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Password)
62+
{
63+
<MudButton Color="Color.Primary"
64+
IconSize="Size.Small"
65+
OnClick="ResetPassword">
66+
@(Lang["ResetPassword"])
67+
</MudButton>
68+
69+
<div class="d-flex align-center">
70+
<MudSwitch @bind-Value="@(AppSettings.EnablePasswordBox)"
8971
@bind-Value:after="SaveSettings"
90-
Class="ml-6"
91-
Disabled="@(!AppSettings.EnablePasswordBox)"
92-
Label="@(Lang["HidePasswordWindow"])"
72+
Label="@(Lang["EnablePasswordBox"])"
9373
Color="Color.Primary" />
74+
@if (!AppSettings.EnablePasswordBox)
75+
{
76+
<MudChip T="string"
77+
Label="true"
78+
Icon="@Icons.Material.Filled.WarningAmber"
79+
IconColor="Color.Primary"
80+
DisableRipple="true"
81+
Size="Size.Small">
82+
@(Lang["EnablePasswordBoxTips"])
83+
</MudChip>
84+
}
85+
</div>
86+
87+
<MudSwitch @bind-Value="@(AppSettings.IsHidePasswordWindow)"
88+
@bind-Value:after="SaveSettings"
89+
Class="ml-6"
90+
Disabled="@(!AppSettings.EnablePasswordBox)"
91+
Label="@(Lang["HidePasswordWindow"])"
92+
Color="Color.Primary" />
9493

95-
<MudSwitch @bind-Value="@(_keyboardDownChecked)"
96-
@bind-Value:after="KeyboardDownChecked"
97-
Class="ml-6"
98-
Disabled="@(!AppSettings.EnablePasswordBox)"
99-
Label="@(Lang["KeyboardDownActivePwd"])"
100-
Color="Color.Primary" />
94+
<MudSwitch @bind-Value="@(_keyboardDownChecked)"
95+
@bind-Value:after="KeyboardDownChecked"
96+
Class="ml-6"
97+
Disabled="@(!AppSettings.EnablePasswordBox)"
98+
Label="@(Lang["KeyboardDownActivePwd"])"
99+
Color="Color.Primary" />
101100

102-
<MudSwitch @bind-Value="@(_mouseDownChecked)"
103-
@bind-Value:after="MouseDownChecked"
104-
Class="ml-6"
105-
Disabled="@(!AppSettings.EnablePasswordBox)"
106-
Label="@(Lang["MouseDownActivePwd"])"
107-
Color="Color.Primary" />
101+
<MudSwitch @bind-Value="@(_mouseDownChecked)"
102+
@bind-Value:after="MouseDownChecked"
103+
Class="ml-6"
104+
Disabled="@(!AppSettings.EnablePasswordBox)"
105+
Label="@(Lang["MouseDownActivePwd"])"
106+
Color="Color.Primary" />
108107

109-
<MudSelect T="ScreenLocationEnum"
110-
Label="@(Lang["PwdLocation"])"
111-
Variant="Variant.Outlined"
112-
Value="@(AppSettings.PasswordInputLocation)"
113-
Disabled="@(!AppSettings.EnablePasswordBox)"
114-
Class="ml-6"
115-
ValueChanged="PwdBoxLocationChanged"
116-
Margin="Margin.Dense"
117-
Dense="true">
118-
<MudSelectItem Value="@(ScreenLocationEnum.Center)">@(Lang["Center"])</MudSelectItem>
119-
<MudSelectItem Value="@(ScreenLocationEnum.TopLeft)">@(Lang["TopLeft"])</MudSelectItem>
120-
<MudSelectItem Value="@(ScreenLocationEnum.TopRight)">@(Lang["TopRight"])</MudSelectItem>
121-
<MudSelectItem Value="@(ScreenLocationEnum.BottomLeft)">@(Lang["BottomLeft"])</MudSelectItem>
122-
<MudSelectItem Value="@(ScreenLocationEnum.BottomRight)">@(Lang["BottomRight"])</MudSelectItem>
123-
</MudSelect>
124-
125-
<MudButton Color="Color.Primary"
126-
StartIcon="@Icons.Material.Filled.VpnKey"
127-
IconSize="Size.Small"
128-
OnClick="ResetPassword">
129-
@(Lang["ResetPassword"])
130-
</MudButton>
131-
}
132-
else if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Hotkey)
133-
{
134-
<MudPaper Class="mt-1 d-flex align-center" Elevation="0">
135-
<HotkeyInput Title="@(Lang["UnlockHotkey"])"
136-
Hotkey="@(AppSettings.UnlockHotkeyString)"
137-
Disabled="@AppSettings.IsUnlockUseLockHotkey"
138-
OnHotkeySet="SetUnlockHotkey"
139-
OnHotkeyClear="ClearUnlockHotkey" />
140-
141-
<MudCheckBox @bind-Value="@(AppSettings.IsUnlockUseLockHotkey)"
142-
@bind-Value:after="SaveSettings"
143-
class="ml-3"
144-
Label="@(Lang["UseLockHotkey"])"
145-
Size="Size.Small"
146-
Dense="true"
147-
Color="Color.Primary"></MudCheckBox>
148-
</MudPaper>
149-
}
150-
</MudPaper>
151-
}
108+
<MudSelect T="ScreenLocationEnum"
109+
Label="@(Lang["PwdLocation"])"
110+
Variant="Variant.Outlined"
111+
Value="@(AppSettings.PasswordInputLocation)"
112+
Disabled="@(!AppSettings.EnablePasswordBox)"
113+
Class="ml-6"
114+
ValueChanged="PwdBoxLocationChanged"
115+
Margin="Margin.Dense"
116+
Dense="true">
117+
<MudSelectItem Value="@(ScreenLocationEnum.Center)">@(Lang["Center"])</MudSelectItem>
118+
<MudSelectItem Value="@(ScreenLocationEnum.TopLeft)">@(Lang["TopLeft"])</MudSelectItem>
119+
<MudSelectItem Value="@(ScreenLocationEnum.TopRight)">@(Lang["TopRight"])</MudSelectItem>
120+
<MudSelectItem Value="@(ScreenLocationEnum.BottomLeft)">@(Lang["BottomLeft"])</MudSelectItem>
121+
<MudSelectItem Value="@(ScreenLocationEnum.BottomRight)">@(Lang["BottomRight"])</MudSelectItem>
122+
</MudSelect>
123+
}
124+
else if (AppSettings.ScreenUnlockMethod == ScreenUnlockMethods.Hotkey)
125+
{
126+
<MudPaper Class="mt-1 d-flex align-center" Elevation="0">
127+
<HotkeyInput Title="@(Lang["UnlockHotkey"])"
128+
Hotkey="@(AppSettings.UnlockHotkeyString)"
129+
Disabled="@AppSettings.IsUnlockUseLockHotkey"
130+
OnHotkeySet="SetUnlockHotkey"
131+
OnHotkeyClear="ClearUnlockHotkey" />
132+
133+
<MudCheckBox @bind-Value="@(AppSettings.IsUnlockUseLockHotkey)"
134+
@bind-Value:after="SaveSettings"
135+
class="ml-3"
136+
Label="@(Lang["UseLockHotkey"])"
137+
Size="Size.Small"
138+
Dense="true"
139+
Color="Color.Primary"></MudCheckBox>
140+
</MudPaper>
141+
}
142+
</MudPaper>

0 commit comments

Comments
 (0)