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

fix: Login页面主题设置不生效 #371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions arco-design-pro-vite/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import zhCN from '@arco-design/web-vue/es/locale/lang/zh-cn';
import GlobalSetting from '@/components/global-setting/index.vue';
import useLocale from '@/hooks/locale';
import useThemes from '@/hooks/themes';

const { currentLocale } = useLocale();
const locale = computed(() => {
Expand All @@ -23,4 +24,6 @@
return enUS;
}
});

useThemes();
</script>
17 changes: 4 additions & 13 deletions arco-design-pro-vite/src/components/navbar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,12 @@
<script lang="ts" setup>
import { computed, ref, inject } from 'vue';
import { Message } from '@arco-design/web-vue';
import { useDark, useToggle, useFullscreen } from '@vueuse/core';
import { useFullscreen } from '@vueuse/core';
import { useAppStore, useUserStore } from '@/store';
import { LOCALE_OPTIONS } from '@/locale';
import useLocale from '@/hooks/locale';
import useUser from '@/hooks/user';
import useThemes from '@/hooks/themes';
import Menu from '@/components/menu/index.vue';
import MessageBox from '../message-box/index.vue';

Expand All @@ -216,18 +217,8 @@
return appStore.theme;
});
const topMenu = computed(() => appStore.topMenu && appStore.menu);
const isDark = useDark({
selector: 'body',
attribute: 'arco-theme',
valueDark: 'dark',
valueLight: 'light',
storageKey: 'arco-theme',
onChanged(dark: boolean) {
// overridden default behavior
appStore.toggleTheme(dark);
},
});
const toggleTheme = useToggle(isDark);

const { toggleTheme } = useThemes();
const handleToggleTheme = () => {
toggleTheme();
};
Expand Down
18 changes: 16 additions & 2 deletions arco-design-pro-vite/src/hooks/themes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import { computed } from 'vue';
import { useAppStore } from '@/store';
import { useDark, useToggle } from '@vueuse/core';

export default function useThemes() {
const appStore = useAppStore();
const isDark = computed(() => {
return appStore.theme === 'dark';

const isDark = useDark({
selector: 'body',
attribute: 'arco-theme',
valueDark: 'dark',
valueLight: 'light',
storageKey: 'arco-theme',
onChanged(dark: boolean) {
// overridden default behavior
appStore.toggleTheme(dark);
},
});

const toggleTheme = useToggle(isDark);

return {
isDark,
toggleTheme,
};
}