Blame view

HHECS.Web/src/store/modules/app.js 1.04 KB
胡菁 authored
1
import Cookies from 'js-cookie'
胡菁 authored
2
3
4

const state = {
  sidebar: {
胡菁 authored
5
6
    opened: Cookies.get('sidebarStatus')
      ? !!+Cookies.get('sidebarStatus')
胡菁 authored
7
      : true,
胡菁 authored
8
    withoutAnimation: false
胡菁 authored
9
  },
胡菁 authored
10
11
  device: 'desktop'
}
胡菁 authored
12
13

const mutations = {
胡菁 authored
14
  TOGGLE_SIDEBAR: (state) => {
胡菁 authored
15
16
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
胡菁 authored
17
    if (state.sidebar.opened) {
胡菁 authored
18
      Cookies.set('sidebarStatus', 1)
胡菁 authored
19
    } else {
胡菁 authored
20
      Cookies.set('sidebarStatus', 0)
胡菁 authored
21
22
23
    }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
胡菁 authored
24
25
26
    Cookies.set('sidebarStatus', 0)
    state.sidebar.opened = false
    state.sidebar.withoutAnimation = withoutAnimation
胡菁 authored
27
28
  },
  TOGGLE_DEVICE: (state, device) => {
胡菁 authored
29
30
31
    state.device = device
  }
}
胡菁 authored
32
33
34

const actions = {
  toggleSideBar({ commit }) {
胡菁 authored
35
    commit('TOGGLE_SIDEBAR')
胡菁 authored
36
37
  },
  closeSideBar({ commit }, { withoutAnimation }) {
胡菁 authored
38
    commit('CLOSE_SIDEBAR', withoutAnimation)
胡菁 authored
39
40
  },
  toggleDevice({ commit }, device) {
胡菁 authored
41
42
43
    commit('TOGGLE_DEVICE', device)
  }
}
胡菁 authored
44
45
46
47
48

export default {
  namespaced: true,
  state,
  mutations,
胡菁 authored
49
50
  actions
}