132e54e0660111db0c75af7ce1c606319ffc5ef4.svn-base 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import Cookies from 'js-cookie'
  2. const state = {
  3. sidebar: {
  4. opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
  5. withoutAnimation: false
  6. },
  7. device: 'desktop'
  8. }
  9. const mutations = {
  10. TOGGLE_SIDEBAR: state => {
  11. state.sidebar.opened = !state.sidebar.opened
  12. state.sidebar.withoutAnimation = false
  13. if (state.sidebar.opened) {
  14. Cookies.set('sidebarStatus', 1)
  15. } else {
  16. Cookies.set('sidebarStatus', 0)
  17. }
  18. },
  19. CLOSE_SIDEBAR: (state, withoutAnimation) => {
  20. Cookies.set('sidebarStatus', 0)
  21. state.sidebar.opened = false
  22. state.sidebar.withoutAnimation = withoutAnimation
  23. },
  24. TOGGLE_DEVICE: (state, device) => {
  25. state.device = device
  26. }
  27. }
  28. const actions = {
  29. toggleSideBar({ commit }) {
  30. commit('TOGGLE_SIDEBAR')
  31. },
  32. closeSideBar({ commit }, { withoutAnimation }) {
  33. commit('CLOSE_SIDEBAR', withoutAnimation)
  34. },
  35. toggleDevice({ commit }, device) {
  36. commit('TOGGLE_DEVICE', device)
  37. }
  38. }
  39. export default {
  40. namespaced: true,
  41. state,
  42. mutations,
  43. actions
  44. }