Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(projects): support loading page dark mode adaptation. close #695 #702

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/constants/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ export const resetCacheStrategyRecord: Record<UnionKey.ResetCacheStrategy, App.I
};

export const resetCacheStrategyOptions = transformRecordToOption(resetCacheStrategyRecord);

export const DARK_CLASS = 'dark';
12 changes: 9 additions & 3 deletions src/plugins/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import { getRgb } from '@sa/color';
import { $t } from '@/locales';
import { localStg } from '@/utils/storage';
import systemLogo from '@/assets/svg-icon/logo.svg?raw';
import { DARK_CLASS } from '@/constants/app';
import { toggleHtmlClass } from '@/utils/common';

export function setupLoading() {
const themeColor = localStg.get('themeColor') || '#646cff';

const darkMode = localStg.get('darkMode') || false;
const { r, g, b } = getRgb(themeColor);

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

if (darkMode) {
toggleHtmlClass(DARK_CLASS).add();
}

const loadingClasses = [
'left-0 top-0',
'left-0 bottom-0 animate-delay-500',
Expand All @@ -27,14 +33,14 @@ export function setupLoading() {
.join('\n');

const loading = `
<div class="fixed-center flex-col" style="${primaryColor}">
<div class="fixed-center flex-col bg-layout" style="${primaryColor}">
${logoWithClass}
<div class="w-56px h-56px my-36px">
<div class="relative h-full animate-spin">
${dot}
</div>
</div>
<h2 class="text-28px font-500 text-#646464">${$t('system.title')}</h2>
<h2 class="text-28px font-500 text-primary">${$t('system.title')}</h2>
</div>`;

const app = document.getElementById('app');
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
darkMode,
val => {
toggleCssDarkMode(val);
localStg.set('darkMode', val);
},
{ immediate: true }
);
Expand Down
3 changes: 1 addition & 2 deletions src/store/modules/theme/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { overrideThemeSettings, themeSettings } from '@/theme/settings';
import { themeVars } from '@/theme/vars';
import { toggleHtmlClass } from '@/utils/common';
import { localStg } from '@/utils/storage';

const DARK_CLASS = 'dark';
import { DARK_CLASS } from '@/constants/app';

/** Init theme settings */
export function initThemeSettings() {
Expand Down
2 changes: 2 additions & 0 deletions src/typings/storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ declare namespace StorageType {
refreshToken: string;
/** The theme color */
themeColor: string;
/** The dark mode */
darkMode: boolean;
/** The theme settings */
themeSettings: App.Theme.ThemeSetting;
/**
Expand Down
Loading