Skip to content

Commit 805672d

Browse files
committed
perf: 优化 rdp 复用下拉选项
1 parent 8fe0731 commit 805672d

File tree

2 files changed

+64
-41
lines changed

2 files changed

+64
-41
lines changed

src/app/elements/connect/connect-dialog/advanced-option/advanced-option.component.html

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,40 @@
99

1010
<div *ngIf="isShowAdvancedOption" class="options-container">
1111
<ng-container *ngFor="let item of advancedOptions">
12-
<div *ngIf="item.type === 'checkbox'" class="option-item">
13-
<mat-checkbox
14-
[(ngModel)]="connectOption[item.field]"
15-
[name]="item.field"
16-
>
17-
{{ item.label | translate }}
18-
</mat-checkbox>
19-
</div>
20-
<ng-container *ngIf="item.type === 'select'">
21-
<mat-form-field class="option-item">
22-
<mat-label>{{ item.label | translate }}</mat-label>
23-
<mat-select [(ngModel)]="connectOption[item.field]" [name]="item.field">
24-
<mat-option *ngFor="let option of item.options" [value]="option.value">
25-
{{ option.label | translate }}
26-
</mat-option>
27-
</mat-select>
28-
</mat-form-field>
29-
</ng-container>
30-
<ng-container *ngIf="item.type === 'radio'">
31-
<div class="option-item">
32-
<mat-radio-group [(ngModel)]="connectOption[item.field]" [name]="item.field">
33-
<mat-label style="margin-right: 10px">{{ item.label | translate }}</mat-label>
34-
<mat-radio-button *ngFor="let option of item.options" [value]="option.value">
35-
{{ option.label | translate }}
36-
</mat-radio-button>
37-
</mat-radio-group>
12+
<span>
13+
<div *ngIf="item.type === 'checkbox'" class="option-item">
14+
<mat-checkbox
15+
(change)="onChange()"
16+
[(ngModel)]="connectOption[item.field]"
17+
[name]="item.field"
18+
>
19+
{{ item.label | translate }}
20+
</mat-checkbox>
3821
</div>
39-
</ng-container>
22+
<ng-container *ngIf="item.type === 'select'">
23+
<mat-form-field class="option-item">
24+
<mat-label>{{ item.label | translate }}</mat-label>
25+
<mat-select (selectionChange)="onChange()" [(ngModel)]="connectOption[item.field]"
26+
[name]="item.field"
27+
>
28+
<mat-option *ngFor="let option of item.options" [value]="option.value">
29+
{{ option.label | translate }}
30+
</mat-option>
31+
</mat-select>
32+
</mat-form-field>
33+
</ng-container>
34+
<ng-container *ngIf="item.type === 'radio'">
35+
<div class="option-item">
36+
<mat-radio-group (change)="onChange()" [(ngModel)]="connectOption[item.field]"
37+
[name]="item.field">
38+
<mat-label style="margin-right: 10px">{{ item.label | translate }}</mat-label>
39+
<mat-radio-button *ngFor="let option of item.options" [value]="option.value">
40+
{{ option.label | translate }}
41+
</mat-radio-button>
42+
</mat-radio-group>
43+
</div>
44+
</ng-container>
45+
</span>
4046
</ng-container>
4147
</div>
4248
</mat-expansion-panel>

src/app/elements/connect/connect-dialog/advanced-option/advanced-option.component.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, Input, OnChanges} from '@angular/core';
1+
import {Component, Input, OnChanges, OnInit} from '@angular/core';
22
import {ConnectMethod, ConnectOption, Protocol, Setting} from '@app/model';
33
import {resolutionsChoices} from '@app/globals';
44
import {SettingService} from '@app/services';
@@ -8,24 +8,22 @@ import {SettingService} from '@app/services';
88
templateUrl: './advanced-option.component.html',
99
styleUrls: ['./advanced-option.component.scss'],
1010
})
11-
export class ElementAdvancedOptionComponent implements OnChanges {
11+
export class ElementAdvancedOptionComponent implements OnChanges, OnInit {
1212
@Input() protocol: Protocol;
1313
@Input() connectMethod: ConnectMethod;
14-
@Input() connectOption: Object = {};
14+
@Input() connectOption: any = {};
1515
public advancedOptions: ConnectOption[] = [];
1616
public isShowAdvancedOption = false;
1717
public setting: Setting;
18+
private allOptions: ConnectOption[] = [];
1819
private boolChoices = [
1920
{label: 'Yes', value: true},
2021
{label: 'No', value: false},
2122
];
2223

2324
constructor(public _settingSvc: SettingService) {
2425
this.setting = _settingSvc.setting;
25-
}
26-
27-
ngOnChanges() {
28-
this.advancedOptions = [
26+
this.allOptions = [
2927
{
3028
type: 'select',
3129
field: 'charset',
@@ -96,7 +94,6 @@ export class ElementAdvancedOptionComponent implements OnChanges {
9694
if (!this._settingSvc.hasXPack()) {
9795
return true;
9896
}
99-
10097
return !this.connectMethod || this.connectMethod.component !== 'tinker';
10198
}
10299
},
@@ -113,20 +110,40 @@ export class ElementAdvancedOptionComponent implements OnChanges {
113110
if (!this._settingSvc.globalSetting.CONNECTION_TOKEN_REUSABLE) {
114111
return true;
115112
}
116-
return this.connectMethod.component !== 'tinker' && this.connectMethod.component !== 'razor';
113+
if (this.connectMethod.component === 'razor') {
114+
return false;
115+
}
116+
if (this.connectMethod.component === 'tinker') {
117+
return this.connectOption.appletConnectMethod !== 'client';
118+
}
119+
return true;
117120
}
118121
}
119122
];
123+
}
124+
125+
ngOnInit() {
126+
}
127+
128+
checkOptions() {
120129
const onlyUsingDefaultFields = ['reusable'];
121-
onlyUsingDefaultFields.forEach(i => {
122-
this.connectOption[i] = this.advancedOptions.find(j => j.field === i).value;
123-
});
124-
this.advancedOptions = this.advancedOptions.filter(i => !i.hidden());
125-
this.advancedOptions.forEach(i => {
130+
this.allOptions.forEach(i => {
126131
if (this.connectOption[i.field] === undefined) {
127132
this.connectOption[i.field] = i.value;
128133
}
134+
if (onlyUsingDefaultFields.includes(i.field)) {
135+
i.value = this.connectOption[i.field];
136+
}
129137
});
138+
this.advancedOptions = this.allOptions.filter(i => !i.hidden());
130139
this.isShowAdvancedOption = this.advancedOptions.length > 0;
131140
}
141+
142+
onChange() {
143+
this.checkOptions();
144+
}
145+
146+
ngOnChanges() {
147+
this.checkOptions();
148+
}
132149
}

0 commit comments

Comments
 (0)