app.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Cookies from 'js-cookie'
  2. const useAppStore = defineStore(
  3. 'app_sd', {
  4. state: () => ({
  5. sidebar: {
  6. opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
  7. withoutAnimation: false,
  8. hide: true //控制是否隐藏左侧导航栏
  9. },
  10. device: 'desktop',
  11. size: Cookies.get('size') || 'default'
  12. }),
  13. actions: {
  14. toggleSideBar(withoutAnimation) {
  15. if (this.sidebar.hide) {
  16. return false;
  17. }
  18. this.sidebar.opened = !this.sidebar.opened
  19. this.sidebar.withoutAnimation = withoutAnimation
  20. if (this.sidebar.opened) {
  21. Cookies.set('sidebarStatus', 1)
  22. } else {
  23. Cookies.set('sidebarStatus', 0)
  24. }
  25. },
  26. closeSideBar({
  27. withoutAnimation
  28. }) {
  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. export default useAppStore