huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame^] | 1 | import Cookies from 'js-cookie' |
| 2 | |
| 3 | const app = { |
| 4 | state: { |
| 5 | sidebar: { |
| 6 | opened: !+Cookies.get('sidebarStatus'), |
| 7 | withoutAnimation: false |
| 8 | }, |
| 9 | device: 'desktop' |
| 10 | }, |
| 11 | mutations: { |
| 12 | TOGGLE_SIDEBAR: state => { |
| 13 | if (state.sidebar.opened) { |
| 14 | Cookies.set('sidebarStatus', 1) |
| 15 | } else { |
| 16 | Cookies.set('sidebarStatus', 0) |
| 17 | } |
| 18 | state.sidebar.opened = !state.sidebar.opened |
| 19 | state.sidebar.withoutAnimation = false |
| 20 | }, |
| 21 | CLOSE_SIDEBAR: (state, withoutAnimation) => { |
| 22 | Cookies.set('sidebarStatus', 1) |
| 23 | state.sidebar.opened = false |
| 24 | state.sidebar.withoutAnimation = withoutAnimation |
| 25 | }, |
| 26 | TOGGLE_DEVICE: (state, device) => { |
| 27 | state.device = device |
| 28 | } |
| 29 | }, |
| 30 | actions: { |
| 31 | ToggleSideBar: ({ commit }) => { |
| 32 | commit('TOGGLE_SIDEBAR') |
| 33 | }, |
| 34 | CloseSideBar({ commit }, { withoutAnimation }) { |
| 35 | commit('CLOSE_SIDEBAR', withoutAnimation) |
| 36 | }, |
| 37 | ToggleDevice({ commit }, device) { |
| 38 | commit('TOGGLE_DEVICE', device) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | export default app |