Fix init theme failed error (#217)

This commit is contained in:
Germey authored and GitHub committed 2025-07-13 18:22:26 +08:00
1 parent 6edf940747
commit 37af52a3a2
5 files changed
+27

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix theme init failed issue",
"packageName": "@acedatacloud/nexior",
"email": "cqc@cuiqingcai.com",
"dependentChangeType": "patch"
}
+2
View File
@@ -14,6 +14,7 @@ import {
initializeCookies,
initializeDescription,
initializeFavicon,
initializeTheme,
initializeToken,
initializeUser,
initializeKeywords,
@@ -35,6 +36,7 @@ const main = async () => {
// non-async and no need to await
initializeCurrency();
initializeTheme();
initializeExchangeRate();
initializeTitle();
initializeDescription();
+1
View File
@@ -7,3 +7,4 @@ export * from './login';
export * from './site';
export * from './price';
export * from './application';
export * from './theme';
+10
View File
@@ -1,6 +1,7 @@
import { getCookie, setCookie } from 'typescript-cookie';
import favicon from '@/assets/images/favicon.ico';
import { getLocale } from '@/i18n';
import { applyTheme } from './theme';
import store from '@/store';
import { IToken } from '@/models';
import psl from 'psl';
@@ -165,6 +166,15 @@ export const initializeToken = async () => {
}
};
/**
* Initialize theme
*/
export const initializeTheme = async () => {
const theme = getCookie('THEME') || 'light';
console.debug('initialize theme', theme);
applyTheme(theme);
};
/**
* Initialize user by token
*/
+7
View File
@@ -0,0 +1,7 @@
export function applyTheme(theme: string) {
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}