app.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import defaultSettings from '@/settings';
  2. import { defineStore } from 'pinia';
  3. export const useAppStore = defineStore('app', {
  4. state: () => {
  5. return {
  6. sidebar: { opened: true },
  7. device: 'desktop',
  8. settings: defaultSettings,
  9. cachedViews: [],
  10. cachedViewsDeep: []
  11. };
  12. },
  13. actions: {
  14. M_settings(data) {
  15. this.$patch((state) => {
  16. state.settings = { ...state.settings, ...data };
  17. });
  18. },
  19. M_sidebar_opened(data) {
  20. this.$patch((state) => {
  21. state.sidebar.opened = data;
  22. });
  23. },
  24. M_toggleSideBar() {
  25. this.$patch((state) => {
  26. state.sidebar.opened = !state.sidebar.opened;
  27. });
  28. },
  29. M_ADD_CACHED_VIEW(view) {
  30. this.$patch((state) => {
  31. if (state.cachedViews.includes(view))
  32. return;
  33. state.cachedViews.push(view);
  34. });
  35. },
  36. M_DEL_CACHED_VIEW(view) {
  37. this.$patch((state) => {
  38. const index = state.cachedViews.indexOf(view);
  39. index > -1 && state.cachedViews.splice(index, 1);
  40. });
  41. },
  42. M_ADD_CACHED_VIEW_DEEP(view) {
  43. this.$patch((state) => {
  44. if (state.cachedViewsDeep.includes(view))
  45. return;
  46. state.cachedViewsDeep.push(view);
  47. });
  48. },
  49. M_DEL_CACHED_VIEW_DEEP(view) {
  50. this.$patch((state) => {
  51. const index = state.cachedViewsDeep.indexOf(view);
  52. index > -1 && state.cachedViewsDeep.splice(index, 1);
  53. });
  54. },
  55. A_sidebar_opened(data) {
  56. this.M_sidebar_opened(data);
  57. }
  58. }
  59. });
  60. //# sourceMappingURL=app.js.map