1- import { Injectable } from '@angular/core' ;
2- import { Router } from '@angular/router' ;
3- import { CookieService } from 'ngx-cookie-service' ;
4- import { environment } from '@src/environments/environment' ;
5- import { DataStore , User } from '@app/globals' ;
6- import { HttpService } from './http' ;
7- import { LocalStorageService , LogService } from './share' ;
8- import { SettingService } from '@app/services/setting' ;
9- import { Account , Asset , AuthInfo , ConnectData , Endpoint , Organization , View } from '@app/model' ;
1+ import { Injectable } from '@angular/core' ;
2+ import { Router } from '@angular/router' ;
3+ import { CookieService } from 'ngx-cookie-service' ;
4+ import { environment } from '@src/environments/environment' ;
5+ import { DataStore , User } from '@app/globals' ;
6+ import { HttpService } from './http' ;
7+ import { LocalStorageService , LogService } from './share' ;
8+ import { SettingService } from '@app/services/setting' ;
9+ import { Account , Asset , AuthInfo , ConnectData , Endpoint , Organization , View } from '@app/model' ;
1010import * as CryptoJS from 'crypto-js' ;
11- import { OrganizationService } from './organization' ;
12- import { I18nService } from '@app/services/i18n' ;
11+ import { OrganizationService } from './organization' ;
12+ import { I18nService } from '@app/services/i18n' ;
1313
1414declare function unescape ( s : string ) : string ;
1515
@@ -34,14 +34,16 @@ export class AppService {
3434 private newLoginHasOpen = false ; // 避免多次打开新登录页
3535 private checkSecond = 120 ;
3636
37- constructor ( private _http : HttpService ,
38- private _router : Router ,
39- private _cookie : CookieService ,
40- private _i18n : I18nService ,
41- private _logger : LogService ,
42- private _settingSvc : SettingService ,
43- private _localStorage : LocalStorageService ,
44- private _orgSvc : OrganizationService ) {
37+ constructor (
38+ private _http : HttpService ,
39+ private _router : Router ,
40+ private _cookie : CookieService ,
41+ private _i18n : I18nService ,
42+ private _logger : LogService ,
43+ private _settingSvc : SettingService ,
44+ private _localStorage : LocalStorageService ,
45+ private _orgSvc : OrganizationService
46+ ) {
4547 this . setLogLevel ( ) ;
4648 this . setOrgFromQueryString ( ) ;
4749 this . checkLogin ( ) ;
@@ -62,7 +64,7 @@ export class AppService {
6264 setOrgFromQueryString ( ) {
6365 const oid = this . getQueryString ( 'oid' ) ;
6466 if ( oid ) {
65- const currentOrg : Organization = { id : oid , name : '' } ;
67+ const currentOrg : Organization = { id : oid , name : '' } ;
6668 this . _orgSvc . switchOrg ( currentOrg ) ;
6769 }
6870 }
@@ -127,9 +129,9 @@ export class AppService {
127129
128130 getErrorMsg ( status : string ) {
129131 const messages = {
130- ' unauthorized' : 'LoginExpireMsg' ,
131- ' badrequest' : 'Bad request. The server does not understand the syntax of the request' ,
132- ' error' : 'The server encountered an error while trying to process the request'
132+ unauthorized : 'LoginExpireMsg' ,
133+ badrequest : 'Bad request. The server does not understand the syntax of the request' ,
134+ error : 'The server encountered an error while trying to process the request'
133135 } ;
134136 return messages [ status ] ;
135137 }
@@ -168,7 +170,6 @@ export class AppService {
168170
169171 this . _http . getUserProfile ( ) . then (
170172 user => {
171- console . log ( 'User is: ' , user ) ;
172173 this . _orgSvc . setWorkbenchOrgs ( user [ 'workbench_orgs' ] ) ;
173174 Object . assign ( User , user ) ;
174175 User . logined = true ;
@@ -182,7 +183,7 @@ export class AppService {
182183 gotoLogin ( ) ;
183184 }
184185 // this._router.navigate(['login']);
185- } ,
186+ }
186187 ) ;
187188 }
188189
@@ -237,17 +238,17 @@ export class AppService {
237238 }
238239
239240 setPreConnectData ( asset : Asset , connectData : ConnectData ) {
240- const { account, protocol, connectMethod, manualAuthInfo, connectOption} = connectData ;
241+ const { account, protocol, connectMethod, manualAuthInfo, connectOption } = connectData ;
241242 const key = `JMS_PRE_${ asset . id } ` ;
242243
243244 const saveData = {
244- account : { alias : account . alias , username : account . username , has_secret : account . has_secret } ,
245- connectMethod : { value : connectMethod . value } ,
246- protocol : { name : protocol . name } ,
245+ account : { alias : account . alias , username : account . username , has_secret : account . has_secret } ,
246+ connectMethod : { value : connectMethod . value } ,
247+ protocol : { name : protocol . name } ,
247248 downloadRDP : connectData . downloadRDP ,
248249 autoLogin : connectData . autoLogin ,
249250 connectOption,
250- direct : connectData . direct ,
251+ direct : connectData . direct
251252 } ;
252253 this . setAccountLocalAuth ( asset , account , manualAuthInfo ) ;
253254 this . _localStorage . set ( key , saveData ) ;
@@ -330,7 +331,13 @@ export class AppService {
330331
331332 setAccountLocalAuth ( asset : Asset , account : Account , auth : AuthInfo ) {
332333 const assetId = asset . id ;
333- const newAuth = Object . assign ( { alias : account . alias , username : account . username } , auth ) ;
334+ const newAuth = Object . assign ( { alias : account . alias , username : account . username } , auth ) ;
335+
336+ // 如果 auth.alias 是 undefined,保持使用 account.alias
337+ if ( auth . alias === undefined && account . alias !== undefined ) {
338+ newAuth . alias = account . alias ;
339+ }
340+
334341 if ( ! auth . secret || ! auth . rememberAuth ) {
335342 newAuth . secret = '' ;
336343 } else {
@@ -340,7 +347,7 @@ export class AppService {
340347 let auths = this . getAccountLocalAuth ( assetId , false ) ;
341348 const localKey = `JMS_MA_${ assetId } ` ;
342349
343- auths = auths . filter ( ( item ) => item . username !== newAuth . username ) ;
350+ auths = auths . filter ( item => item . username !== newAuth . username ) ;
344351 auths . splice ( 0 , 0 , newAuth ) ;
345352 this . _localStorage . set ( localKey , auths ) ;
346353 }
@@ -355,7 +362,7 @@ export class AppService {
355362 if ( protocol === 'http' ) {
356363 protocol = window . location . protocol . replace ( ':' , '' ) ;
357364 }
358- const data = { ' assetId' : '' , ' sessionId' : '' , ' token' : '' } ;
365+ const data = { assetId : '' , sessionId : '' , token : '' } ;
359366 if ( view . connectToken ) {
360367 data [ 'token' ] = view . connectToken . id ;
361368 } else {
@@ -369,7 +376,7 @@ export class AppService {
369376 }
370377 }
371378 const res = this . _http . getSmartEndpoint ( data , protocol ) ;
372- res . catch ( ( err ) => {
379+ res . catch ( err => {
373380 alert ( err . error . detail ) ;
374381 } ) ;
375382 return res ;
0 commit comments