From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/store/modules/locale.ts | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/src/store/modules/locale.ts b/src/store/modules/locale.ts
new file mode 100644
index 0000000..1fc772a
--- /dev/null
+++ b/src/store/modules/locale.ts
@@ -0,0 +1,59 @@
+import { defineStore } from 'pinia'
+import { store } from '../index'
+import zhCn from 'element-plus/es/locale/lang/zh-cn'
+import en from 'element-plus/es/locale/lang/en'
+import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import { LocaleDropdownType } from '@/types/localeDropdown'
+
+const { wsCache } = useCache()
+
+const elLocaleMap = {
+ 'zh-CN': zhCn,
+ en: en
+}
+interface LocaleState {
+ currentLocale: LocaleDropdownType
+ localeMap: LocaleDropdownType[]
+}
+
+export const useLocaleStore = defineStore('locales', {
+ state: (): LocaleState => {
+ return {
+ currentLocale: {
+ lang: wsCache.get(CACHE_KEY.LANG) || 'zh-CN',
+ elLocale: elLocaleMap[wsCache.get(CACHE_KEY.LANG) || 'zh-CN']
+ },
+ // 澶氳瑷�
+ localeMap: [
+ {
+ lang: 'zh-CN',
+ name: '绠�浣撲腑鏂�'
+ },
+ {
+ lang: 'en',
+ name: 'English'
+ }
+ ]
+ }
+ },
+ getters: {
+ getCurrentLocale(): LocaleDropdownType {
+ return this.currentLocale
+ },
+ getLocaleMap(): LocaleDropdownType[] {
+ return this.localeMap
+ }
+ },
+ actions: {
+ setCurrentLocale(localeMap: LocaleDropdownType) {
+ // this.locale = Object.assign(this.locale, localeMap)
+ this.currentLocale.lang = localeMap?.lang
+ this.currentLocale.elLocale = elLocaleMap[localeMap?.lang]
+ wsCache.set(CACHE_KEY.LANG, localeMap?.lang)
+ }
+ }
+})
+
+export const useLocaleStoreWithOut = () => {
+ return useLocaleStore(store)
+}
--
Gitblit v1.8.0