1- import { ActivatedRoute } from '@angular/router' ;
2- import { AfterViewInit , Component , ElementRef , OnInit , ViewChild } from '@angular/core' ;
1+ import { ActivatedRoute } from '@angular/router' ;
2+ import { AfterViewInit , Component , ElementRef , OnInit , ViewChild } from '@angular/core' ;
33
4- // TODO 与 kubernetes 合并
54@Component ( {
65 standalone : false ,
76 selector : 'pages-share' ,
8- templateUrl : 'share.component.html' ,
7+ templateUrl : 'share.component.html'
98} )
109export class PagesShareComponent implements OnInit , AfterViewInit {
11- @ViewChild ( 'iFrame' , { static : false } ) iframeRef : ElementRef ;
10+ @ViewChild ( 'iFrame' , { static : false } ) iframeRef : ElementRef ;
1211
1312 public ping ;
1413 public id : string = '' ;
1514 public type : string = '' ;
1615 public shareId : string = '' ;
1716 public iframeURL : string = '' ;
1817
19- constructor ( private _route : ActivatedRoute ) {
20- }
18+ constructor ( private _route : ActivatedRoute ) { }
2119
2220 ngOnInit ( ) : void {
2321 this . id = 'window-' + Math . random ( ) . toString ( 36 ) . substr ( 2 ) ;
2422 this . shareId = this . _route . snapshot . params [ 'id' ] ;
2523 this . type = this . _route . snapshot . queryParams [ 'type' ] ;
2624
25+ const queryParams = new URLSearchParams ( ) ;
26+
27+ Object . entries ( this . _route . snapshot . queryParams ) . forEach ( ( [ key , value ] ) => {
28+ if ( value !== null && value !== undefined ) {
29+ queryParams . append ( key , value as string ) ;
30+ }
31+ } ) ;
32+
33+ const queryString = queryParams . toString ( ) ;
2734 const baseUrl = `${ window . location . protocol } //${ window . location . host } ` ;
2835
2936 if ( this . type && this . type === 'lion' ) {
30- this . iframeURL = `${ baseUrl } /lion/share/${ this . shareId } ` ;
37+ this . iframeURL = `${ baseUrl } /lion/share/${ this . shareId } ? ${ queryString } ` ;
3138 return ;
3239 }
3340
34- this . iframeURL = `${ baseUrl } /koko/share/${ this . shareId } ` ;
41+ this . iframeURL = `${ baseUrl } /koko/share/${ this . shareId } ? ${ queryString } ` ;
3542 }
3643
3744 ngAfterViewInit ( ) : void {
@@ -40,18 +47,21 @@ export class PagesShareComponent implements OnInit, AfterViewInit {
4047
4148 handleK8sIframeEvent ( ) {
4249 this . ping = setInterval ( ( ) => {
43- this . iframeRef . nativeElement . contentWindow . postMessage ( { name : 'PING' , id : this . id } , '*' ) ;
50+ this . iframeRef . nativeElement . contentWindow . postMessage ( { name : 'PING' , id : this . id } , '*' ) ;
4451 } , 1000 ) ;
4552
46- window . addEventListener ( 'message' , ( event ) => {
53+ window . addEventListener ( 'message' , event => {
4754 const msg = event . data ;
4855
4956 switch ( msg . name ) {
5057 case 'PONG' :
5158 clearInterval ( this . ping ) ;
5259 break ;
5360 case 'PING' :
54- this . iframeRef . nativeElement . contentWindow . postMessage ( { name : 'PING' , id : this . id } , '*' ) ;
61+ this . iframeRef . nativeElement . contentWindow . postMessage (
62+ { name : 'PING' , id : this . id } ,
63+ '*'
64+ ) ;
5565 break ;
5666 default :
5767 break ;
0 commit comments