fix: 🐛 主题设置登录页和首页不一致问题修复

Former-commit-id: fbd82fa91166dbeb1203d24abc1e2ae799867c94
This commit is contained in:
郝先瑞
2023-11-03 14:29:03 +08:00
parent 2798c16a1a
commit 56d4cdcac2
3 changed files with 28 additions and 10 deletions

View File

@@ -79,11 +79,8 @@ const currentThemeColor = computed(() => {
}); });
onMounted(() => { onMounted(() => {
window.document.body.setAttribute("layout", settingsStore.layout); window.document.body.setAttribute("layout", settingsStore.layout);
const theme = const theme = settingsStore.theme;
localStorage.getItem("vueuse-color-scheme") || defaultSettings.theme; if (theme == "dark") {
settingsStore.changeSetting({ key: "theme", value: theme });
if (theme != "light") {
document.documentElement.classList.add("dark"); document.documentElement.classList.add("dark");
} }

View File

@@ -20,9 +20,7 @@ export const useSettingsStore = defineStore("setting", () => {
); );
const theme = useStorage<string>("theme", defaultSettings.theme); const theme = useStorage<string>("theme", defaultSettings.theme);
if (theme.value == "light") {
document.body.classList.remove("dark");
}
// actions // actions
function changeSetting(param: { key: string; value: any }) { function changeSetting(param: { key: string; value: any }) {
const { key, value } = param; const { key, value } = param;
@@ -47,6 +45,9 @@ export const useSettingsStore = defineStore("setting", () => {
break; break;
case "theme": case "theme":
theme.value = value; theme.value = value;
if (theme.value !== "dark") {
document.documentElement.classList.remove("dark");
}
break; break;
} }
} }

View File

@@ -9,7 +9,7 @@
:inactive-icon="IconEpSunny" :inactive-icon="IconEpSunny"
active-color="var(--el-fill-color-dark)" active-color="var(--el-fill-color-dark)"
inactive-color="var(--el-color-primary)" inactive-color="var(--el-color-primary)"
@change="toggleDark" @change="handleThemeChange"
/> />
<lang-select class="ml-4 cursor-pointer" /> <lang-select class="ml-4 cursor-pointer" />
</div> </div>
@@ -104,7 +104,7 @@
</el-card> </el-card>
<!-- ICP备案 --> <!-- ICP备案 -->
<div class="absolute bottom-1 text-[6px] text-center"> <div class="absolute bottom-1 text-[10px] text-center">
<p> <p>
Copyright © 2021 - 2023 youlai.tech All Rights Reserved. 有来技术 Copyright © 2021 - 2023 youlai.tech All Rights Reserved. 有来技术
版权所有 版权所有
@@ -121,6 +121,7 @@ import LangSelect from "@/components/LangSelect/index.vue";
import SvgIcon from "@/components/SvgIcon/index.vue"; import SvgIcon from "@/components/SvgIcon/index.vue";
import IconEpSunny from "~icons/ep/sunny"; import IconEpSunny from "~icons/ep/sunny";
import IconEpMoon from "~icons/ep/moon"; import IconEpMoon from "~icons/ep/moon";
import { useSettingsStore } from "@/store/modules/settings";
// 状态管理依赖 // 状态管理依赖
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from "@/store/modules/user";
@@ -138,6 +139,14 @@ const route = useRoute();
const isDark = useDark(); const isDark = useDark();
const toggleDark = () => useToggle(isDark); const toggleDark = () => useToggle(isDark);
function handleThemeChange() {
toggleDark();
useSettingsStore().changeSetting({
key: "theme",
value: isDark.value ? "dark" : "light",
});
}
/** /**
* 按钮loading * 按钮loading
*/ */
@@ -264,6 +273,16 @@ function handleLogin() {
onMounted(() => { onMounted(() => {
getCaptcha(); getCaptcha();
// 主题初始化
const theme = useSettingsStore().theme;
console.log("登录页面主题", theme);
useSettingsStore().changeSetting({ key: "theme", value: theme });
if (theme == "dark") {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
}); });
</script> </script>
@@ -275,6 +294,7 @@ onMounted(() => {
.login-container { .login-container {
@apply w-full h-full flex-center; @apply w-full h-full flex-center;
overflow-y: auto;
background: url("@/assets/images/login-bg.jpg") no-repeat center right; background: url("@/assets/images/login-bg.jpg") no-repeat center right;
.login-form { .login-form {