app.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Cookies from 'js-cookie'
  2. const useAppStore = defineStore(
  3. 'app',
  4. {
  5. state: () => ({
  6. sidebar: {
  7. opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
  8. withoutAnimation: false,
  9. hide: false
  10. },
  11. device: 'desktop',
  12. size: Cookies.get('size') || 'default'
  13. }),
  14. actions: {
  15. toggleSideBar(withoutAnimation) {
  16. if (this.sidebar.hide) {
  17. return false
  18. }
  19. this.sidebar.opened = !this.sidebar.opened
  20. this.sidebar.withoutAnimation = withoutAnimation
  21. if (this.sidebar.opened) {
  22. Cookies.set('sidebarStatus', 1)
  23. } else {
  24. Cookies.set('sidebarStatus', 0)
  25. }
  26. },
  27. closeSideBar({ withoutAnimation }) {
  28. Cookies.set('sidebarStatus', 0)
  29. this.sidebar.opened = false
  30. this.sidebar.withoutAnimation = withoutAnimation
  31. },
  32. toggleDevice(device) {
  33. this.device = device
  34. },
  35. setSize(size) {
  36. this.size = size
  37. Cookies.set('size', size)
  38. },
  39. toggleSideBarHide(status) {
  40. this.sidebar.hide = status
  41. }
  42. }
  43. })
  44. export default useAppStore