Browse Source

新增路由守卫

dev
陈鹏飞 3 years ago
parent
commit
ebb8f65ee8
  1. 39
      src/app/pages/init3D.guard.ts
  2. 3
      src/app/pages/pages-routing.module.ts
  3. 2
      src/app/pages/plan/plan.component.html
  4. 8
      src/app/pages/plan/plan.component.scss
  5. 8
      src/app/pages/plan/plan.component.ts

39
src/app/pages/init3D.guard.ts

@ -0,0 +1,39 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Component, OnInit, Inject } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { ModeManager } from '../babylon/controller/mode-manager';
import { NzMessageService } from 'ng-zorro-antd/message';
@Injectable({
providedIn: 'root'
})
export class init3DGuard implements CanActivate {
constructor(private router: Router, private http: HttpClient, private message: NzMessageService,) { }
// 路由守卫
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot,): Promise<boolean> {
return this.getGasStationBaseInfo().then((res: any) => {
sessionStorage.setItem("3dSceneData", JSON.stringify(res))
let isMakeMode = ModeManager.s_isMakeMode
if (isMakeMode || res.hasBuildingInfo) {
return true
} else if (!res.hasBuildingInfo) {
this.message.info("当前站点没有数字油站!");
return false
}
});
}
//获取 当前加油站基本信息
getGasStationBaseInfo() {
return new Promise((resolve, reject) => {
let params = { organizationUnitId: (JSON.parse(sessionStorage.getItem('userdataOfgasstation'))).organization.id }
this.http.get('/api/services/app/GasStation/Get', { params: params }).subscribe((data: any)=>{
resolve(data.result)
})
})
}
}

3
src/app/pages/pages-routing.module.ts

@ -10,11 +10,12 @@ import { OilStationInfoComponent } from './oil-station-info/oil-station-info.com
import { EquipmentInfoComponent } from './equipment-info/equipment-info.component';
import { PlanAdminComponent } from './plan-admin/plan-admin.component';
import { HomePageComponent } from './home-page/home-page.component';
import { init3DGuard } from './init3D.guard';
const routes: Routes = [
{ path: 'homepage', component: HomePageComponent },
{ path: 'plan', component: PlanAdminComponent },
{ path: 'plan/petrolStation', component: PlanComponent },
{ path: 'plan/petrolStation', component: PlanComponent, canActivate: [init3DGuard], },
{ path: 'warning', component: TodayWarningAdminComponent },
{ path: 'warning/petrolStation', component: TodayWarningComponent },
{ path: 'records', component: CriminalRecordsAdminComponent },

2
src/app/pages/plan/plan.component.html

@ -104,7 +104,7 @@
<!-- 右侧属性栏 -->
<!-- 右侧图标栏 -->
<div class="rightIcons" *ngIf="editMode && (selectFence === 0 || selectFence === 7)" [ngClass]="{'publicMoveUp': selectFence === 7}" [ngStyle]="{'width': selectFence === 0? '60px' : null}">
<div class="rightIcons" *ngIf="editMode && (selectFence === 0 || selectFence === 7)" [ngClass]="{'publicMoveUp': selectFence === 7}" [ngStyle]="{'width': selectFence === 7? '100px' : null}">
<div class="bottomCenter" id="bottomCenter">
<ng-container *ngIf="selectFence === 0">
<div class="everyIcon" (click)='selectBottomIcon(item)' *ngFor="let item of allFacilityUIItemes" [ngClass]="{'selectLeftIcon': beforeOneIcon == item.getIconID()}">

8
src/app/pages/plan/plan.component.scss

@ -227,13 +227,11 @@
//右侧图标栏
.rightIcons{
width: 100px;
height: 70%;
width: 60px;
height: 260px;
position: absolute;
top: 0;
bottom: 0;
top: 10%;
right: 1%;
margin: auto;/*这行代码是关键*/
color: #fff;
background: linear-gradient(360deg, #000D21 0%, rgba(0, 59, 110, 0.8) 100%);
overflow: hidden;

8
src/app/pages/plan/plan.component.ts

@ -80,7 +80,6 @@ export class PlanComponent implements OnInit {
ngAfterViewInit(): void {
this.getGasStationBaseInfo().then((res: any) => { //获取单位 基本信息
// console.log(res, "当前加油站信息")
let simpleData: InsitutionDataSimple = new InsitutionDataSimple();
simpleData.id = res.id || 6; //来自选中的单位的信息 ,测试:1
simpleData.key = `${res.id}` || "ceshi"; //测试:"ceshi"
@ -91,7 +90,6 @@ export class PlanComponent implements OnInit {
if (ModeManager.institutionDemoKey == ModeManager.c_demoKey_null) { //无指定测试单位,则为正式启动,根据当前单位key寻找
if (has3dData) { //如果已经有三维数据,直接进入
this.beforeOneSatus = StatusManager.getStatus<LoginSatus>(LoginSatus);
// console.log("进入三维单位", simpleData);
this.beforeOneSatus.onSelectInsSuccess(simpleData)
} else { //如果没有三维数据
if (ModeManager.s_isMakeMode) //内部制作模式下,询问新建
@ -131,10 +129,8 @@ export class PlanComponent implements OnInit {
//获取 当前加油站基本信息
getGasStationBaseInfo() {
return new Promise((resolve, reject) => {
let params = { organizationUnitId: this.companyData.id }
this.http.get('/api/services/app/GasStation/Get', { params: params }).subscribe((data: any) => {
resolve(data.result)
})
let result = JSON.parse(sessionStorage.getItem("3dSceneData"))
resolve(result)
})
}

Loading…
Cancel
Save