4 changed files with 158 additions and 106 deletions
@ -1,35 +1,96 @@
|
||||
import { Component, OnInit, Inject } from '@angular/core'; |
||||
import { Injectable } from '@angular/core'; |
||||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; |
||||
import { HttpClient } from "@angular/common/http"; |
||||
import { Component, OnInit, Inject } from "@angular/core"; |
||||
import { Injectable } from "@angular/core"; |
||||
import { |
||||
CanActivate, |
||||
ActivatedRouteSnapshot, |
||||
RouterStateSnapshot, |
||||
Router, |
||||
} from "@angular/router"; |
||||
|
||||
@Injectable({ |
||||
providedIn: 'root' |
||||
providedIn: "root", |
||||
}) |
||||
export class AuthGuard implements CanActivate { |
||||
constructor(private http: HttpClient, private router: Router) {} |
||||
|
||||
constructor(private router: Router) { |
||||
|
||||
// 路由守卫
|
||||
async canActivate( |
||||
next: ActivatedRouteSnapshot, |
||||
state: RouterStateSnapshot |
||||
): Promise<boolean> { |
||||
console.log("路由守卫", next); |
||||
if ( |
||||
next.queryParams.singleSignOn && |
||||
next.queryParams.singleSignOn === "true" |
||||
) { |
||||
await this.autoLogin(); |
||||
} |
||||
return this.checkLogin(); |
||||
} |
||||
|
||||
// 路由守卫
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { |
||||
// console.log('路由守卫',next.data)
|
||||
// if(next.data.permission == 'xxxx'){
|
||||
// return true;
|
||||
// }
|
||||
return this.checkLogin(); |
||||
} |
||||
checkLogin(): boolean { |
||||
// 判断本地有没有token
|
||||
const token = sessionStorage.getItem("token"); |
||||
|
||||
checkLogin(): boolean { |
||||
// 判断本地有没有token
|
||||
const token = sessionStorage.getItem('token'); |
||||
// 如果有token,允许访问
|
||||
if (token) { |
||||
return true; |
||||
} |
||||
|
||||
// 如果有token,允许访问
|
||||
if (token) { return true; } |
||||
//如果没有token,跳转登录页
|
||||
this.router.navigate(["/login"]); |
||||
|
||||
//如果没有token,跳转登录页
|
||||
this.router.navigate(['/login']); |
||||
return false; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
autoLogin() { |
||||
return new Promise<void>((resolve, reject) => { |
||||
this.http |
||||
.post("/api/TokenAuth/Authenticate", { |
||||
userNameOrEmailAddress: "superadmin", |
||||
password: "Admin119119119", |
||||
}) |
||||
.subscribe( |
||||
(data: any) => { |
||||
sessionStorage.setItem("token", data.result.accessToken); |
||||
sessionStorage.setItem( |
||||
"encryptedAccessToken", |
||||
data.result.encryptedAccessToken |
||||
); |
||||
this.http |
||||
.get("/api/services/app/Session/GetCurrentLoginInformations") |
||||
.subscribe( |
||||
async (data: any) => { |
||||
console.log("GetCurrentLoginInformations", data.result); |
||||
sessionStorage.setItem( |
||||
"userdata", |
||||
JSON.stringify(data.result.user) |
||||
); |
||||
sessionStorage.setItem( |
||||
"userdataOfgasstation", |
||||
JSON.stringify(data.result.user) |
||||
); |
||||
sessionStorage.setItem( |
||||
"isDefaultPassword", |
||||
JSON.stringify(data.result.user.isDefaultPassword) |
||||
); |
||||
sessionStorage.setItem( |
||||
"isPasswordExpired", |
||||
JSON.stringify(data.result.user.isPasswordExpired) |
||||
); |
||||
sessionStorage.setItem("isGasStation", "false"); |
||||
resolve(); |
||||
}, |
||||
(err) => { |
||||
reject(); |
||||
} |
||||
); |
||||
}, |
||||
(err) => { |
||||
reject(); |
||||
} |
||||
); |
||||
}); |
||||
} |
||||
} |
||||
|
@ -1,80 +1,86 @@
|
||||
import { Component, OnInit } from '@angular/core'; |
||||
import { Router } from '@angular/router'; |
||||
import { IsShowEchartsService } from 'src/app/service/isShowEcharts.service'; |
||||
import {Location} from "@angular/common"; |
||||
import { Component, OnInit } from "@angular/core"; |
||||
import { Router } from "@angular/router"; |
||||
import { IsShowEchartsService } from "src/app/service/isShowEcharts.service"; |
||||
import { Location } from "@angular/common"; |
||||
@Component({ |
||||
selector: 'app-records-nav', |
||||
templateUrl: './records-nav.component.html', |
||||
styleUrls: ['./records-nav.component.scss'] |
||||
selector: "app-records-nav", |
||||
templateUrl: "./records-nav.component.html", |
||||
styleUrls: ["./records-nav.component.scss"], |
||||
}) |
||||
export class RecordsNavComponent implements OnInit { |
||||
constructor( |
||||
private router: Router, |
||||
private isShowEcharts: IsShowEchartsService, |
||||
private location: Location |
||||
) {} |
||||
|
||||
constructor(private router: Router, private isShowEcharts: IsShowEchartsService,private location: Location) { } |
||||
|
||||
isEcharts = true |
||||
menuList = ['预警类型统计', '卸油统计', '证照预警统计'] |
||||
tap=[] |
||||
userMenu = [] |
||||
menu=[] |
||||
selectedMenu |
||||
isEcharts = true; |
||||
menuList = ["预警类型统计", "卸油统计", "证照预警统计"]; |
||||
tap = []; |
||||
userMenu = []; |
||||
menu = []; |
||||
selectedMenu; |
||||
ngOnInit(): void { |
||||
let a= sessionStorage.getItem('userdata') |
||||
this.userMenu=JSON.parse(a).menus |
||||
console.log(this.userMenu); |
||||
if (this.router.url.indexOf("oliunloadinglist") !== -1) { |
||||
console.log('走这个列里看看看看') |
||||
this.selectedMenu = "卸油统计"; |
||||
}else{ |
||||
this.selectedMenu = this.menu[0]; |
||||
} |
||||
|
||||
|
||||
let a = sessionStorage.getItem("userdata"); |
||||
this.userMenu = JSON.parse(a).menus; |
||||
for (let index = 0; index < this.userMenu.length; index++) { |
||||
let a=this.userMenu[index].name |
||||
this.tap.push(a) |
||||
|
||||
let a = this.userMenu[index].name; |
||||
this.tap.push(a); |
||||
} |
||||
console.log(this.tap); |
||||
|
||||
if (this.userMenu.length==0) { |
||||
this.menu=this.menuList |
||||
}else{ |
||||
if (this.userMenu.length == 0) { |
||||
this.menu = this.menuList; |
||||
} else { |
||||
for (let index = 0; index < this.menuList.length; index++) { |
||||
|
||||
for (let k = 0; k < this.tap.length; k++) { |
||||
if (this.tap[k]==this.menuList[index]) { |
||||
this.menu.push(this.tap[k])
|
||||
console.log( this.menu); |
||||
if (this.tap[k] == this.menuList[index]) { |
||||
this.menu.push(this.tap[k]); |
||||
console.log(this.menu); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
} |
||||
this.selectedMenu = this.menu[0] |
||||
this.routerChange() |
||||
|
||||
// this.selectedMenu = this.menu[0];
|
||||
this.routerChange(); |
||||
} |
||||
|
||||
selectMenu(item) { |
||||
if (this.selectedMenu == item) { |
||||
return |
||||
return; |
||||
} |
||||
this.isEcharts = true |
||||
this.selectedMenu = item |
||||
this.routerChange() |
||||
this.isEcharts = true; |
||||
this.selectedMenu = item; |
||||
this.routerChange(); |
||||
} |
||||
|
||||
routerChange() { |
||||
if (sessionStorage.getItem('isGasStation') == 'false') { |
||||
if (this.selectedMenu == '预警类型统计') { |
||||
this.router.navigate(['/records_nav/all']) |
||||
} else if (this.selectedMenu == '卸油统计') { |
||||
this.router.navigate(['/records_nav/oliunloadinglist']) |
||||
} else if (this.selectedMenu == '证照预警统计') { |
||||
this.router.navigate(['/records_nav/warningstatisticslist']) |
||||
if (sessionStorage.getItem("isGasStation") == "false") { |
||||
if (this.selectedMenu == "预警类型统计") { |
||||
this.router.navigate(["/records_nav/all"]); |
||||
} else if (this.selectedMenu == "卸油统计") { |
||||
|
||||
console.log(888888888888888888888888) |
||||
this.router.navigate(["/records_nav/oliunloadinglist"]); |
||||
} else if (this.selectedMenu == "证照预警统计") { |
||||
this.router.navigate(["/records_nav/warningstatisticslist"]); |
||||
} |
||||
} else { |
||||
if (this.selectedMenu == '预警类型统计') { |
||||
this.router.navigate(['/records_nav/petrolStation/all']) |
||||
} else if (this.selectedMenu == '卸油统计') { |
||||
this.router.navigate(['/records_nav/petrolStation/oliunloadinglist']) |
||||
} else if (this.selectedMenu == '证照预警统计') { |
||||
this.router.navigate(['/records_nav/petrolStation/warningstatisticslist']) |
||||
if (this.selectedMenu == "预警类型统计") { |
||||
this.router.navigate(["/records_nav/petrolStation/all"]); |
||||
} else if (this.selectedMenu == "卸油统计") { |
||||
this.router.navigate(["/records_nav/petrolStation/oliunloadinglist"]); |
||||
} else if (this.selectedMenu == "证照预警统计") { |
||||
this.router.navigate([ |
||||
"/records_nav/petrolStation/warningstatisticslist", |
||||
]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue