|
|
|
@ -22,7 +22,25 @@ export class LoginComponent implements OnInit {
|
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
userName: [null, [Validators.required]], |
|
|
|
|
password: [null, [Validators.required]], |
|
|
|
|
remember: [null], |
|
|
|
|
autologin: [null], |
|
|
|
|
}); |
|
|
|
|
//如果本地储存了账号密码信息,那就回显在输入框
|
|
|
|
|
let account = localStorage.getItem('account') |
|
|
|
|
let password = localStorage.getItem('password') |
|
|
|
|
if (account && password) { |
|
|
|
|
this.validateForm.patchValue({ |
|
|
|
|
userName: localStorage.getItem('account'), |
|
|
|
|
password: localStorage.getItem('password') |
|
|
|
|
}); |
|
|
|
|
this.remember = true //这一步是回显后让勾选框为选中状态
|
|
|
|
|
} |
|
|
|
|
//自动登陆
|
|
|
|
|
if (localStorage.getItem('isautologin') == 'true') { |
|
|
|
|
this.submitForm() |
|
|
|
|
this.autologin = true //这一步是回显后让勾选框为选中状态
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
errmsg: string = ''; //错误信息
|
|
|
|
@ -34,10 +52,39 @@ export class LoginComponent implements OnInit {
|
|
|
|
|
this.router.navigate(['/register']) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
remember:any//记住密码
|
|
|
|
|
autologin:any//自动登录
|
|
|
|
|
|
|
|
|
|
//记住密码
|
|
|
|
|
rememberInfo() { |
|
|
|
|
// 判断用户是否勾选记住密码,如果勾选,在本地储存中储存登录信息
|
|
|
|
|
if (this.remember) { |
|
|
|
|
localStorage.setItem("account", this.validateForm.value.userName) |
|
|
|
|
localStorage.setItem("password", this.validateForm.value.password) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//自动登陆
|
|
|
|
|
autoLogin() { |
|
|
|
|
if (this.autologin) { |
|
|
|
|
localStorage.setItem("isautologin", 'true') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remember: any//记住密码
|
|
|
|
|
autologin: any//自动登录
|
|
|
|
|
isLoading = false; |
|
|
|
|
submitForm(): void { |
|
|
|
|
|
|
|
|
|
if (!this.remember) { |
|
|
|
|
localStorage.removeItem("account") |
|
|
|
|
localStorage.removeItem("password") |
|
|
|
|
} |
|
|
|
|
if(!this.autologin){ |
|
|
|
|
localStorage.removeItem("isautologin") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const i in this.validateForm.controls) { |
|
|
|
|
this.validateForm.controls[i].markAsDirty(); |
|
|
|
|
this.validateForm.controls[i].updateValueAndValidity(); |
|
|
|
@ -59,6 +106,10 @@ export class LoginComponent implements OnInit {
|
|
|
|
|
sessionStorage.setItem('userdata', JSON.stringify(data.result.user)) |
|
|
|
|
sessionStorage.setItem('userdataOfgasstation', JSON.stringify(data.result.user)) |
|
|
|
|
this.isLoading = false; |
|
|
|
|
//记住密码
|
|
|
|
|
this.rememberInfo() |
|
|
|
|
//自动登陆
|
|
|
|
|
this.autoLogin() |
|
|
|
|
if (data.result.user.userName == 'admin') { |
|
|
|
|
this.router.navigate(['/system/organization']) |
|
|
|
|
} else { |
|
|
|
|