国际化、主题处理

This commit is contained in:
Gary Fu
2023-12-17 15:11:38 +08:00
parent 99629bc0a5
commit 45ccfddba5
8 changed files with 37 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { useGlobalConfigStore } from '@/stores/globalConfig' import { useGlobalConfigStore } from '@/stores/globalConfigStore'
import { $changeLocale, elementLocale } from '@/languages/MessagesConfig' import { $changeLocale, elementLocale } from '@/languages/MessagesConfig'
const globalConfigStore = useGlobalConfigStore() const globalConfigStore = useGlobalConfigStore()

View File

@@ -1,22 +1,16 @@
<script setup> <script setup>
import { ref } from 'vue'
import { useDark } from '@vueuse/core'
import { Check } from '@element-plus/icons-vue' import { Check } from '@element-plus/icons-vue'
import { useGlobalConfigStore } from '@/stores/globalConfig' import { useGlobalConfigStore } from '@/stores/globalConfigStore'
const globalConfigStore = useGlobalConfigStore() const globalConfigStore = useGlobalConfigStore()
const isCollapseLeft = ref(false)
const emit = defineEmits(['update:collapseLeft']) const emit = defineEmits(['update:collapseLeft'])
const updateCollapseLeft = () => { const updateCollapseLeft = () => {
isCollapseLeft.value = !isCollapseLeft.value globalConfigStore.collapseLeft()
emit('update:collapseLeft', isCollapseLeft.value) emit('update:collapseLeft', globalConfigStore.isCollapseLeft)
} }
const isDark = useDark()
defineProps({ defineProps({
collapseLeft: { collapseLeft: {
type: Boolean type: Boolean
@@ -30,10 +24,10 @@ defineProps({
> >
<el-menu-item @click="updateCollapseLeft"> <el-menu-item @click="updateCollapseLeft">
<template #title> <template #title>
<el-icon v-if="!isCollapseLeft"> <el-icon v-if="!globalConfigStore.isCollapseLeft">
<Fold /> <Fold />
</el-icon> </el-icon>
<el-icon v-if="isCollapseLeft"> <el-icon v-if="globalConfigStore.isCollapseLeft">
<Expand /> <Expand />
</el-icon> </el-icon>
<span>&nbsp;</span> <span>&nbsp;</span>
@@ -69,18 +63,18 @@ defineProps({
</template> </template>
<el-menu-item <el-menu-item
index="2-1" index="2-1"
@click="isDark=false" @click="globalConfigStore.changeTheme(false)"
> >
<el-icon v-if="!isDark"> <el-icon v-if="!globalConfigStore.isDarkTheme">
<Check /> <Check />
</el-icon> </el-icon>
{{ $t('common.label.themeDefault') }} {{ $t('common.label.themeDefault') }}
</el-menu-item> </el-menu-item>
<el-menu-item <el-menu-item
index="2-2" index="2-2"
@click="isDark=true" @click="globalConfigStore.changeTheme(true)"
> >
<el-icon v-if="isDark"> <el-icon v-if="globalConfigStore.isDarkTheme">
<Check /> <Check />
</el-icon> </el-icon>
{{ $t('common.label.themeDark') }} {{ $t('common.label.themeDark') }}

View File

@@ -6,7 +6,7 @@ import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import en from 'element-plus/dist/locale/en.mjs' import en from 'element-plus/dist/locale/en.mjs'
import 'dayjs/locale/zh-cn' import 'dayjs/locale/zh-cn'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { useGlobalConfigStore } from '@/stores/globalConfig' import { useGlobalConfigStore } from '@/stores/globalConfigStore'
const DEFAULT_LOCALE = 'zh-CN' const DEFAULT_LOCALE = 'zh-CN'
dayjs.locale(DEFAULT_LOCALE) // dayjs的语言配置 dayjs.locale(DEFAULT_LOCALE) // dayjs的语言配置

View File

@@ -9,7 +9,6 @@ export default {
theme: '主题', theme: '主题',
themeDefault: '默认', themeDefault: '默认',
themeDark: '黑色', themeDark: '黑色',
themePurple: '紫色',
personalCenter: '个人中心', personalCenter: '个人中心',
personalInfo: '个人资料', personalInfo: '个人资料',
about: '关于', about: '关于',

View File

@@ -9,7 +9,6 @@ export default {
theme: 'Themes', theme: 'Themes',
themeDefault: 'default', themeDefault: 'default',
themeDark: 'dark', themeDark: 'dark',
themePurple: 'purple',
personalCenter: 'Personal Center', personalCenter: 'Personal Center',
personalInfo: 'Personal Info', personalInfo: 'Personal Info',
about: 'About', about: 'About',

View File

@@ -1,6 +1,6 @@
import { defineStore, createPinia } from 'pinia' import { defineStore, createPinia } from 'pinia'
import piniaPluginPersistedState from 'pinia-plugin-persistedstate' import piniaPluginPersistedState from 'pinia-plugin-persistedstate'
import { useGlobalConfigStore } from '@/stores/globalConfig' import { useGlobalConfigStore } from '@/stores/globalConfigStore'
export const usePinia = { export const usePinia = {
install (app) { install (app) {

View File

@@ -1,12 +0,0 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useGlobalConfigStore = defineStore('globalConfig', () => {
const currentLocale = ref('zh-CN')
const changeLocale = function (locale) {
currentLocale.value = locale
}
return { currentLocale, changeLocale }
}, {
persist: true
})

View File

@@ -0,0 +1,25 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useDark } from '@vueuse/core'
export const useGlobalConfigStore = defineStore('globalConfig', () => {
const currentLocale = ref('zh-CN')
const isDarkTheme = useDark()
const isCollapseLeft = ref(false)
return {
currentLocale,
isDarkTheme,
isCollapseLeft,
changeLocale (locale) {
currentLocale.value = locale
},
changeTheme (dark) {
isDarkTheme.value = dark
},
collapseLeft () {
isCollapseLeft.value = !isCollapseLeft.value
}
}
}, {
persist: true
})