setTabs.js
1.1 KB
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
import util from '@/libs/util.js'
const getDefaultState = () => {
return {
openTab: [], //所有打开的路由
activeIndex: '/panel' //激活状态
}
}
const state = getDefaultState()
const mutations = {
// 添加tabs
ADD_TABS (state, data) {
state.openTab.push(data);
},
// 删除tabs
DELETE_TABS (state, route) {
let index = 0;
for (let option of state.openTab) {
if (option.route === route) {
break;
}
index++;
}
state.openTab.splice(index, 1);
},
// 设置当前激活的tab
SET_ACTIVE_INDEX (state, index) {
state.activeIndex = index;
},
// 初始化
INIT_TABS(state) {
state.openTab = [];
state.openTab[0] = { route: "/panel", name: "首页" }
},
}
const actions = {
add_tabs({ commit }, data) {
commit('ADD_TABS', data)
},
delete_tabs({ commit }, route) {
commit('DELETE_TABS', route)
},
set_active_index({ commit }, index) {
commit('SET_ACTIVE_INDEX', index)
},
init_tabs({ commit }) {
commit('INIT_TABS')
},
}
export default {
namespaced: true,
state,
mutations,
actions
}