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.
 
 
 
 
pocketcommunityweb/src/app/AbstractRoute.ts

39 lines
1.1 KiB

import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {NavigationStart, 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 {
// 登陆状态
isLogin = false;
// 当前登陆账户
managerName = null;
navStart: Observable<NavigationStart>;
constructor(
private router: Router,
private cookieService: CookieService
) {
this.navStart = router.events.pipe(
filter(evt => evt instanceof NavigationStart)
) as Observable<NavigationStart>;
}
checkUser(routeInterface: RouteInterface): void {
this.isLogin = this.cookieService.check(environment.tokenKey);
this.managerName = this.cookieService.get(environment.managerKey);
this.navStart.subscribe(evt => routeInterface.doNavigationStart(evt, this.isLogin, this.managerName));
}
}