Skip to content

Commit

Permalink
perf: 优化切换组织
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuler committed May 21, 2024
1 parent a93405d commit 975477d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/app/elements/organization/organization.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component, OnInit, OnDestroy, Input} from '@angular/core';
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {CookieService} from 'ngx-cookie-service';
import {ActivatedRoute, Router} from '@angular/router';
import {OrganizationService, SettingService} from '@app/services';
import {Organization} from '@app/model';
import {DEFAULT_ORG_ID, ROOT_ORG_ID} from '@app/globals';
Expand All @@ -13,14 +14,18 @@ export class ElementOrganizationComponent implements OnInit, OnDestroy {
currentOrg: Organization = {id: '', name: ''};
organizations = [];
@Input() isK8s: boolean = false;

constructor(private _cookie: CookieService,
public _settingSvc: SettingService,
private _orgSvc: OrganizationService
) {}
private _orgSvc: OrganizationService,
private _router: Router,
private _route: ActivatedRoute
) {
}

ngOnInit() {
const cookieOrgId = this._cookie.get('X-JMS-LUNA-ORG') || this._cookie.get('X-JMS-ORG');
this._orgSvc.orgListChange$.subscribe(async(res) => {
this._orgSvc.orgListChange$.subscribe(async (res) => {
this.organizations = res;
const cookieOrg = await this.organizations.find(i => i.id === cookieOrgId);
if (!cookieOrg) {
Expand Down Expand Up @@ -50,5 +55,12 @@ export class ElementOrganizationComponent implements OnInit, OnDestroy {
changeOrg(event) {
this.currentOrg = event.value;
this._orgSvc.switchOrg(this.currentOrg);
const query = {...this._route.snapshot.queryParams};
delete query['oid'];
delete query['_'];
this._router.navigate([], {
relativeTo: this._route,
queryParams: query,
});
}
}

0 comments on commit 975477d

Please sign in to comment.