import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , CanActivateChild } from '@angular/router' ; import { SessionService } from 'app/base/shared/session.service' ; import { NzModalService } from 'ng-zorro-antd' ; @ Injectable ( ) export class PermissionGurid implements CanActivate , CanActivateChild { constructor ( private sessionService , private confirmServ ) { } canActivate ( route , state ) { const pCodes = route . data ? route . data [ 'permission' ] : null ; if ( ! pCodes ) { return true ; } ; const permissions = this . sessionService . getSession ( ) . permissions ; const success = permissions . some ( p => pCodes . some ( code => p . code === code ) ) ; if ( ! success ) { this . confirmServ . error ( { title : '缺少权限' , content : '缺少权限：' + pCodes . join ( ',' ) } ) ; } return success ; } canActivateChild ( route , state ) { return this . canActivate ( route , state ) ; } }