app.js 1.03 KB
Newer Older
Pan's avatar
Pan committed
1
import Cookies from 'js-cookie'
Pan's avatar
Pan committed
2

花裤衩's avatar
花裤衩 committed
3 4 5 6
const state = {
  sidebar: {
    opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
    withoutAnimation: false
Pan's avatar
Pan committed
7
  },
花裤衩's avatar
花裤衩 committed
8 9 10 11 12 13 14 15
  device: 'desktop'
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
16
      Cookies.set('sidebarStatus', 1)
花裤衩's avatar
花裤衩 committed
17 18
    } else {
      Cookies.set('sidebarStatus', 0)
Pan's avatar
Pan committed
19 20
    }
  },
花裤衩's avatar
花裤衩 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    Cookies.set('sidebarStatus', 0)
    state.sidebar.opened = false
    state.sidebar.withoutAnimation = withoutAnimation
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device
  }
}

const actions = {
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  closeSideBar({ commit }, { withoutAnimation }) {
    commit('CLOSE_SIDEBAR', withoutAnimation)
  },
  toggleDevice({ commit }, device) {
    commit('TOGGLE_DEVICE', device)
Pan's avatar
Pan committed
40
  }
Pan's avatar
Pan committed
41
}
Pan's avatar
Pan committed
42

花裤衩's avatar
花裤衩 committed
43 44 45 46 47 48
export default {
  namespaced: true,
  state,
  mutations,
  actions
}