app.js 1.1 KB

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