locale.js 843 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { defineStore } from 'pinia'
  2. import { en, zhHans } from 'vuetify/locale'
  3. import { reactive } from 'vue'
  4. const elLocaleMap = {
  5. 'zh-CN': zhHans,
  6. en: en
  7. }
  8. export const useLocaleStore = defineStore('locales',
  9. () => {
  10. const localeMap = [
  11. {
  12. lang: 'zh-CN',
  13. name: '简体中文'
  14. },
  15. {
  16. lang: 'en',
  17. name: 'English'
  18. }
  19. ]
  20. const currentLocale = reactive({
  21. lang: 'zh-CN',
  22. elLocale: elLocaleMap['zh-CN']
  23. })
  24. const setCurrentLocale = (localeMap) => {
  25. // this.locale = Object.assign(this.locale, localeMap)
  26. currentLocale.lang = localeMap.lang
  27. currentLocale.elLocale = elLocaleMap[localeMap.lang]
  28. }
  29. return {
  30. localeMap,
  31. currentLocale,
  32. setCurrentLocale
  33. }
  34. },
  35. {
  36. persist: true, // ref() 持久化响应
  37. }
  38. )