Skip to content

Commit 42246be

Browse files
authored
Merge pull request #1460 from jumpserver/dev
v4.10.10
2 parents da93e29 + c78d936 commit 42246be

File tree

7 files changed

+56
-29
lines changed

7 files changed

+56
-29
lines changed

src/app/elements/nav/nav.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ export class ElementNavComponent implements OnInit {
137137
children: themes.map(theme => ({
138138
id: theme.name,
139139
click: () => {
140+
(this._settingSvc.setting.basic as any).themes = theme.name;
140141
useTheme().switchTheme(theme.name);
141142
this._iframeSvc.sendMessage({
142143
name: 'CHANGE_MAIN_THEME',
143144
data: theme.name
144145
});
146+
this._settingSvc.save();
145147
},
146148
name: this._i18n.instant(theme.label)
147149
}))

src/app/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export class Setting {
289289
basic: {
290290
is_async_asset_tree: boolean;
291291
connect_default_open_method: string;
292+
themes?: string;
292293
};
293294
graphics: {
294295
rdp_resolution: string;
@@ -311,7 +312,8 @@ export class Setting {
311312
this.sqlClient = '1';
312313
this.basic = {
313314
is_async_asset_tree: false,
314-
connect_default_open_method: 'new'
315+
connect_default_open_method: 'new',
316+
themes: 'default'
315317
};
316318
this.graphics = {
317319
rdp_resolution: 'Auto',

src/app/pages/connect/connect.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<app-face-monitor *ngIf="isAdminConnect"></app-face-monitor>
12
<elements-chat></elements-chat>
23

34
<div #contentWindow *ngIf="isDirect">

src/app/pages/connect/connect.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class PagesConnectComponent implements OnInit, OnDestroy {
6262
private asset: any;
6363
private method: string;
6464
private permedProtocol: Protocol;
65+
public isAdminConnect: boolean = false;
6566

6667
constructor(
6768
private _i18n: I18nService,
@@ -110,6 +111,11 @@ export class PagesConnectComponent implements OnInit, OnDestroy {
110111
* 检查是否为直连模式
111112
*/
112113
private checkDirectMode() {
114+
115+
if (this._route.snapshot.routeConfig?.path === 'admin-connect') {
116+
this.isAdminConnect = true;
117+
}
118+
113119
const params = this._route.snapshot.queryParams;
114120
// 检查是否有 direct: true 参数,或者同时有 account, asset, protocol 参数
115121
this.isDirect =

src/app/services/connect-token/acl-dialog/acl-dialog.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export class ElementACLDialogComponent implements OnInit {
384384
]
385385
},
386386
face_verify_capture: {
387-
title: 'Face Verify',
387+
title: this._i18n.instant('Face Verify'),
388388
message: 'Please complete the face verification',
389389
actions: [],
390390
},
@@ -395,7 +395,7 @@ export class ElementACLDialogComponent implements OnInit {
395395
customContent: {
396396
type: 'link',
397397
link: '/ui/#/profile/index',
398-
linkText: 'Go to profile'
398+
linkText: this._i18n.instant('Go to profile')
399399
},
400400
actions: [
401401
{

src/app/services/setting.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { I18nService } from "@app/services/i18n";
55
import { HttpService } from "@app/services/http";
66
import { canvasWaterMark, getQueryParamFromURL } from "@app/utils/common";
77
import { BehaviorSubject } from "rxjs";
8+
import { setThemeTypeGetter, useTheme } from "@src/sass/theme/util";
89

910
@Injectable()
1011
export class SettingService {
@@ -106,6 +107,16 @@ export class SettingService {
106107
}
107108
await this.getSystemSetting();
108109
await this.getPublicSettings();
110+
111+
setThemeTypeGetter(() => this.setting?.basic?.themes || null);
112+
113+
try {
114+
const theme = this.setting?.basic?.themes;
115+
116+
if (theme) {
117+
useTheme().switchTheme(theme);
118+
}
119+
} catch (e) {}
109120
this.initialized$.next(true);
110121
}
111122

src/sass/theme/util.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import { mainTheme, themeColors } from "./main";
1+
import { mainTheme, themeColors } from './main';
22

33
export namespace Theme {
4-
export type ThemeType = "default" | "darkBlue" | "deepBlue" | "chinaRed";
4+
export type ThemeType = 'default' | 'darkBlue' | 'deepBlue' | 'chinaRed';
5+
}
6+
7+
let themeTypeGetter: (() => string | null) | null = null;
8+
9+
export function setThemeTypeGetter(fn: () => string | null) {
10+
themeTypeGetter = fn;
511
}
612

7-
// 获取当前主题的主色
813
function getCurrentThemeColor(): string {
9-
const themeType = localStorage.getItem("themeType") || "default";
14+
const themeType = (themeTypeGetter && themeTypeGetter()) || 'default';
1015
return themeColors[themeType] || themeColors.default;
1116
}
1217

@@ -16,12 +21,12 @@ export function lighten(amount: number, color?: string, alphaValue?: number): st
1621
const actualColor = color || getCurrentThemeColor();
1722
const hsl = hexToHSL(actualColor);
1823
const hexColor = hslToHex(hsl.h, hsl.s, Math.min(100, hsl.l + amount));
19-
24+
2025
// 如果提供了透明度参数,应用透明度
2126
if (alphaValue !== undefined) {
2227
return alpha(alphaValue, hexColor);
2328
}
24-
29+
2530
return hexColor;
2631
}
2732

@@ -31,12 +36,12 @@ export function darken(amount: number, color?: string, alphaValue?: number): str
3136
const actualColor = color || getCurrentThemeColor();
3237
const hsl = hexToHSL(actualColor);
3338
const hexColor = hslToHex(hsl.h, hsl.s, Math.max(0, hsl.l - amount));
34-
39+
3540
// 如果提供了透明度参数,应用透明度
3641
if (alphaValue !== undefined) {
3742
return alpha(alphaValue, hexColor);
3843
}
39-
44+
4045
return hexColor;
4146
}
4247

@@ -64,12 +69,12 @@ export function alpha(alphaValue: number, color?: string): string {
6469
const alpha = Math.max(0, Math.min(1, alphaValue));
6570

6671
// 移除#号并处理缩写形式
67-
let hex = actualColor.replace(/^#/, "");
72+
let hex = actualColor.replace(/^#/, '');
6873
if (hex.length === 3) {
6974
hex = hex
70-
.split("")
71-
.map((char) => char + char)
72-
.join("");
75+
.split('')
76+
.map(char => char + char)
77+
.join('');
7378
}
7479

7580
// 解析RGB值
@@ -90,12 +95,12 @@ interface HSL {
9095

9196
export function hexToHSL(hex: string): HSL {
9297
// 移除#号并处理缩写形式
93-
let hexValue = hex.replace(/^#/, "");
98+
let hexValue = hex.replace(/^#/, '');
9499
if (hexValue.length === 3) {
95100
hexValue = hexValue
96-
.split("")
97-
.map((char) => char + char)
98-
.join("");
101+
.split('')
102+
.map(char => char + char)
103+
.join('');
99104
}
100105

101106
// 解析RGB值
@@ -133,7 +138,7 @@ export function hexToHSL(hex: string): HSL {
133138
return {
134139
h: Math.round(h * 360),
135140
s: Math.round(s * 100),
136-
l: Math.round(l * 100),
141+
l: Math.round(l * 100)
137142
};
138143
}
139144

@@ -170,15 +175,15 @@ export function hslToHex(h: number, s: number, l: number): string {
170175
// 转换为十六进制
171176
const toHex = (x: number): string => {
172177
const hex = Math.round(x * 255).toString(16);
173-
return hex.length === 1 ? "0" + hex : hex;
178+
return hex.length === 1 ? '0' + hex : hex;
174179
};
175180

176181
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
177182
}
178183

179184
export const useTheme = () => {
180185
// 获取主题类型
181-
const getThemeType = () => localStorage.getItem("themeType") || "default";
186+
const getThemeType = () => localStorage.getItem('themeType') || 'default';
182187
const html = document.documentElement as HTMLElement;
183188

184189
// 通用设置主题的方法
@@ -190,13 +195,13 @@ export const useTheme = () => {
190195

191196
// 切换主题方法
192197
const switchTheme = (theme: string) => {
193-
localStorage.setItem("themeType", theme);
194-
if (theme === "darkBlue") {
195-
html.setAttribute("class", "darkBlue");
196-
} else if (theme === "deepBlue") {
197-
html.setAttribute("class", "deepBlue");
198+
localStorage.setItem('themeType', theme);
199+
if (theme === 'darkBlue') {
200+
html.setAttribute('class', 'darkBlue');
201+
} else if (theme === 'deepBlue') {
202+
html.setAttribute('class', 'deepBlue');
198203
} else {
199-
html.setAttribute("class", "");
204+
html.setAttribute('class', '');
200205
}
201206

202207
// 应用所有主题
@@ -213,6 +218,6 @@ export const useTheme = () => {
213218
return {
214219
initTheme,
215220
setMainTheme,
216-
switchTheme,
221+
switchTheme
217222
};
218223
};

0 commit comments

Comments
 (0)