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
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "minor",
|
||||||
|
"comment": "add dark mode switch",
|
||||||
|
"packageName": "@acedatacloud/hub",
|
||||||
|
"email": "cqc@cuiqingcai.com",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -1,41 +1,52 @@
|
|||||||
<template>
|
<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>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
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({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
DarkSwitch
|
FontAwesomeIcon,
|
||||||
|
ElButton
|
||||||
},
|
},
|
||||||
emits: ['update:dark'],
|
emits: ['update:dark'],
|
||||||
computed: {
|
computed: {
|
||||||
dark() {
|
dark() {
|
||||||
return this.$store.getters.dark;
|
return this.$store.getters.dark;
|
||||||
},
|
|
||||||
switchValue() {
|
|
||||||
return isDark.value;
|
|
||||||
}
|
}
|
||||||
|
// switchValue() {
|
||||||
|
// return isDark.value;
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
switchValue(val) {
|
|
||||||
console.log('switchValue', val);
|
|
||||||
this.$store.dispatch('setDark', val);
|
|
||||||
},
|
|
||||||
dark(val) {
|
dark(val) {
|
||||||
document.documentElement.classList.toggle('dark', val);
|
this.setDark(val);
|
||||||
this.$store.dispatch('setDark', this.dark);
|
|
||||||
}
|
}
|
||||||
|
// switchValue(val) {
|
||||||
|
// console.log('switchValue', val);
|
||||||
|
// // this.$store.dispatch('setDark', val);
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.dark) {
|
console.log('mounted', this.dark);
|
||||||
toggleDark(true);
|
this.setDark(this.dark);
|
||||||
document.documentElement.classList.add('dark');
|
},
|
||||||
} else {
|
methods: {
|
||||||
toggleDark(false);
|
setDark(flag: boolean) {
|
||||||
document.documentElement.classList.remove('dark');
|
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 class="top">
|
||||||
<div v-if="!collapsed">
|
<div v-if="!collapsed">
|
||||||
<logo @click="onHome" />
|
<logo @click="onHome" />
|
||||||
<dark-selector v-show="false" />
|
|
||||||
</div>
|
</div>
|
||||||
<el-menu v-if="!collapsed" :default-active="activeIndex">
|
<el-menu v-if="!collapsed" :default-active="activeIndex">
|
||||||
<el-menu-item
|
<el-menu-item
|
||||||
@@ -47,6 +46,11 @@
|
|||||||
</el-menu>
|
</el-menu>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="bottom">
|
<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">
|
<div v-if="$config.navigation?.locale" class="link">
|
||||||
<el-tooltip effect="dark" :content="$t('common.nav.locale')" placement="right">
|
<el-tooltip effect="dark" :content="$t('common.nav.locale')" placement="right">
|
||||||
<el-button class="button">
|
<el-button class="button">
|
||||||
@@ -84,6 +88,7 @@ import { defineComponent } from 'vue';
|
|||||||
import { ElButton, ElTooltip, ElMenu, ElMenuItem } from 'element-plus';
|
import { ElButton, ElTooltip, ElMenu, ElMenuItem } from 'element-plus';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
import LocaleSelector from './LocaleSelector.vue';
|
import LocaleSelector from './LocaleSelector.vue';
|
||||||
|
import DarkSelector from './DarkSelector.vue';
|
||||||
import {
|
import {
|
||||||
ROUTE_CHATDOC_INDEX,
|
ROUTE_CHATDOC_INDEX,
|
||||||
ROUTE_CHATDOC_CONVERSATION,
|
ROUTE_CHATDOC_CONVERSATION,
|
||||||
@@ -98,7 +103,6 @@ import {
|
|||||||
ROUTE_MIDJOURNEY_INDEX
|
ROUTE_MIDJOURNEY_INDEX
|
||||||
} from '@/router/constants';
|
} from '@/router/constants';
|
||||||
import Chevron from './Chevron.vue';
|
import Chevron from './Chevron.vue';
|
||||||
import DarkSelector from './DarkSelector.vue';
|
|
||||||
import Logo from './Logo.vue';
|
import Logo from './Logo.vue';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -262,7 +266,7 @@ export default defineComponent({
|
|||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
border: none;
|
border: none;
|
||||||
color: var(--el-text-color-primary);
|
color: var(--el-text-color-primary);
|
||||||
background-color: var(--el-bg-color-overlay);
|
background-color: var(--el-bg-color-page);
|
||||||
&.active,
|
&.active,
|
||||||
&:hover,
|
&:hover,
|
||||||
&:focus {
|
&:focus {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
<div class="extra">
|
<div class="extra">
|
||||||
<p v-if="modelValue?.created_at" class="datetime">
|
<p v-if="modelValue?.created_at" class="datetime">
|
||||||
<font-awesome-icon icon="fa-regular fa-clock" class="mr-1" />
|
<font-awesome-icon icon="fa-regular fa-clock" class="mr-1" />
|
||||||
{{ $dayjs.format(new Date(parseFloat(modelValue?.created_at) * 1000)) }}
|
{{ $dayjs.format('' + new Date(parseFloat(modelValue?.created_at) * 1000)) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -337,8 +337,7 @@ export default defineComponent({
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: var(--el-fill-color-light);
|
background: var(--el-fill-color-light);
|
||||||
color: var(--el-text-color-secondary);
|
color: var(--el-text-color-regular);
|
||||||
// font-size: 30px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.progress {
|
.progress {
|
||||||
@@ -362,7 +361,7 @@ export default defineComponent({
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #666;
|
color: var(--el-text-color-regular);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
|
||||||
@@ -380,7 +379,7 @@ export default defineComponent({
|
|||||||
.datetime,
|
.datetime,
|
||||||
.prompt {
|
.prompt {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #666;
|
color: var(--el-text-color-regular);
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ export default {
|
|||||||
*/
|
*/
|
||||||
locale: true,
|
locale: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show dark entry in left navigation.
|
||||||
|
*/
|
||||||
|
darkMode: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show console entry in left navigation.
|
* Show console entry in left navigation.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -241,7 +241,7 @@
|
|||||||
},
|
},
|
||||||
"nav.chat": {
|
"nav.chat": {
|
||||||
"message": "Chat",
|
"message": "Chat",
|
||||||
"description": "The text in nav bar of the website, which is used to show the chat page"
|
"description": "The text in nav bar of the website, which is used to show the chat page, please do not translate 'Chat', keep it as 'Chat'"
|
||||||
},
|
},
|
||||||
"nav.midjourney": {
|
"nav.midjourney": {
|
||||||
"message": "Midjourney",
|
"message": "Midjourney",
|
||||||
@@ -249,7 +249,7 @@
|
|||||||
},
|
},
|
||||||
"nav.chatdoc": {
|
"nav.chatdoc": {
|
||||||
"message": "Chatdoc",
|
"message": "Chatdoc",
|
||||||
"description": "The text in nav bar of the website, which is used to show the chatdoc page"
|
"description": "The text in nav bar of the website, which is used to show the chatdoc page, please do not translate 'Chatdoc', keep it as 'Chatdoc'"
|
||||||
},
|
},
|
||||||
"nav.distribution": {
|
"nav.distribution": {
|
||||||
"message": "Referral Earnings",
|
"message": "Referral Earnings",
|
||||||
@@ -263,6 +263,10 @@
|
|||||||
"message": "Language",
|
"message": "Language",
|
||||||
"description": "The text in nav bar of the website, which is used to change the language"
|
"description": "The text in nav bar of the website, which is used to change the language"
|
||||||
},
|
},
|
||||||
|
"nav.darkMode": {
|
||||||
|
"message": "Dark Mode",
|
||||||
|
"description": "The text in nav bar of the website, which is used to change the theme to dark mode"
|
||||||
|
},
|
||||||
"title.alert": {
|
"title.alert": {
|
||||||
"message": "Alert",
|
"message": "Alert",
|
||||||
"description": "The title of the alert message"
|
"description": "The title of the alert message"
|
||||||
@@ -311,4 +315,4 @@
|
|||||||
"message": "Credentials",
|
"message": "Credentials",
|
||||||
"description": "The title of the page to show all credentials, the credentials are used to access the API"
|
"description": "The title of the page to show all credentials, the credentials are used to access the API"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,7 +376,7 @@ export default defineComponent({
|
|||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
color: #333;
|
color: var(--el-text-color-primary);
|
||||||
}
|
}
|
||||||
.icon {
|
.icon {
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
@@ -385,7 +385,7 @@ export default defineComponent({
|
|||||||
padding: 15px 0;
|
padding: 15px 0;
|
||||||
p {
|
p {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #999;
|
color: var(--el-text-color-regular);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -402,7 +402,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
.description {
|
.description {
|
||||||
color: #999;
|
color: var(--el-text-color-regular);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
.more {
|
.more {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
} from '@fortawesome/free-regular-svg-icons';
|
} from '@fortawesome/free-regular-svg-icons';
|
||||||
import {
|
import {
|
||||||
faChevronRight as faSolidChevronRight,
|
faChevronRight as faSolidChevronRight,
|
||||||
|
faMoon as faSolidMoon,
|
||||||
faChevronLeft as faSolidChevronLeft,
|
faChevronLeft as faSolidChevronLeft,
|
||||||
faFire as faSolidFire,
|
faFire as faSolidFire,
|
||||||
faBook as faSolidBook,
|
faBook as faSolidBook,
|
||||||
@@ -71,6 +72,7 @@ library.add(faSolidCheck);
|
|||||||
library.add(faSolidLocationArrow);
|
library.add(faSolidLocationArrow);
|
||||||
library.add(faRegularUser);
|
library.add(faRegularUser);
|
||||||
library.add(faRegularSun);
|
library.add(faRegularSun);
|
||||||
|
library.add(faSolidMoon);
|
||||||
library.add(faSolidBolt);
|
library.add(faSolidBolt);
|
||||||
library.add(faSolidBook);
|
library.add(faSolidBook);
|
||||||
library.add(faSolidGear);
|
library.add(faSolidGear);
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export default ['user', 'token', 'setting', 'locale'];
|
export default ['user', 'token', 'setting', 'locale', 'dark'];
|
||||||
Reference in new issue
Block a user