Blame view

src/store/modules/layout/index.js 2.22 KB
c1b532ad   梁保满   权限配置,路由基础设置
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  
  export default {
    state: {
      isCollapse: false,
      logoShow: false,
      uniquerouter: true,
      rightNav: {},
      tabnavBox: JSON.parse(sessionStorage.getItem("addTab")) || [{
        title: "home",
        path: "/index"
      }]
    },
    mutations: {
      addTab (state, arg) {
        state.isActive = arg.path
        if (state.tabnavBox[0] && state.tabnavBox[0].title !== "home") {
          state.tabnavBox.unshift({
            title: "home",
            path: "/index"
          })
        }
  
        for (let i = 0; i < state.tabnavBox.length; i++) {
          if (state.tabnavBox[i].path === arg.path) {
            return false
          }
        }
        state.tabnavBox.push({
          title: arg.title,
          path: arg.path
        })
  
        sessionStorage.setItem("addTab", JSON.stringify(state.tabnavBox))
      },
      openMenu (state, arg) {
        state.rightNav = arg
      },
      removeTab (state, arg) {
        let index = state.tabnavBox.findIndex(function (value, key) {
          return value.path === arg.tabItem.path
        })
        state.tabnavBox.splice(index, 1)
        if (arg.tabItem.path === arg.fullPath) {
          let tabActive = state.tabnavBox[index] || state.tabnavBox[index - 1]
          arg.router.push(tabActive.path)
        }
        sessionStorage.setItem("addTab", JSON.stringify(state.tabnavBox))
      },
      removeOtherTab (state, arg) {
        state.tabnavBox = [{
          title: "home",
          path: "/index"
        }]
        if (arg.all) {
          arg.router.push("/index")
          return false
        }
        state.tabnavBox.push(arg.tabItem)
        arg.router.push(arg.tabItem.path)
        sessionStorage.setItem("addTab", JSON.stringify(state.tabnavBox))
      },
      collapse (state, arg) {
        state.isCollapse = !state.isCollapse
        if (state.logoShow) {
          setTimeout(function () {
            state.logoShow = false
          }, 300)
        } else {
          state.logoShow = true
        }
      }
    },
    actions: {
      addTab ({commit}, arg) {
        commit("addTab", arg)
      },
      openMenu ({commit}, arg) {
        commit("openMenu", arg)
      },
      removeTab ({commit}, arg) {
        commit("removeTab", arg)
      },
      removeOtherTab ({commit}, arg) {
        commit("removeOtherTab", arg)
      },
      collapse ({commit}, arg) {
        commit("collapse", arg)
      }
    }
  }