app.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.opened = true;
  13. state.sidebar.withoutAnimation = false
  14. if (state.sidebar.opened) {
  15. Cookies.set('sidebarStatus', 1)
  16. } else {
  17. Cookies.set('sidebarStatus', 0)
  18. }
  19. },
  20. CLOSE_SIDEBAR: (state, withoutAnimation) => {
  21. Cookies.set('sidebarStatus', 0)
  22. state.sidebar.opened = false
  23. state.sidebar.withoutAnimation = withoutAnimation
  24. },
  25. TOGGLE_DEVICE: (state, device) => {
  26. state.device = device
  27. }
  28. }
  29. const actions = {
  30. toggleSideBar ({ commit }) {
  31. commit('TOGGLE_SIDEBAR')
  32. },
  33. closeSideBar ({ commit }, { withoutAnimation }) {
  34. commit('CLOSE_SIDEBAR', withoutAnimation)
  35. },
  36. toggleDevice ({ commit }, device) {
  37. commit('TOGGLE_DEVICE', device)
  38. }
  39. }
  40. export default {
  41. namespaced: true,
  42. state,
  43. mutations,
  44. actions
  45. }