From b3f722d8fff1c328594329909da650d9d494d735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E5=BA=86=E6=89=8D=E4=B8=A8=E9=9D=99=E8=A7=85?= Date: Sat, 11 May 2024 17:39:35 +0800 Subject: [PATCH] align locale theme across sites (#38) --- ...-949fa604-3730-4605-a6cc-506cd925fda6.json | 7 ++ src/components/common/DarkSelector.vue | 19 +++--- src/components/common/LocaleSelector.vue | 14 +++- src/i18n/index.ts | 4 +- src/main.ts | 64 ++++++++++--------- src/router/index.ts | 4 +- src/store/common/actions.ts | 10 --- src/store/common/getters.ts | 10 --- src/store/common/models.ts | 2 - src/store/common/mutations.ts | 10 --- src/store/common/state.ts | 7 +- src/utils/initializer.ts | 60 ++++++++++++++--- 12 files changed, 122 insertions(+), 89 deletions(-) create mode 100644 change/@acedatacloud-hub-949fa604-3730-4605-a6cc-506cd925fda6.json diff --git a/change/@acedatacloud-hub-949fa604-3730-4605-a6cc-506cd925fda6.json b/change/@acedatacloud-hub-949fa604-3730-4605-a6cc-506cd925fda6.json new file mode 100644 index 00000000..a5ca9ce3 --- /dev/null +++ b/change/@acedatacloud-hub-949fa604-3730-4605-a6cc-506cd925fda6.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "align across site for theme and locale", + "packageName": "@acedatacloud/hub", + "email": "cqc@cuiqingcai.com", + "dependentChangeType": "patch" +} diff --git a/src/components/common/DarkSelector.vue b/src/components/common/DarkSelector.vue index a7a5b10b..25195595 100644 --- a/src/components/common/DarkSelector.vue +++ b/src/components/common/DarkSelector.vue @@ -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() + }); } } }); diff --git a/src/components/common/LocaleSelector.vue b/src/components/common/LocaleSelector.vue index e6e44e95..501e58d6 100644 --- a/src/components/common/LocaleSelector.vue +++ b/src/components/common/LocaleSelector.vue @@ -22,8 +22,10 @@