index.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineStore } from 'pinia'
  2. import Cache from '/admin/support/cache'
  3. /**
  4. * app
  5. */
  6. type app = {
  7. size: 'small' | 'medium' | 'large'
  8. isExpand: boolean
  9. locale: 'zh' | 'en'
  10. isMobile: boolean
  11. isDarkMode: boolean
  12. activeMenu: string
  13. }
  14. export const useAppStore = defineStore('app', {
  15. state: (): app => ({
  16. size: 'small',
  17. isExpand: true,
  18. locale: Cache.get('language'),
  19. isMobile: false,
  20. isDarkMode: false,
  21. activeMenu: '/dashboard',
  22. }),
  23. getters: {
  24. getSize(): string {
  25. return this.size
  26. },
  27. getLocale(): string {
  28. return this.locale
  29. },
  30. getIsMobile(): boolean {
  31. return this.isMobile
  32. },
  33. getIsDarkMode(): boolean {
  34. return this.isDarkMode
  35. },
  36. getActiveMenu(): string {
  37. return this.activeMenu
  38. },
  39. },
  40. actions: {
  41. changeSize(size: 'small' | 'medium' | 'large'): void {
  42. this.size = size
  43. },
  44. changeLocale(locale: 'zh' | 'en'): void {
  45. Cache.set('language', locale)
  46. this.locale = locale
  47. },
  48. changeExpaned(): void {
  49. this.isExpand = !this.isExpand
  50. },
  51. setDarkMode(isDarkMode: boolean): void {
  52. this.isDarkMode = isDarkMode
  53. },
  54. setActiveMenu(activeMenu: string): void {
  55. this.activeMenu = activeMenu.startsWith('/') ? activeMenu : '/' + activeMenu
  56. },
  57. },
  58. })