app.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. size: Cookies.get('size') || 'medium'
  9. }
  10. const mutations = {
  11. TOGGLE_SIDEBAR: state => {
  12. state.sidebar.opened = !state.sidebar.opened
  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. SET_SIZE: (state, size) => {
  29. state.size = size
  30. Cookies.set('size', size)
  31. }
  32. }
  33. const actions = {
  34. toggleSideBar({ commit }) {
  35. commit('TOGGLE_SIDEBAR')
  36. },
  37. closeSideBar({ commit }, { withoutAnimation }) {
  38. commit('CLOSE_SIDEBAR', withoutAnimation)
  39. },
  40. toggleDevice({ commit }, device) {
  41. commit('TOGGLE_DEVICE', device)
  42. },
  43. setSize({ commit }, size) {
  44. commit('SET_SIZE', size)
  45. }
  46. }
  47. export default {
  48. namespaced: true,
  49. state,
  50. mutations,
  51. actions
  52. }