Browse Source

[完善]跳转预案

master
邵佳豪 1 year ago
parent
commit
c4ebd842cd
  1. 75
      src/app/auth.guard.ts
  2. 12
      src/app/plan-management/entry-plan/entry-plan.component.ts

75
src/app/auth.guard.ts

@ -1,31 +1,70 @@
import { Injectable } from '@angular/core'; import { HttpClient } from "@angular/common/http";
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; import { Injectable } from "@angular/core";
import {
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Router,
} from "@angular/router";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: "root",
}) })
export class AuthGuard implements CanActivate { 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", next);
console.log("state", state);
if (
next.queryParams.singleSignOn &&
next.queryParams.singleSignOn === "true"
) {
//执行自动登录逻辑
await this.onSubmit();
} }
return this.checkLogin();
}
// 路由守卫 checkLogin(): boolean {
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { // 判断本地有没有token
const token = sessionStorage.getItem("token");
return this.checkLogin(); // 如果有token,允许访问
if (token) {
return true;
} }
checkLogin(): boolean { //如果没有token,跳转登录页
this.router.navigate(["/login"]);
return false;
}
// 判断本地有没有token onSubmit() {
const token = sessionStorage.getItem('token'); return new Promise<void>((resolve, reject) => {
this.http
// 如果有token,允许访问 .post("/api/Account/SignIn", {
if (token) { return true; } name: "superadmin",
password: "SHya119!@",
//如果没有token,跳转登录页 })
this.router.navigate(['/login']); .subscribe(
return false; (data: any) => {
} sessionStorage.setItem("level", data.level);
sessionStorage.setItem("token", data.token);
sessionStorage.setItem("refreshToken", data.refreshToken);
sessionStorage.setItem("isDefaultPassword", data.isDefaultPassword); //是否需要修改默认密码
sessionStorage.setItem("singleSignOn", "true"); //是否需要修改默认密码
resolve();
},
(err) => {
reject();
}
);
});
}
} }

12
src/app/plan-management/entry-plan/entry-plan.component.ts

@ -370,6 +370,8 @@ export class EntryPlanComponent implements OnInit {
if (this.reservePlanType && this.reservePlanType.length != 0) { if (this.reservePlanType && this.reservePlanType.length != 0) {
reservePlanType = eval(this.reservePlanType.join("|")); reservePlanType = eval(this.reservePlanType.join("|"));
} }
let singleSignOn = sessionStorage.getItem("singleSignOn");
let paramsdata: any = { let paramsdata: any = {
CompanyName: this.companyName || "", CompanyName: this.companyName || "",
OrganizationId: this.jsId || "", OrganizationId: this.jsId || "",
@ -389,6 +391,14 @@ export class EntryPlanComponent implements OnInit {
IsNewData: this.IsNewData, IsNewData: this.IsNewData,
IsNewCompanyData: this.IsNewCompanyData, IsNewCompanyData: this.IsNewCompanyData,
PlanModes: planmode, PlanModes: planmode,
CompanyNames: singleSignOn
? [
"大连路地铁站",
"东方渔人码头投资开发有限公司",
"上海孚宝港务有限公司",
"上海国际会议中心",
]
: [],
}; };
this.http this.http
.get("/api/Plans", { params: paramsdata }) .get("/api/Plans", { params: paramsdata })
@ -396,7 +406,7 @@ export class EntryPlanComponent implements OnInit {
this.length = data.totalCount; this.length = data.totalCount;
this.allPlanInfo = data; this.allPlanInfo = data;
this.tabledataSource = data.items; this.tabledataSource = data.items;
console.log('预案列表',this.tabledataSource) console.log("预案列表", this.tabledataSource);
}); });
} }

Loading…
Cancel
Save