app.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const state = {
  2. sidebar: {
  3. opened: localStorage.getItem("sidebarStatus")
  4. ? !!+localStorage.getItem("sidebarStatus")
  5. : true,
  6. withoutAnimation: false,
  7. hide: false,
  8. },
  9. device: "desktop",
  10. size: localStorage.getItem("size") || "medium",
  11. };
  12. const mutations = {
  13. TOGGLE_SIDEBAR: (state) => {
  14. if (state.sidebar.hide) {
  15. return false;
  16. }
  17. state.sidebar.opened = !state.sidebar.opened;
  18. state.sidebar.withoutAnimation = false;
  19. if (state.sidebar.opened) {
  20. localStorage.setItem("sidebarStatus", 1);
  21. } else {
  22. localStorage.setItem("sidebarStatus", 0);
  23. }
  24. },
  25. CLOSE_SIDEBAR: (state, withoutAnimation) => {
  26. localStorage.setItem("sidebarStatus", 0);
  27. state.sidebar.opened = false;
  28. state.sidebar.withoutAnimation = withoutAnimation;
  29. },
  30. TOGGLE_DEVICE: (state, device) => {
  31. state.device = device;
  32. },
  33. SET_SIZE: (state, size) => {
  34. state.size = size;
  35. localStorage.setItem("size", size);
  36. },
  37. SET_SIDEBAR_HIDE: (state, status) => {
  38. state.sidebar.hide = status;
  39. },
  40. };
  41. const actions = {
  42. toggleSideBar({ commit }) {
  43. commit("TOGGLE_SIDEBAR");
  44. },
  45. closeSideBar({ commit }, { withoutAnimation }) {
  46. commit("CLOSE_SIDEBAR", withoutAnimation);
  47. },
  48. toggleDevice({ commit }, device) {
  49. commit("TOGGLE_DEVICE", device);
  50. },
  51. setSize({ commit }, size) {
  52. commit("SET_SIZE", size);
  53. },
  54. toggleSideBarHide({ commit }, status) {
  55. commit("SET_SIDEBAR_HIDE", status);
  56. },
  57. };
  58. export default {
  59. namespaced: true,
  60. state,
  61. mutations,
  62. actions,
  63. };