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