Add dark mode switch (#19)
This commit is contained in:
1 parent
3fc105ea84
commit
5d0a99b84d
9 files changed
+65
-33
No files matched your search
@@ -1,41 +1,52 @@
|
||||
<template>
|
||||
<dark-switch class="switch" dark-background="#333" light-background="#fff" />
|
||||
<el-button :class="{ active: !!dark }" @click="setDark(!dark)">
|
||||
<font-awesome-icon v-if="dark" icon="fa-solid fa-moon" />
|
||||
<font-awesome-icon v-else icon="fa-solid fa-moon" />
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { Switch as DarkSwitch, toggleDark, isDark } from 'vue-dark-switch';
|
||||
import { toggleDark } from 'vue-dark-switch';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ElButton } from 'element-plus';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
DarkSwitch
|
||||
FontAwesomeIcon,
|
||||
ElButton
|
||||
},
|
||||
emits: ['update:dark'],
|
||||
computed: {
|
||||
dark() {
|
||||
return this.$store.getters.dark;
|
||||
},
|
||||
switchValue() {
|
||||
return isDark.value;
|
||||
}
|
||||
// switchValue() {
|
||||
// return isDark.value;
|
||||
// }
|
||||
},
|
||||
watch: {
|
||||
switchValue(val) {
|
||||
console.log('switchValue', val);
|
||||
this.$store.dispatch('setDark', val);
|
||||
},
|
||||
dark(val) {
|
||||
document.documentElement.classList.toggle('dark', val);
|
||||
this.$store.dispatch('setDark', this.dark);
|
||||
this.setDark(val);
|
||||
}
|
||||
// switchValue(val) {
|
||||
// console.log('switchValue', val);
|
||||
// // this.$store.dispatch('setDark', val);
|
||||
// }
|
||||
},
|
||||
mounted() {
|
||||
if (this.dark) {
|
||||
toggleDark(true);
|
||||
document.documentElement.classList.add('dark');
|
||||
} else {
|
||||
toggleDark(false);
|
||||
document.documentElement.classList.remove('dark');
|
||||
console.log('mounted', this.dark);
|
||||
this.setDark(this.dark);
|
||||
},
|
||||
methods: {
|
||||
setDark(flag: boolean) {
|
||||
toggleDark(flag);
|
||||
this.$store.dispatch('setDark', flag);
|
||||
if (flag === true) {
|
||||
document.documentElement.classList.add('dark');
|
||||
} else if (flag === false) {
|
||||
document.documentElement.classList.remove('dark');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<div class="top">
|
||||
<div v-if="!collapsed">
|
||||
<logo @click="onHome" />
|
||||
<dark-selector v-show="false" />
|
||||
</div>
|
||||
<el-menu v-if="!collapsed" :default-active="activeIndex">
|
||||
<el-menu-item
|
||||
@@ -47,6 +46,11 @@
|
||||
</el-menu>
|
||||
</div>
|
||||
<div v-else class="bottom">
|
||||
<div v-if="$config.navigation?.darkMode" class="link">
|
||||
<el-tooltip effect="dark" :content="$t('common.nav.darkMode')" placement="right">
|
||||
<dark-selector class="button" />
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div v-if="$config.navigation?.locale" class="link">
|
||||
<el-tooltip effect="dark" :content="$t('common.nav.locale')" placement="right">
|
||||
<el-button class="button">
|
||||
@@ -84,6 +88,7 @@ import { defineComponent } from 'vue';
|
||||
import { ElButton, ElTooltip, ElMenu, ElMenuItem } from 'element-plus';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import LocaleSelector from './LocaleSelector.vue';
|
||||
import DarkSelector from './DarkSelector.vue';
|
||||
import {
|
||||
ROUTE_CHATDOC_INDEX,
|
||||
ROUTE_CHATDOC_CONVERSATION,
|
||||
@@ -98,7 +103,6 @@ import {
|
||||
ROUTE_MIDJOURNEY_INDEX
|
||||
} from '@/router/constants';
|
||||
import Chevron from './Chevron.vue';
|
||||
import DarkSelector from './DarkSelector.vue';
|
||||
import Logo from './Logo.vue';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -262,7 +266,7 @@ export default defineComponent({
|
||||
border-radius: 10px;
|
||||
border: none;
|
||||
color: var(--el-text-color-primary);
|
||||
background-color: var(--el-bg-color-overlay);
|
||||
background-color: var(--el-bg-color-page);
|
||||
&.active,
|
||||
&:hover,
|
||||
&:focus {
|
||||
|
||||
Reference in new issue
Block a user