import { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd, ActivatedRoute } from '@angular/router'; import { Title } from '@angular/platform-browser' import { filter } from 'rxjs/operators'; import { NavChangeService } from 'src/app/service/navChange.service'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'] }) export class HomeComponent implements OnInit { constructor(private router: Router, private navChangeService: NavChangeService) { } isGasStationNav: boolean isGasStation: boolean isWarning: boolean = false//是否是今日预警页面 num ngOnInit(): void { this.navChangeService.getMessage().subscribe((message: any) => { console.log(message);//send a message if (message.name == 'oilstation') { this.isGasStationNav = true } if (message.name == '改变数量') { this.isWarning = true this.num = message.num } }); if (this.router.url.indexOf('warning') != -1) { this.isWarning = true } else { this.isWarning = false } if (this.router.url.indexOf('petrolStation') != -1 && sessionStorage.getItem('isGasStation') == 'false') {//控制返回按钮显示 this.isGasStation = true } else { this.isGasStation = false } if (sessionStorage.getItem('isGasStation') == 'true') { this.isGasStationNav = true } else { this.isGasStationNav = false } this.router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((event: any) => { if (event.url.indexOf('warning') != -1) {//控制今日预警左上角数字显示 } else { this.isWarning = false } if (event.url.indexOf('petrolStation') != -1 && sessionStorage.getItem('isGasStation') == 'false') {//控制返回按钮显示 this.isGasStation = true } else { this.isGasStation = false } }); } goback() { this.router.navigate(['/plan']) this.isGasStationNav = false } }