gaoshp
2024-01-05 b5db49ce1e4c678ce4a7120928811a9621128b8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Cookies from 'js-cookie'
 
const app = {
  state: {
    sidebar: {
      opened: !+Cookies.get('sidebarStatus'),
      withoutAnimation: false
    },
    device: 'desktop',
    mainHeight: 0,
    mainWidth: 0
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('sidebarStatus', 1)
      } else {
        Cookies.set('sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
      state.sidebar.withoutAnimation = false
      // 左侧菜单栏宽度变化后 重新计算右侧内容区域宽度
      let dif = 0
      if (state.device === 'desktop') {
        dif = state.sidebar.opened ? 180 : 36
      } else {
        dif = 0
      }
      state.mainWidth = window.innerWidth - dif
    },
    CLOSE_SIDEBAR: (state, withoutAnimation) => {
      Cookies.set('sidebarStatus', 1)
      state.sidebar.opened = false
      state.sidebar.withoutAnimation = withoutAnimation
    },
    TOGGLE_DEVICE: (state, device) => {
      state.device = device
      state.mainHeight = window.innerHeight - 50
      // 页面尺寸变化后(页面初始化时) 计算右侧内容区域宽度
      let dif = 0
      if (state.device === 'desktop') {
        dif = state.sidebar.opened ? 180 : 36
      } else {
        dif = 0
      }
      state.mainWidth = window.innerWidth - dif
    }
  },
  actions: {
    ToggleSideBar: ({ commit }) => {
      commit('TOGGLE_SIDEBAR')
    },
    CloseSideBar({ commit }, { withoutAnimation }) {
      commit('CLOSE_SIDEBAR', withoutAnimation)
    },
    ToggleDevice({ commit }, device) {
      commit('TOGGLE_DEVICE', device)
    }
  }
}
 
export default app