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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { menuNav } from '@/api/menu'
//从服务端获取
const mock = [
{
"id": "1044886626813353984",
"parentId": "0",
"name": "dashboard",
"path": '/dashboard',
"icon": 'dashboard',
"leaf": false,
"children": [{
"id": "1044886629921333248",
"parentId": "1044886626813353984",
"name": "analysis",
"path": '/dashboard/analysis',
"leaf": true,
"children": []
},{
"id": "1044886629921333248",
"parentId": "1044886626813353984",
"name": "workplace",
"path": '/dashboard/workplace',
"leaf": true,
"children": []
}]
},
{
"id": "1044886626813353984",
"parentId": "0",
"name": "system",
"path": '/system',
"icon": 'setting',
"leaf": false,
"children": [{
"id": "1044886629921333248",
"parentId": "1044886626813353984",
"name": "setting",
"path": "/system/setting",
"leaf": false,
"children": [{
"id": "1044886630026190848",
"parentId": "1044886629921333248",
"name": "menu",
"path": "/system/setting/menu",
"leaf": true,
"children": []
}, {
"id": "1044886630122659840",
"parentId": "1044886629921333248",
"name": "module",
"path": "/system/setting/module",
"leaf": true,
"children": []
}, {
"id": "1044886630122659841",
"parentId": "1044886629921333248",
"name": "file-manager",
"path": "/system/setting/file-manager",
"leaf": true,
"children": []
}]
},{
"id": "1044886629921333248",
"parentId": "1044886626813353984",
"name": "role",
"path": "/system/role",
"leaf": true,
},{
"id": "1044886629921333248",
"parentId": "1044886626813353984",
"name": "admin",
"path": "/system/admin",
"leaf": true,
}]
}]
const state = {
loading: false,
menuNav: {
data: []
}
}
const actions = {
['getMenuNav']({ commit, state }, config) {
state.loading = true
return new Promise((resolve, reject) => {
menuNav().then(response => {
// console.log(mock);
commit('setMenuNav', mock)
state.loading = false
resolve()
}).catch(error => {
state.loading = false
reject(error)
})
})
},
}
const mutations = {
['setMenuNav'](state, payload) {
state.menuNav = {
data: payload
}
}
}
const getters = {
['getMenuNav'](state) {
return state.menuNav;
},
['loading'](state) {
return state.loading;
},
}
export default {
namespaced: true,
state,
actions,
mutations,
getters
}