|
49 | 49 | { |
50 | 50 | <h3>登录</h3> |
51 | 51 | <p class="subtitle">使用你的 BootstrapBlazor 帐户。</p> |
52 | | - <BootstrapInput type="email" class="input" placeholder="电子邮件或电话号码" @bind-Value="email"></BootstrapInput> |
53 | | - <div class="error" hidden="@(!showEmailError)">请输入有效的电子邮件地址或电话号码</div> |
54 | | - <Button class="button" Color="Color.Primary" OnClick="OnEmailSubmit">下一步</Button> |
| 52 | + <ValidateForm Model="_loginModel" OnValidSubmit="OnEmailSubmit"> |
| 53 | + <BootstrapInput type="email" class="input" SkipValidate="true" IsAutoFocus="true" |
| 54 | + placeholder="电子邮件或电话号码" @bind-Value="@_loginModel.Email"></BootstrapInput> |
| 55 | + <div class="error" hidden="@(!showEmailError)">请输入有效的电子邮件地址或电话号码</div> |
| 56 | + <Button class="button" Color="Color.Primary" ButtonType="ButtonType.Submit" Text="下一步"></Button> |
| 57 | + </ValidateForm> |
55 | 58 | <div class="links"> |
56 | 59 | <a href="#" @onclick:preventDefault>忘记用户名?</a> |
57 | 60 | </div> |
|
62 | 65 | else if (!isAuth) |
63 | 66 | { |
64 | 67 | <h3>输入你的密码</h3> |
65 | | - <p class="email-display">@email</p> |
66 | | - <BootstrapInput type="password" class="input" placeholder="密码" @bind-Value="password"></BootstrapInput> |
67 | | - <div class="links"> |
68 | | - <a href="#" @onclick:preventDefault>忘记了密码?</a> |
69 | | - </div> |
70 | | - <Button class="button" Color="Color.Primary" OnClick="OnPasswordSubmit">下一步</Button> |
| 68 | + <p class="email-display">@_loginModel.Email</p> |
| 69 | + <ValidateForm Model="_loginModel" OnValidSubmit="OnPasswordSubmit"> |
| 70 | + <BootstrapInput type="password" class="input" SkipValidate="true" IsAutoFocus="true" |
| 71 | + placeholder="密码" @bind-Value="@_loginModel.Password"></BootstrapInput> |
| 72 | + <div class="links"> |
| 73 | + <a href="#" @onclick:preventDefault>忘记了密码?</a> |
| 74 | + </div> |
| 75 | + <Button class="button" Color="Color.Primary" ButtonType="ButtonType.Submit" Text="下一步"></Button> |
| 76 | + </ValidateForm> |
71 | 77 | <div class="links"> |
72 | 78 | <a href="#" @onclick:preventDefault>其他登录方法</a> |
73 | 79 | </div> |
74 | 80 | } |
75 | 81 | else |
76 | 82 | { |
77 | | - <div class="email-display2"><span>@email</span></div> |
| 83 | + <div class="email-display2"><span>@_loginModel.Email</span></div> |
78 | 84 | <h5 class="text-center mt-3 mb-0">欢迎,您已成功登录</h5> |
79 | 85 | <div class="login-video-wrap"> |
80 | 86 | <video class="login-video" autoplay="autoplay" playsinline="playsinline" disablepictureinpicture=""> |
|
86 | 92 | </video> |
87 | 93 | </div> |
88 | 94 | <p class="text-center text-muted" style="font-size: 0.75rem;">此登录高仿微软登录 UI</p> |
89 | | - <Button class="button" Color="Color.Primary" OnClick="OnEnterSubmit">进入</Button> |
| 95 | + <Button class="button" Color="Color.Primary">进入</Button> |
90 | 96 | } |
91 | 97 | </div> |
92 | 98 | </div> |
|
95 | 101 | @code { |
96 | 102 | private bool isEmailEntered = false; |
97 | 103 | private bool isAuth = false; |
98 | | - private string email = "[email protected]"; |
99 | | - private string password = "123456"; |
100 | 104 | private bool showEmailError = false; |
| 105 | + private LoginModel _loginModel = new LoginModel() |
| 106 | + { |
| 107 | + |
| 108 | + Password = "123456" |
| 109 | + }; |
101 | 110 |
|
102 | | - private void OnEmailSubmit() |
| 111 | + private Task OnEmailSubmit(EditContext context) |
103 | 112 | { |
104 | | - if (string.IsNullOrWhiteSpace(email)) |
| 113 | + if (string.IsNullOrWhiteSpace(_loginModel.Email)) |
105 | 114 | { |
106 | 115 | showEmailError = true; |
107 | 116 | } |
|
110 | 119 | showEmailError = false; |
111 | 120 | isEmailEntered = true; |
112 | 121 | } |
| 122 | + StateHasChanged(); |
| 123 | + return Task.CompletedTask; |
113 | 124 | } |
114 | 125 |
|
115 | | - private void OnPasswordSubmit() |
| 126 | + private Task OnPasswordSubmit(EditContext context) |
116 | 127 | { |
117 | 128 | // 数据库检查密码逻辑可以在这里实现 |
118 | 129 | // 演示代码一律通过 |
119 | 130 | isAuth = true; |
| 131 | + StateHasChanged(); |
| 132 | + return Task.CompletedTask; |
120 | 133 | } |
121 | 134 |
|
122 | | - private void OnEnterSubmit() |
| 135 | + private void GoBack() |
123 | 136 | { |
124 | | - |
| 137 | + isEmailEntered = false; |
125 | 138 | } |
126 | 139 |
|
127 | | - private void GoBack() |
| 140 | + class LoginModel |
128 | 141 | { |
129 | | - isEmailEntered = false; |
| 142 | + public string? Email { get; set; } |
| 143 | + |
| 144 | + public string? Password { get; set; } |
130 | 145 | } |
131 | 146 | } |
0 commit comments