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