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.
35 lines
981 B
35 lines
981 B
import {Injectable} from '@angular/core';
|
|
import {Observable} from 'rxjs';
|
|
import {NavigationEnd, Router} from '@angular/router';
|
|
import {filter} from 'rxjs/operators';
|
|
import {environment} from '../environments/environment';
|
|
import {CookieService} from 'ngx-cookie-service';
|
|
import {RouteInterface} from './RouteInterface';
|
|
|
|
/**
|
|
* 导航开始时触发的事件
|
|
*/
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class AbstractRoute {
|
|
|
|
navStart: Observable<NavigationEnd>;
|
|
|
|
constructor(
|
|
private router: Router,
|
|
private cookieService: CookieService
|
|
) {
|
|
this.navStart = router.events.pipe(
|
|
filter(evt => evt instanceof NavigationEnd)
|
|
) as Observable<NavigationEnd>;
|
|
}
|
|
|
|
isLogin(): boolean {
|
|
return this.cookieService.check(environment.tokenKey);
|
|
}
|
|
|
|
checkUser(routeInterface: RouteInterface): void {
|
|
this.navStart.subscribe(evt => routeInterface.doNavigationStart(evt, this.isLogin(), this.cookieService.get(environment.managerKey)));
|
|
}
|
|
}
|
|
|