locale.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import type { LocaleSetting, LocaleType } from '/#/config';
  2. import { defineStore } from 'pinia';
  3. import { store } from '/@/store';
  4. import { LOCALE_KEY } from '/@/enums/cacheEnum';
  5. import { createLocalStorage } from '/@/utils/cache';
  6. import { localeSetting } from '/@/settings/localeSetting';
  7. const ls = createLocalStorage();
  8. const lsLocaleSetting = (ls.get(LOCALE_KEY) || localeSetting) as LocaleSetting;
  9. interface LocaleState {
  10. localInfo: LocaleSetting;
  11. pathTitleMap: object;
  12. // myapps主题色(低代码应用列表首页)
  13. appIndexTheme: string
  14. // myapps - 跳转前路由地址
  15. appMainPth: string
  16. }
  17. export const useLocaleStore = defineStore({
  18. id: 'app-locale',
  19. state: (): LocaleState => ({
  20. localInfo: lsLocaleSetting,
  21. pathTitleMap: {},
  22. appIndexTheme: '',
  23. appMainPth: ''
  24. }),
  25. getters: {
  26. getShowPicker(): boolean {
  27. return !!this.localInfo?.showPicker;
  28. },
  29. getLocale(): LocaleType {
  30. return this.localInfo?.locale ?? 'zh_CN';
  31. },
  32. //update-begin-author:taoyan date:2022-6-1 for: VUEN-1144 online 配置成菜单后,打开菜单,显示名称未展示为菜单名称
  33. getPathTitle: (state) => {
  34. return (path) => state.pathTitleMap[path];
  35. },
  36. //update-end-author:taoyan date:2022-6-1 for: VUEN-1144 online 配置成菜单后,打开菜单,显示名称未展示为菜单名称
  37. getAppIndexTheme(): string {
  38. return this.appIndexTheme;
  39. },
  40. getAppMainPth(): string {
  41. return this.appMainPth;
  42. },
  43. },
  44. actions: {
  45. /**
  46. * Set up multilingual information and cache
  47. * @param info multilingual info
  48. */
  49. setLocaleInfo(info: Partial<LocaleSetting>) {
  50. this.localInfo = { ...this.localInfo, ...info };
  51. ls.set(LOCALE_KEY, this.localInfo);
  52. },
  53. /**
  54. * Initialize multilingual information and load the existing configuration from the local cache
  55. */
  56. initLocale() {
  57. this.setLocaleInfo({
  58. ...localeSetting,
  59. ...this.localInfo,
  60. });
  61. },
  62. //update-begin-author:taoyan date:2022-6-1 for: VUEN-1144 online 配置成菜单后,打开菜单,显示名称未展示为菜单名称
  63. setPathTitle(path, title) {
  64. this.pathTitleMap[path] = title;
  65. },
  66. //update-end-author:taoyan date:2022-6-1 for: VUEN-1144 online 配置成菜单后,打开菜单,显示名称未展示为菜单名称
  67. setAppIndexTheme(theme) {
  68. this.appIndexTheme = theme;
  69. },
  70. setAppMainPth(path) {
  71. this.appMainPth = path;
  72. },
  73. },
  74. });
  75. // Need to be used outside the setup
  76. export function useLocaleStoreWithOut() {
  77. return useLocaleStore(store);
  78. }