You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
4 years ago
|
import { Component, OnInit } from '@angular/core';
|
||
|
import { HttpClient } from '@angular/common/http'
|
||
|
import { Data } from '../../interface'
|
||
|
import { Router,ActivatedRoute } from '@angular/router'
|
||
|
import {CacheTokenService} from '../../service/cache-token.service'//引入服务
|
||
|
import { CookieService } from 'ngx-cookie-service';//cookie插件
|
||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||
|
|
||
|
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-login',
|
||
|
templateUrl: './login.component.html',
|
||
|
styleUrls: ['./login.component.scss'],
|
||
|
|
||
|
})
|
||
|
export class LoginComponent implements OnInit {
|
||
|
|
||
|
constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,
|
||
|
public snackBar: MatSnackBar,private cookieService: CookieService) { }
|
||
|
|
||
|
ngOnInit() {}
|
||
|
|
||
|
errmsg :string = ''; //错误信息
|
||
|
|
||
|
//提交登录表单
|
||
|
onSubmit(e){
|
||
|
this.http.post('/api/CompanyAccount/SignIn',{
|
||
|
name: e.name,
|
||
|
password: e.password}).subscribe(
|
||
|
(data: Data) =>
|
||
|
{
|
||
|
sessionStorage.setItem("isDefaultPassword",data.isDefaultPassword);
|
||
|
sessionStorage.setItem("token",data.token);
|
||
|
this.cookieService.set("token",data.token,null,'/');
|
||
|
this.cookieService.set("refreshToken",data.refreshToken,null,'/');
|
||
|
this.router.navigate(['/home'])
|
||
|
|
||
|
//调用服务中的function刷新token
|
||
|
this.token.startUp()
|
||
|
},
|
||
|
(err) =>
|
||
|
{this.errmsg = err}
|
||
|
)
|
||
|
}
|
||
|
|
||
|
//跳转注册页面
|
||
|
toRegister () {
|
||
|
this.router.navigate(['/register'])
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|