Skip to content

Commit 9b9455d

Browse files
authored
feat(projects): support loading page dark mode adaptation. (#702)
1 parent 86da767 commit 9b9455d

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/constants/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ export const resetCacheStrategyRecord: Record<UnionKey.ResetCacheStrategy, App.I
6161
};
6262

6363
export const resetCacheStrategyOptions = transformRecordToOption(resetCacheStrategyRecord);
64+
65+
export const DARK_CLASS = 'dark';

src/plugins/loading.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ import { getRgb } from '@sa/color';
33
import { $t } from '@/locales';
44
import { localStg } from '@/utils/storage';
55
import systemLogo from '@/assets/svg-icon/logo.svg?raw';
6+
import { DARK_CLASS } from '@/constants/app';
7+
import { toggleHtmlClass } from '@/utils/common';
68

79
export function setupLoading() {
810
const themeColor = localStg.get('themeColor') || '#646cff';
9-
11+
const darkMode = localStg.get('darkMode') || false;
1012
const { r, g, b } = getRgb(themeColor);
1113

1214
const primaryColor = `--primary-color: ${r} ${g} ${b}`;
1315

16+
if (darkMode) {
17+
toggleHtmlClass(DARK_CLASS).add();
18+
}
19+
1420
const loadingClasses = [
1521
'left-0 top-0',
1622
'left-0 bottom-0 animate-delay-500',
@@ -27,14 +33,14 @@ export function setupLoading() {
2733
.join('\n');
2834

2935
const loading = `
30-
<div class="fixed-center flex-col" style="${primaryColor}">
36+
<div class="fixed-center flex-col bg-layout" style="${primaryColor}">
3137
${logoWithClass}
3238
<div class="w-56px h-56px my-36px">
3339
<div class="relative h-full animate-spin">
3440
${dot}
3541
</div>
3642
</div>
37-
<h2 class="text-28px font-500 text-#646464">${$t('system.title')}</h2>
43+
<h2 class="text-28px font-500 text-primary">${$t('system.title')}</h2>
3844
</div>`;
3945

4046
const app = document.getElementById('app');

src/store/modules/theme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
174174
darkMode,
175175
val => {
176176
toggleCssDarkMode(val);
177+
localStg.set('darkMode', val);
177178
},
178179
{ immediate: true }
179180
);

src/store/modules/theme/shared.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { overrideThemeSettings, themeSettings } from '@/theme/settings';
55
import { themeVars } from '@/theme/vars';
66
import { toggleHtmlClass } from '@/utils/common';
77
import { localStg } from '@/utils/storage';
8-
9-
const DARK_CLASS = 'dark';
8+
import { DARK_CLASS } from '@/constants/app';
109

1110
/** Init theme settings */
1211
export function initThemeSettings() {

src/typings/storage.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ declare namespace StorageType {
2020
refreshToken: string;
2121
/** The theme color */
2222
themeColor: string;
23+
/** The dark mode */
24+
darkMode: boolean;
2325
/** The theme settings */
2426
themeSettings: App.Theme.ThemeSetting;
2527
/**

0 commit comments

Comments
 (0)