index.ts 731 B

123456789101112131415161718192021222324252627282930
  1. import { defineStore, createPinia } from 'pinia';
  2. const LOCALE_KEY = 'LOCALE__';
  3. const lsLocaleSetting = "";// window.sessionStorage.getItem(LOCALE_KEY);
  4. export const useLocaleStore = defineStore({
  5. id: 'app-locale',
  6. state: () => ({
  7. localInfo: lsLocaleSetting
  8. }),
  9. getters: {
  10. getLocale (): string {
  11. return this.localInfo ?? 'zh-CN';
  12. }
  13. },
  14. actions: {
  15. setLocaleInfo (info: string) {
  16. // window.sessionStorage.setItem(LOCALE_KEY,info);
  17. },
  18. initLocale () {
  19. const info = this.localInfo === null ? '' : this.localInfo;
  20. this.setLocaleInfo(info);
  21. }
  22. }
  23. })
  24. // Need to be used outside the setup
  25. export function useLocaleStoreWithOut () {
  26. return useLocaleStore(createPinia());
  27. }