mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
fix: 处理切换语言,UI框架不会变的问题
This commit is contained in:
parent
f6a4e87e05
commit
afed1cb6b3
12
pnpm-lock.yaml
generated
12
pnpm-lock.yaml
generated
@ -1,6 +1,8 @@
|
|||||||
lockfileVersion: 5.4
|
lockfileVersion: 5.4
|
||||||
|
|
||||||
specifiers:
|
specifiers:
|
||||||
|
'@amap/amap-jsapi-loader': ^1.0.1
|
||||||
|
'@amap/amap-jsapi-types': ^0.0.8
|
||||||
'@commitlint/cli': ^17.0.2
|
'@commitlint/cli': ^17.0.2
|
||||||
'@commitlint/config-conventional': ^17.0.2
|
'@commitlint/config-conventional': ^17.0.2
|
||||||
'@types/color': ^3.0.3
|
'@types/color': ^3.0.3
|
||||||
@ -65,6 +67,8 @@ specifiers:
|
|||||||
vuedraggable: ^4.1.0
|
vuedraggable: ^4.1.0
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@amap/amap-jsapi-loader': 1.0.1
|
||||||
|
'@amap/amap-jsapi-types': 0.0.8
|
||||||
'@types/color': 3.0.3
|
'@types/color': 3.0.3
|
||||||
'@types/crypto-js': 4.1.1
|
'@types/crypto-js': 4.1.1
|
||||||
'@types/keymaster': 1.6.30
|
'@types/keymaster': 1.6.30
|
||||||
@ -132,6 +136,14 @@ devDependencies:
|
|||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
|
/@amap/amap-jsapi-loader/1.0.1:
|
||||||
|
resolution: {integrity: sha512-nPyLKt7Ow/ThHLkSvn2etQlUzqxmTVgK7bIgwdBRTg2HK5668oN7xVxkaiRe3YZEzGzfV2XgH5Jmu2T73ljejw==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@amap/amap-jsapi-types/0.0.8:
|
||||||
|
resolution: {integrity: sha512-q0FyZDIJcXjsMLGc3oS9rjfJsErOvt9rcp6AgzY4k14vo7bBhdq4eKwoSdVp/pYjR/rfaKBns5v10ycZOFwf/A==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@ampproject/remapping/2.2.0:
|
/@ampproject/remapping/2.2.0:
|
||||||
resolution: {integrity: sha512-qRmjj8nj9qmLTQXXmaR1cck3UXSRMPrbsLJAasZpF+t3riI71BXed5ebIOYwQntykeZuhjsdweEc9BxH5Jc26w==}
|
resolution: {integrity: sha512-qRmjj8nj9qmLTQXXmaR1cck3UXSRMPrbsLJAasZpF+t3riI71BXed5ebIOYwQntykeZuhjsdweEc9BxH5Jc26w==}
|
||||||
engines: {node: '>=6.0.0'}
|
engines: {node: '>=6.0.0'}
|
||||||
|
13
src/App.vue
13
src/App.vue
@ -1,9 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-config-provider
|
<n-config-provider
|
||||||
:locale="zhCN"
|
|
||||||
:theme="darkTheme"
|
:theme="darkTheme"
|
||||||
:hljs="hljsTheme"
|
:hljs="hljsTheme"
|
||||||
:date-locale="dateZhCN"
|
:locale="locale"
|
||||||
|
:date-locale="dateLocale"
|
||||||
:theme-overrides="overridesTheme"
|
:theme-overrides="overridesTheme"
|
||||||
>
|
>
|
||||||
<go-app-provider>
|
<go-app-provider>
|
||||||
@ -14,11 +14,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { zhCN, dateZhCN, NConfigProvider } from 'naive-ui'
|
import { NConfigProvider } from 'naive-ui'
|
||||||
import { GoAppProvider } from '@/components/GoAppProvider'
|
import { GoAppProvider } from '@/components/GoAppProvider'
|
||||||
import { I18n } from '@/components/I18n'
|
import { I18n } from '@/components/I18n'
|
||||||
|
import { useDarkThemeHook, useThemeOverridesHook, useCode, useLang } from '@/hooks'
|
||||||
import { useDarkThemeHook, useThemeOverridesHook, useCode } from '@/hooks'
|
|
||||||
|
|
||||||
// 暗黑主题
|
// 暗黑主题
|
||||||
const darkTheme = useDarkThemeHook()
|
const darkTheme = useDarkThemeHook()
|
||||||
@ -28,4 +27,8 @@ const overridesTheme = useThemeOverridesHook()
|
|||||||
|
|
||||||
// 代码主题
|
// 代码主题
|
||||||
const hljsTheme = useCode()
|
const hljsTheme = useCode()
|
||||||
|
|
||||||
|
// 全局语言
|
||||||
|
const { locale, dateLocale } = useLang()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -2,4 +2,5 @@ export * from '@/hooks/useTheme.hook'
|
|||||||
export * from '@/hooks/usePreviewScale.hook'
|
export * from '@/hooks/usePreviewScale.hook'
|
||||||
export * from '@/hooks/useCode.hook'
|
export * from '@/hooks/useCode.hook'
|
||||||
export * from '@/hooks/useChartDataFetch.hook'
|
export * from '@/hooks/useChartDataFetch.hook'
|
||||||
export * from '@/hooks/useLifeHandler.hook'
|
export * from '@/hooks/useLifeHandler.hook'
|
||||||
|
export * from '@/hooks/useLang.hook'
|
24
src/hooks/useLang.hook.ts
Normal file
24
src/hooks/useLang.hook.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { computed } from 'vue'
|
||||||
|
import { LangEnum } from '@/enums/styleEnum'
|
||||||
|
import { useLangStore } from '@/store/modules/langStore/langStore'
|
||||||
|
import { zhCN, enUS, dateEnUS, dateZhCN } from 'naive-ui'
|
||||||
|
|
||||||
|
type LangStoreType = typeof useLangStore
|
||||||
|
|
||||||
|
// 语言切换
|
||||||
|
export const useLang = () => {
|
||||||
|
const lang = useLangStore()
|
||||||
|
|
||||||
|
const locale = computed(() => {
|
||||||
|
return lang.getLang === LangEnum.ZH ? zhCN : enUS
|
||||||
|
})
|
||||||
|
|
||||||
|
const dateLocale = computed(() => {
|
||||||
|
return lang.getLang === LangEnum.ZH ? dateZhCN : dateEnUS
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
locale,
|
||||||
|
dateLocale
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
import type { App } from 'vue';
|
import type { App } from 'vue';
|
||||||
import { createPinia } from 'pinia';
|
import { createPinia } from 'pinia';
|
||||||
|
|
||||||
const store = createPinia();
|
const pinia = createPinia();
|
||||||
|
|
||||||
export function setupStore(app: App<Element>) {
|
export function setupStore(app: App<Element>) {
|
||||||
app.use(store);
|
app.use(pinia);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { store };
|
export { pinia };
|
||||||
|
@ -6,10 +6,8 @@ import i18n from '@/i18n/index'
|
|||||||
import { setLocalStorage, getLocalStorage, reloadRoutePage } from '@/utils'
|
import { setLocalStorage, getLocalStorage, reloadRoutePage } from '@/utils'
|
||||||
import { StorageEnum } from '@/enums/storageEnum'
|
import { StorageEnum } from '@/enums/storageEnum'
|
||||||
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
|
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
|
||||||
const settingStore = useSettingStore()
|
|
||||||
|
|
||||||
const { GO_LANG_STORE } = StorageEnum
|
const { GO_LANG_STORE } = StorageEnum
|
||||||
|
|
||||||
const storageLang: LangStateType = getLocalStorage(GO_LANG_STORE)
|
const storageLang: LangStateType = getLocalStorage(GO_LANG_STORE)
|
||||||
|
|
||||||
// 语言
|
// 语言
|
||||||
@ -17,7 +15,7 @@ export const useLangStore = defineStore({
|
|||||||
id: 'useLangStore',
|
id: 'useLangStore',
|
||||||
state: (): LangStateType =>
|
state: (): LangStateType =>
|
||||||
storageLang || {
|
storageLang || {
|
||||||
lang,
|
lang
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
getLang(): LangEnum {
|
getLang(): LangEnum {
|
||||||
@ -26,6 +24,8 @@ export const useLangStore = defineStore({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
changeLang(lang: LangEnum): void {
|
changeLang(lang: LangEnum): void {
|
||||||
|
const settingStore = useSettingStore()
|
||||||
|
|
||||||
if (this.lang === lang) return
|
if (this.lang === lang) return
|
||||||
this.lang = lang
|
this.lang = lang
|
||||||
i18n.global.locale = lang
|
i18n.global.locale = lang
|
||||||
|
Loading…
x
Reference in New Issue
Block a user