he wei
2025-04-03 c6a2d2debf161b987ff91c6ac9560d10fc98c54b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { defineStore } from 'pinia';
import Cookies from 'js-cookie';
import { ref } from 'vue';
 
export const useAppStore = defineStore('app', () => {
  const sidebar = ref({
    opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
    withoutAnimation: false
  });
  const device = ref('desktop');
  const size = ref(Cookies.get('size') || 'default');
  
  function toggleSidebar() {
    sidebar.value.opened = !sidebar.value.opened;
    sidebar.value.withoutAnimation = false;
    if (sidebar.value.opened) {
      Cookies.set('sidebarStatus', 1);
    } else {
      Cookies.set('sidebarStatus', 0);
    }
  }
  
  function closeSidebar({ withoutAnimation }) {
    Cookies.set('sidebarStatus', 0);
    sidebar.value.opened = false;
    sidebar.value.withoutAnimation = withoutAnimation;
  }
  
  function toggleDevice(device) {
    device.value = device;
  }
  
  function setSize(size) {
    size.value = size;
    Cookies.set('size', size);
  }
  
  return { sidebar, device, size, toggleSidebar, closeSidebar, toggleDevice, setSize };
});