|
@@ -1,28 +1,73 @@
|
|
|
// page-vibration-monitor.component.ts
|
|
|
-import { Component, AfterViewInit } from '@angular/core';
|
|
|
+import { Component, AfterViewInit, OnInit } from '@angular/core';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
import { Swiper } from 'swiper';
|
|
|
import { Navigation, Pagination, Autoplay } from 'swiper/modules';
|
|
|
import * as echarts from 'echarts';
|
|
|
-import { RouterModule } from '@angular/router';
|
|
|
+import { Router, RouterModule, NavigationEnd } from '@angular/router';
|
|
|
+import { filter } from 'rxjs/operators';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-page-vibration-monitor',
|
|
|
- // standalone: true,
|
|
|
- imports: [CommonModule, FormsModule,RouterModule],
|
|
|
+ // standalone: true,
|
|
|
+ imports: [CommonModule, FormsModule, RouterModule],
|
|
|
templateUrl: './page-vibration-monitor.component.html',
|
|
|
styleUrls: ['./page-vibration-monitor.component.scss']
|
|
|
})
|
|
|
-export class PageVibrationMonitorComponent implements AfterViewInit {
|
|
|
+export class PageVibrationMonitorComponent implements AfterViewInit, OnInit {
|
|
|
searchQuery = '';
|
|
|
|
|
|
+ constructor(private router: Router) {}
|
|
|
+
|
|
|
+ ngOnInit(): void {
|
|
|
+ this.setupFragmentNavigation();
|
|
|
+ }
|
|
|
+
|
|
|
ngAfterViewInit(): void {
|
|
|
this.initKnowledgeGraph();
|
|
|
this.initSwiper();
|
|
|
this.setupEventListeners();
|
|
|
- //jia
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ private setupFragmentNavigation(): void {
|
|
|
+ // 监听路由变化,处理片段导航
|
|
|
+ this.router.events
|
|
|
+ .pipe(filter(event => event instanceof NavigationEnd))
|
|
|
+ .subscribe((event: NavigationEnd) => {
|
|
|
+ const fragment = this.getFragmentFromUrl(event.url);
|
|
|
+ if (fragment) {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scrollToFragment(fragment);
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 初始加载时检查URL中的片段
|
|
|
+ const initialFragment = this.getFragmentFromUrl(this.router.url);
|
|
|
+ if (initialFragment) {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.scrollToFragment(initialFragment);
|
|
|
+ }, 500); // 稍长延迟确保所有内容已加载
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private getFragmentFromUrl(url: string): string | null {
|
|
|
+ const hashIndex = url.indexOf('#');
|
|
|
+ return hashIndex !== -1 ? url.substring(hashIndex + 1) : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private scrollToFragment(fragment: string): void {
|
|
|
+ const element = document.getElementById(fragment);
|
|
|
+ if (element) {
|
|
|
+ element.scrollIntoView({ behavior: 'smooth' });
|
|
|
+
|
|
|
+ // 添加高亮效果
|
|
|
+ element.classList.add('fragment-highlight');
|
|
|
+ setTimeout(() => {
|
|
|
+ element.classList.remove('fragment-highlight');
|
|
|
+ }, 2000);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private initKnowledgeGraph(): void {
|
|
@@ -155,4 +200,4 @@ export class PageVibrationMonitorComponent implements AfterViewInit {
|
|
|
}, 1000);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|