Skip to content

Commit 5ba7182

Browse files
committed
feat(module:theme): add grey theme mode
1 parent 2e2d8e6 commit 5ba7182

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

src/app/core/services/store/common-store/theme.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface SettingInterface {
66
color: string; // 主题色
77
mode: 'side' | 'top' | 'mixi'; // 菜单模式(侧边模式,顶部模式,混合模式)
88
colorWeak: boolean; // 色弱
9+
greyTheme: boolean; // 灰色模式
910
fixedHead: boolean; // 固定头部
1011
splitNav: boolean; // 是否分割菜单(在菜单模式为混合模式时才生效)
1112
fixedLeftNav: boolean; // 固定左侧菜单
@@ -27,6 +28,7 @@ export class ThemeService {
2728
color: '#1890FF',
2829
mode: 'side',
2930
colorWeak: false,
31+
greyTheme: false,
3032
splitNav: false,
3133
fixedTab: true,
3234
fixedHead: true,

src/app/layout/default/def-layout-content/def-layout-content.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class DefLayoutContentComponent implements OnInit {
2525
splitNav: false,
2626
fixedTab: false,
2727
colorWeak: false,
28+
greyTheme: false,
2829
fixedHead: false,
2930
fixedLeftNav: false,
3031
hasTopArea: true,

src/app/layout/default/setting-drawer/setting-drawer.component.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ <h3 class="title">其他设置</h3>
113113
<nz-list [nzSplit]="false">
114114
<nz-list-item [nzActions]="[otherAction]">色弱模式</nz-list-item>
115115
<ng-template #otherAction>
116-
<nz-switch (ngModelChange)="changeWeakMode($event)" [ngModel]="_themesOptions.colorWeak" nzSize="small"></nz-switch>
116+
<nz-switch (ngModelChange)="changeSpecialTheme($event, 'color-weak')" [ngModel]="_themesOptions.colorWeak" nzSize="small"></nz-switch>
117+
</ng-template>
118+
</nz-list>
119+
<nz-list [nzSplit]="false">
120+
<nz-list-item [nzActions]="[greyAction]">灰色模式</nz-list-item>
121+
<ng-template #greyAction>
122+
<nz-switch (ngModelChange)="changeSpecialTheme($event, 'grey-theme')" [ngModel]="_themesOptions.greyTheme" nzSize="small"></nz-switch>
117123
</ng-template>
118124
</nz-list>
119125
</div>

src/app/layout/default/setting-drawer/setting-drawer.component.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IsNightKey, ThemeOptionsKey } from '@config/constant';
66
import { ThemeSkinService } from '@core/services/common/theme-skin.service';
77
import { WindowService } from '@core/services/common/window.service';
88
import { SettingInterface, ThemeService } from '@store/common-store/theme.service';
9+
import { fnFormatToHump } from '@utils/tools';
910
import { NzConfigService } from 'ng-zorro-antd/core/config';
1011
import { NzMessageService } from 'ng-zorro-antd/message';
1112

@@ -19,6 +20,9 @@ interface Theme extends NormalModel {
1920
key: 'dark' | 'light';
2021
}
2122

23+
type SpecialTheme = 'color-weak' | 'grey-theme';
24+
type SpecialThemeHump = 'colorWeak' | 'greyTheme';
25+
2226
interface Color extends NormalModel {
2327
key: string;
2428
color: string;
@@ -44,6 +48,7 @@ export class SettingDrawerComponent implements OnInit {
4448
mode: 'side',
4549
fixedTab: false,
4650
splitNav: true,
51+
greyTheme: false,
4752
colorWeak: false,
4853
fixedLeftNav: true,
4954
fixedHead: true,
@@ -208,15 +213,16 @@ export class SettingDrawerComponent implements OnInit {
208213
this.setThemeOptions();
209214
}
210215

211-
// 修改色弱模式
212-
changeWeakMode(e: boolean): void {
216+
// 修改特殊主题,色弱主题,灰色主题
217+
changeSpecialTheme(e: boolean, themeType: SpecialTheme): void {
213218
const name = this.doc.getElementsByTagName('html');
219+
const theme = fnFormatToHump(themeType);
214220
if (e) {
215-
this.rd2.addClass(name[0], 'color-weak');
221+
this.rd2.addClass(name[0], themeType);
216222
} else {
217-
this.rd2.removeClass(name[0], 'color-weak');
223+
this.rd2.removeClass(name[0], themeType);
218224
}
219-
this._themesOptions.colorWeak = e;
225+
this._themesOptions[theme as SpecialThemeHump] = e;
220226
this.setThemeOptions();
221227
}
222228

@@ -225,7 +231,13 @@ export class SettingDrawerComponent implements OnInit {
225231
this.themesOptions$.pipe(first()).subscribe(res => {
226232
this._themesOptions = res;
227233
});
228-
this.changeWeakMode(this._themesOptions.colorWeak);
234+
235+
// 特殊模式主题变换(色弱模式,灰色模式)
236+
(['grey-theme', 'color-weak'] as SpecialTheme[]).forEach(item => {
237+
const specialTheme = fnFormatToHump(item);
238+
this.changeSpecialTheme(this._themesOptions[specialTheme as SpecialThemeHump], item);
239+
});
240+
229241
this.modes.forEach(item => {
230242
item.isChecked = item.key === this._themesOptions.mode;
231243
});

src/app/utils/tools.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ const fnEndOfDay = function EndOfDay(time: number): number {
138138
return endOfDay(time).getTime();
139139
};
140140

141+
// weak-theme 转换为 weakTheme
142+
// https://blog.csdn.net/weixin_39238200/article/details/125665052
143+
const fnFormatToHump = function formatToHump(value: string): string {
144+
return value.replace(/\-(\w)/g, (_, letter) => letter.toUpperCase());
145+
};
146+
141147
export {
148+
fnFormatToHump,
142149
fnGetReuseStrategyKeyFn,
143150
fnDecrypt,
144151
fnEncrypt,

src/styles/themes/base.less

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,19 @@ h1, h2, h3, h4, h5, h6 {
101101
visibility: hidden;
102102
}
103103

104+
.grey-theme{
105+
-webkit-filter: grayscale(100%);
106+
-moz-filter: grayscale(100%);
107+
-ms-filter: grayscale(100%);
108+
-o-filter: grayscale(100%);
109+
filter: grayscale(100%);
110+
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
111+
}
112+
104113
.color-weak {
105114
filter: invert(80%) !important;
106115
}
107116

108-
109117
.wrap {
110118
width: 980px;
111119
margin: 0 auto;

0 commit comments

Comments
 (0)