app.js 1.5 KB

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