align locale theme across sites (#38)
This commit is contained in:
1 parent
9b8db40440
commit
266f2e8bb2
12 files changed
+124
-91
No files matched your search
@@ -10,6 +10,8 @@ import { defineComponent } from 'vue';
|
||||
import { toggleDark } from 'vue-dark-switch';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ElButton } from 'element-plus';
|
||||
import { getCookie, setCookie } from 'typescript-cookie';
|
||||
import { getDomain } from '@/utils/initializer';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -19,20 +21,13 @@ export default defineComponent({
|
||||
emits: ['update:dark'],
|
||||
computed: {
|
||||
dark() {
|
||||
return this.$store.getters.dark;
|
||||
return getCookie('THEME') === 'dark';
|
||||
}
|
||||
// switchValue() {
|
||||
// return isDark.value;
|
||||
// }
|
||||
},
|
||||
watch: {
|
||||
dark(val) {
|
||||
this.setDark(val);
|
||||
}
|
||||
// switchValue(val) {
|
||||
// console.log('switchValue', val);
|
||||
// // this.$store.dispatch('setDark', val);
|
||||
// }
|
||||
},
|
||||
mounted() {
|
||||
console.log('mounted', this.dark);
|
||||
@@ -41,12 +36,18 @@ export default defineComponent({
|
||||
methods: {
|
||||
setDark(flag: boolean) {
|
||||
toggleDark(flag);
|
||||
this.$store.dispatch('setDark', flag);
|
||||
this.setCookie(flag);
|
||||
if (flag === true) {
|
||||
document.documentElement.classList.add('dark');
|
||||
} else if (flag === false) {
|
||||
document.documentElement.classList.remove('dark');
|
||||
}
|
||||
},
|
||||
setCookie(isDark: boolean) {
|
||||
setCookie('THEME', isDark ? 'dark' : 'light', {
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElDropdown, ElDropdownItem, ElDropdownMenu, ElButton } from 'element-plus';
|
||||
import { ElDropdown, ElDropdownItem, ElDropdownMenu } from 'element-plus';
|
||||
import { SUPPORTED_LOCALES, setI18nLanguage } from '@/i18n';
|
||||
import { setCookie } from 'typescript-cookie';
|
||||
import { getDomain } from '@/utils/initializer';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'LocaleSelector',
|
||||
@@ -39,9 +41,17 @@ export default defineComponent({
|
||||
},
|
||||
methods: {
|
||||
async onSelectLocale(locale: string) {
|
||||
// change router
|
||||
this.$router.push({ query: { ...this.$route.query, locale: undefined } });
|
||||
await setI18nLanguage(locale);
|
||||
this.$store.dispatch('setLocale', locale);
|
||||
this.setCookie(locale);
|
||||
window.location.reload();
|
||||
},
|
||||
setCookie(locale: string) {
|
||||
setCookie('LOCALE', locale, {
|
||||
path: '/',
|
||||
domain: getDomain()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user