diff --git a/src/app/pages/share/share.component.ts b/src/app/pages/share/share.component.ts index c176176f0..a6d1ac812 100644 --- a/src/app/pages/share/share.component.ts +++ b/src/app/pages/share/share.component.ts @@ -1,14 +1,13 @@ -import {ActivatedRoute} from '@angular/router'; -import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'; -// TODO 与 kubernetes 合并 @Component({ standalone: false, selector: 'pages-share', - templateUrl: 'share.component.html', + templateUrl: 'share.component.html' }) export class PagesShareComponent implements OnInit, AfterViewInit { - @ViewChild('iFrame', {static: false}) iframeRef: ElementRef; + @ViewChild('iFrame', { static: false }) iframeRef: ElementRef; public ping; public id: string = ''; @@ -16,22 +15,30 @@ export class PagesShareComponent implements OnInit, AfterViewInit { public shareId: string = ''; public iframeURL: string = ''; - constructor(private _route: ActivatedRoute) { - } + constructor(private _route: ActivatedRoute) {} ngOnInit(): void { this.id = 'window-' + Math.random().toString(36).substr(2); this.shareId = this._route.snapshot.params['id']; this.type = this._route.snapshot.queryParams['type']; + const queryParams = new URLSearchParams(); + + Object.entries(this._route.snapshot.queryParams).forEach(([key, value]) => { + if (value !== null && value !== undefined) { + queryParams.append(key, value as string); + } + }); + + const queryString = queryParams.toString(); const baseUrl = `${window.location.protocol}//${window.location.host}`; if (this.type && this.type === 'lion') { - this.iframeURL = `${baseUrl}/lion/share/${this.shareId}`; + this.iframeURL = `${baseUrl}/lion/share/${this.shareId}?${queryString}`; return; } - this.iframeURL = `${baseUrl}/koko/share/${this.shareId}`; + this.iframeURL = `${baseUrl}/koko/share/${this.shareId}?${queryString}`; } ngAfterViewInit(): void { @@ -40,10 +47,10 @@ export class PagesShareComponent implements OnInit, AfterViewInit { handleK8sIframeEvent() { this.ping = setInterval(() => { - this.iframeRef.nativeElement.contentWindow.postMessage({name: 'PING', id: this.id}, '*'); + this.iframeRef.nativeElement.contentWindow.postMessage({ name: 'PING', id: this.id }, '*'); }, 1000); - window.addEventListener('message', (event) => { + window.addEventListener('message', event => { const msg = event.data; switch (msg.name) { @@ -51,7 +58,10 @@ export class PagesShareComponent implements OnInit, AfterViewInit { clearInterval(this.ping); break; case 'PING': - this.iframeRef.nativeElement.contentWindow.postMessage({name: 'PING', id: this.id}, '*'); + this.iframeRef.nativeElement.contentWindow.postMessage( + { name: 'PING', id: this.id }, + '*' + ); break; default: break;