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 '../../http-interceptors/cache-token.service'//引入服务 import { MatSnackBar } from '@angular/material/snack-bar'; import { ConstantPositionProperty } from 'cesium'; @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) { } ngOnInit() { } errmsg :string = '' onSubmit(e){ this.http.post('/api/Account/SignIn',{ name: e.name, password: e.password}).subscribe( (data: Data) => { sessionStorage.setItem("level",data.level); sessionStorage.setItem("token",data.token); sessionStorage.setItem("refreshToken",data.refreshToken); this.router.navigate([`/ui/home`]) //调用服务中的function刷新token this.token.startUp() }, (err) => {this.errmsg = err}) } //打开弹窗 open () { this.snackBar.open('请联系管理员', '确定', { duration: 3000 }); } }