app.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { defineStore } from 'pinia';
  2. import { useStorage } from '@vueuse/core';
  3. import { ref, reactive, computed } from 'vue';
  4. export const useAppStore = defineStore('app', () => {
  5. const sidebarStatus = useStorage('sidebarStatus', '1');
  6. const sidebar = reactive({
  7. opened: sidebarStatus.value ? !!+sidebarStatus.value : true,
  8. withoutAnimation: false,
  9. hide: false
  10. });
  11. const device = ref<string>('desktop');
  12. const size = useStorage<'large' | 'default' | 'small'>('size', 'default');
  13. const toggleSideBar = (withoutAnimation: boolean) => {
  14. if (sidebar.hide) {
  15. return false;
  16. }
  17. sidebar.opened = !sidebar.opened;
  18. sidebar.withoutAnimation = withoutAnimation;
  19. if (sidebar.opened) {
  20. sidebarStatus.value = '1';
  21. } else {
  22. sidebarStatus.value = '0';
  23. }
  24. };
  25. const closeSideBar = ({ withoutAnimation }: any): void => {
  26. sidebarStatus.value = '0';
  27. sidebar.opened = false;
  28. sidebar.withoutAnimation = withoutAnimation;
  29. };
  30. const toggleDevice = (d: string): void => {
  31. device.value = d;
  32. };
  33. const setSize = (s: 'large' | 'default' | 'small'): void => {
  34. size.value = s;
  35. };
  36. const toggleSideBarHide = (status: boolean): void => {
  37. sidebar.hide = status;
  38. };
  39. return {
  40. device,
  41. sidebar,
  42. size,
  43. toggleSideBar,
  44. closeSideBar,
  45. toggleDevice,
  46. setSize,
  47. toggleSideBarHide
  48. };
  49. });