Pārlūkot izejas kodu

Merge branch 'master' of https://git.citupro.com/zhengnaiwen_citu/menduner

Xiao_123 1 gadu atpakaļ
vecāks
revīzija
abac15427c
6 mainītis faili ar 145 papildinājumiem un 649 dzēšanām
  1. 1 0
      package.json
  2. 19 649
      pnpm-lock.yaml
  3. 15 0
      src/hooks/web/useCache.js
  4. 42 0
      src/plugins/vueI18n/index.js
  5. 60 0
      src/store/modules/locale.js
  6. 8 0
      src/utils/cache.js

+ 1 - 0
package.json

@@ -14,6 +14,7 @@
     "pinia": "^2.1.7",
     "roboto-fontface": "*",
     "vue": "^3.4.0",
+    "vue-i18n": "9",
     "vue-router": "^4.3.0",
     "vuetify": "^3.5.0"
   },

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 19 - 649
pnpm-lock.yaml


+ 15 - 0
src/hooks/web/useCache.js

@@ -0,0 +1,15 @@
+/**
+ * 配置浏览器本地存储的方式,可直接存储对象数组。
+ */
+
+// import WebStorageCache from 'web-storage-cache'
+
+// export const useCache = (type = 'localStorage') => {
+//   const wsCache = new WebStorageCache({
+//     storage: type
+//   })
+
+//   return {
+//     wsCache
+//   }
+// }

+ 42 - 0
src/plugins/vueI18n/index.js

@@ -0,0 +1,42 @@
+// import { App } from 'vue'
+import { createI18n } from 'vue-i18n'
+import { useLocaleStoreWithOut } from '@/store/modules/locale'
+// import { I18n, I18nOptions } from 'vue-i18n'
+// import { setHtmlPageLang } from './helper'
+
+export let i18n
+
+const createI18nOptions = async () => {
+  const localeStore = useLocaleStoreWithOut()
+  const locale = localeStore.getCurrentLocale
+  const localeMap = localeStore.getLocaleMap
+  const defaultLocal = await import(`../../locales/${locale.lang}.js`)
+  const message = defaultLocal.default ?? {}
+  
+  document.querySelector('html')?.setAttribute('lang', locale.lang)
+
+  localeStore.setCurrentLocale({
+    lang: locale.lang
+    // elLocale: elLocal
+  })
+
+  return {
+    legacy: false,
+    locale: locale.lang,
+    fallbackLocale: locale.lang,
+    messages: {
+      [locale.lang]: message
+    },
+    availableLocales: localeMap.map((v) => v.lang),
+    sync: true,
+    silentTranslationWarn: true,
+    missingWarn: false,
+    silentFallbackWarn: true
+  }
+}
+
+export const setupI18n = async (app) => {
+  const options = await createI18nOptions()
+  i18n = createI18n(options)
+  app.use(i18n)
+}

+ 60 - 0
src/store/modules/locale.js

@@ -0,0 +1,60 @@
+import { defineStore } from 'pinia'
+import { store } from '../index'
+import { en, zhHans, zhHant } from 'vuetify/locale'
+import { getLang, setLang } from '@/utils/catch'
+// 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'
+
+// const { wsCache } = useCache()
+
+const elLocaleMap = {
+  'zh-CN-Hant': zhHant,
+  'zh-CN': zhHans,
+  en: en
+}
+export const useLocaleStore = defineStore('locales', {
+  state: () => {
+    return {
+      currentLocale: {
+        lang: getLang() || 'zh-CN',
+        elLocale: elLocaleMap[getLang() || 'zh-CN']
+      },
+      // 多语言
+      localeMap: [
+        {
+          lang: 'zh-CN',
+          name: '简体中文'
+        },
+        {
+          lang: 'zh-CN-Hant',
+          name: '繁体中文'
+        },
+        {
+          lang: 'en',
+          name: 'English'
+        }
+      ]
+    }
+  },
+  getters: {
+    getCurrentLocale() {
+      return this.currentLocale
+    },
+    getLocaleMap() {
+      return this.localeMap
+    }
+  },
+  actions: {
+    setCurrentLocale(localeMap) {
+      // this.locale = Object.assign(this.locale, localeMap)
+      this.currentLocale.lang = localeMap?.lang
+      this.currentLocale.elLocale = elLocaleMap[localeMap?.lang]
+      setLang(localeMap?.lang)
+    }
+  }
+})
+
+export const useLocaleStoreWithOut = () => {
+  return useLocaleStore(store)
+}

+ 8 - 0
src/utils/cache.js

@@ -0,0 +1,8 @@
+
+export const getLang = () => {
+  return localStorage.getItem('lang')
+}
+
+export const setLang = (value) => {
+  return localStorage.setItem('lang', value)
+}

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels