Skip to content

Commit

Permalink
fix(projects): fix app loading theme color
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jan 17, 2024
1 parent 3b31b19 commit 1ad8dbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/components/common/app-loading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ const loadingClasses = [
'right-0 bottom-0 animate-delay-1500'
];
const style = addThemeColorCssVars();
function addThemeColorCssVars() {
const themeColor = localStg.get('themeColor') || '#646cff';
const { r, g, b } = getRgbOfColor(themeColor);
const cssVars = `--primary-color: ${r} ${g} ${b}`;
document.documentElement.style.cssText = cssVars;
}
addThemeColorCssVars();
return cssVars;
}
</script>

<template>
<div class="fixed-center flex-col">
<div class="fixed-center flex-col" :style="style">
<SystemLogo class="text-128px text-primary" />
<div class="w-56px h-56px my-36px">
<div class="relative h-full animate-spin">
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ export const useThemeStore = defineStore(SetupStoreId.Theme, () => {
{ immediate: true }
);

// themeColors change, update css vars
// themeColors change, update css vars and storage theme color
watch(
themeColors,
() => {
val => {
setupThemeVarsToHtml();

localStg.set('themeColor', val.primary);
},
{ immediate: true }
);
Expand Down

0 comments on commit 1ad8dbf

Please sign in to comment.