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