Newer
Older
KaiFengPC / src / store / modules / app.js
@zhangdeliang zhangdeliang on 23 May 1 KB 初始化项目
  1. import Cookies from 'js-cookie';
  2.  
  3. const useAppStore = defineStore('app', {
  4. state: () => ({
  5. sidebar: {
  6. opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
  7. withoutAnimation: false,
  8. hide: false,
  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({ withoutAnimation }) {
  27. Cookies.set('sidebarStatus', 0);
  28. this.sidebar.opened = false;
  29. this.sidebar.withoutAnimation = withoutAnimation;
  30. },
  31. openSideBar({ withoutAnimation }) {
  32. Cookies.set('sidebarStatus', 1);
  33. this.sidebar.opened = true;
  34. this.sidebar.withoutAnimation = withoutAnimation;
  35. },
  36. toggleDevice(device) {
  37. this.device = device;
  38. },
  39. setSize(size) {
  40. this.size = size;
  41. Cookies.set('size', size);
  42. },
  43. toggleSideBarHide(status) {
  44. this.sidebar.hide = status;
  45. },
  46. },
  47. });
  48.  
  49. export default useAppStore;