mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 02:04:26 +08:00
support change theme
This commit is contained in:
@@ -15,6 +15,7 @@ import { useTokensStore } from '@/stores/token.js';
|
|||||||
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
|
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
|
||||||
|
|
||||||
import { loadMapAssets } from '@/lib/map/index.js';
|
import { loadMapAssets } from '@/lib/map/index.js';
|
||||||
|
import { getSystemTheme } from '@/lib/ui.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -36,8 +37,20 @@ export default {
|
|||||||
theme.global.name.value = 'light';
|
theme.global.name.value = 'light';
|
||||||
} else if (self.$settings.getTheme() === 'dark') {
|
} else if (self.$settings.getTheme() === 'dark') {
|
||||||
theme.global.name.value = 'dark';
|
theme.global.name.value = 'dark';
|
||||||
|
} else {
|
||||||
|
theme.global.name.value = getSystemTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function (e) {
|
||||||
|
if (self.$settings.getTheme() === 'auto') {
|
||||||
|
if (e.matches) {
|
||||||
|
theme.global.name.value = 'dark';
|
||||||
|
} else {
|
||||||
|
theme.global.name.value = 'light';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let localeDefaultSettings = self.$locale.initLocale(self.userStore.currentUserLanguage);
|
let localeDefaultSettings = self.$locale.initLocale(self.userStore.currentUserLanguage);
|
||||||
self.settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
self.settingsStore.updateLocalizedDefaultSettings(localeDefaultSettings);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export function getSystemTheme() {
|
||||||
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
|
return 'dark';
|
||||||
|
} else {
|
||||||
|
return 'light';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -96,6 +96,10 @@
|
|||||||
<h1 class="font-weight-medium text-xl">{{ $t('global.app.title') }}</h1>
|
<h1 class="font-weight-medium text-xl">{{ $t('global.app.title') }}</h1>
|
||||||
</div>
|
</div>
|
||||||
<v-spacer />
|
<v-spacer />
|
||||||
|
<v-btn color="primary" variant="text" class="me-2"
|
||||||
|
:icon="true" @click="(currentTheme === 'light' ? currentTheme = 'dark' : (currentTheme === 'dark' ? currentTheme = 'auto' : currentTheme = 'light'))">
|
||||||
|
<v-icon :icon="(currentTheme === 'light' ? icons.themeLight : (currentTheme === 'dark' ? icons.themeDark : icons.themeAuto))" size="24" />
|
||||||
|
</v-btn>
|
||||||
<v-avatar class="cursor-pointer" color="primary" variant="tonal">
|
<v-avatar class="cursor-pointer" color="primary" variant="tonal">
|
||||||
<v-icon :icon="icons.user"/>
|
<v-icon :icon="icons.user"/>
|
||||||
<v-menu activator="parent" width="230" location="bottom end" offset="14px">
|
<v-menu activator="parent" width="230" location="bottom end" offset="14px">
|
||||||
@@ -163,11 +167,15 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { useDisplay } from 'vuetify';
|
import { useDisplay } from 'vuetify';
|
||||||
|
import { useTheme } from 'vuetify';
|
||||||
|
|
||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
import { useRootStore } from '@/stores/index.js';
|
import { useRootStore } from '@/stores/index.js';
|
||||||
import { useSettingsStore } from '@/stores/setting.js';
|
import { useSettingsStore } from '@/stores/setting.js';
|
||||||
import { useUserStore } from '@/stores/user.js';
|
import { useUserStore } from '@/stores/user.js';
|
||||||
|
|
||||||
|
import { getSystemTheme } from '@/lib/ui.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mdiMenu,
|
mdiMenu,
|
||||||
mdiHomeOutline,
|
mdiHomeOutline,
|
||||||
@@ -179,6 +187,9 @@ import {
|
|||||||
mdiSwapHorizontal,
|
mdiSwapHorizontal,
|
||||||
mdiCogOutline,
|
mdiCogOutline,
|
||||||
mdiInformationOutline,
|
mdiInformationOutline,
|
||||||
|
mdiThemeLightDark,
|
||||||
|
mdiWeatherSunny,
|
||||||
|
mdiWeatherNight,
|
||||||
mdiAccount,
|
mdiAccount,
|
||||||
mdiAccountOutline,
|
mdiAccountOutline,
|
||||||
mdiLogout
|
mdiLogout
|
||||||
@@ -186,7 +197,10 @@ import {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
theme: self.$settings.getTheme(),
|
||||||
logouting: false,
|
logouting: false,
|
||||||
isVerticalNavScrolled: false,
|
isVerticalNavScrolled: false,
|
||||||
showVerticalOverlayMenu: false,
|
showVerticalOverlayMenu: false,
|
||||||
@@ -204,6 +218,9 @@ export default {
|
|||||||
exchangeRates: mdiSwapHorizontal,
|
exchangeRates: mdiSwapHorizontal,
|
||||||
settings: mdiCogOutline,
|
settings: mdiCogOutline,
|
||||||
about: mdiInformationOutline,
|
about: mdiInformationOutline,
|
||||||
|
themeAuto: mdiThemeLightDark,
|
||||||
|
themeLight: mdiWeatherSunny,
|
||||||
|
themeDark: mdiWeatherNight,
|
||||||
user: mdiAccount,
|
user: mdiAccount,
|
||||||
profile: mdiAccountOutline,
|
profile: mdiAccountOutline,
|
||||||
logout: mdiLogout
|
logout: mdiLogout
|
||||||
@@ -218,10 +235,31 @@ export default {
|
|||||||
},
|
},
|
||||||
currentNickName() {
|
currentNickName() {
|
||||||
return this.userStore.currentUserNickname || this.$t('User');
|
return this.userStore.currentUserNickname || this.$t('User');
|
||||||
|
},
|
||||||
|
currentTheme: {
|
||||||
|
get: function () {
|
||||||
|
return this.theme;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
if (value !== this.$settings.getTheme()) {
|
||||||
|
this.theme = value;
|
||||||
|
this.$settings.setTheme(value);
|
||||||
|
|
||||||
|
if (value === 'light' || value === 'dark') {
|
||||||
|
this.globalTheme.global.name.value = value;
|
||||||
|
} else {
|
||||||
|
this.globalTheme.global.name.value = getSystemTheme();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
setup () {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return {
|
||||||
|
globalTheme: theme
|
||||||
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleNavScroll(e) {
|
handleNavScroll(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user