|
1 | 1 | using ComputerLock.Interfaces; |
| 2 | +using Microsoft.AspNetCore.Components.Web; |
| 3 | +using MudExtensions; |
2 | 4 |
|
3 | 5 | namespace ComputerLock.Components.Settings; |
4 | 6 |
|
@@ -28,6 +30,44 @@ public partial class LockSettings |
28 | 30 |
|
29 | 31 | [Inject] |
30 | 32 | private PowerManager PowerManager { get; set; } = null!; |
| 33 | + |
| 34 | + private MudTextFieldExtended<string>? _textTipsMessageRef; |
| 35 | + private bool _lockTipsMessageEdit; |
| 36 | + public string LockTipsMessage |
| 37 | + { |
| 38 | + get => AppSettings.LockTipsMessage.IsEmpty() |
| 39 | + ? Lang["LockTipsValue"] // 显示默认文案 |
| 40 | + : AppSettings.LockTipsMessage; |
| 41 | + set => AppSettings.LockTipsMessage = value; |
| 42 | + } |
| 43 | + private async Task EnableTipsMessageEditing() |
| 44 | + { |
| 45 | + _lockTipsMessageEdit = true; |
| 46 | + // 等待渲染后再聚焦,否则焦点可能丢失 |
| 47 | + await Task.Delay(1); |
| 48 | + _textTipsMessageRef?.FocusAsync(); |
| 49 | + } |
| 50 | + |
| 51 | + private void TipsMessageBlur(FocusEventArgs args) |
| 52 | + { |
| 53 | + TipsMessageFinishEditing(); |
| 54 | + } |
| 55 | + private void TipsMessageKeyDown(KeyboardEventArgs args) |
| 56 | + { |
| 57 | + if (args.Key == "Enter") |
| 58 | + { |
| 59 | + TipsMessageFinishEditing(); |
| 60 | + } |
| 61 | + } |
| 62 | + private void TipsMessageFinishEditing() |
| 63 | + { |
| 64 | + if (!_lockTipsMessageEdit) |
| 65 | + { |
| 66 | + return; |
| 67 | + } |
| 68 | + _lockTipsMessageEdit = false; |
| 69 | + } |
| 70 | + |
31 | 71 | private void SaveSettings() |
32 | 72 | { |
33 | 73 | AppSettingsProvider.SaveSettings(AppSettings); |
|
0 commit comments