app.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if (state.sidebar.hide) {
  14. return false;
  15. }
  16. state.sidebar.opened = !state.sidebar.opened
  17. state.sidebar.withoutAnimation = false
  18. if (state.sidebar.opened) {
  19. Cookies.set('sidebarStatus', 1)
  20. } else {
  21. Cookies.set('sidebarStatus', 0)
  22. }
  23. },
  24. CLOSE_SIDEBAR: (state, withoutAnimation) => {
  25. Cookies.set('sidebarStatus', 0)
  26. state.sidebar.opened = false
  27. state.sidebar.withoutAnimation = withoutAnimation
  28. },
  29. TOGGLE_DEVICE: (state, device) => {
  30. state.device = device
  31. },
  32. SET_SIZE: (state, size) => {
  33. state.size = size
  34. Cookies.set('size', size)
  35. },
  36. SET_SIDEBAR_HIDE: (state, status) => {
  37. state.sidebar.hide = status
  38. }
  39. }
  40. const actions = {
  41. toggleSideBar({ commit }) {
  42. commit('TOGGLE_SIDEBAR')
  43. },
  44. closeSideBar({ commit }, { withoutAnimation }) {
  45. commit('CLOSE_SIDEBAR', withoutAnimation)
  46. },
  47. toggleDevice({ commit }, device) {
  48. commit('TOGGLE_DEVICE', device)
  49. },
  50. setSize({ commit }, size) {
  51. commit('SET_SIZE', size)
  52. },
  53. toggleSideBarHide({ commit }, status) {
  54. commit('SET_SIDEBAR_HIDE', status)
  55. }
  56. }
  57. export default {
  58. namespaced: true,
  59. state,
  60. mutations,
  61. actions
  62. }