|
@@ -1,76 +0,0 @@
|
1
|
|
-
|
2
|
|
-const packChildren = (data) => {
|
3
|
|
- // for (var x = 0; x < arr.length; x++) {
|
4
|
|
- // if (arr[x].FatherId === '-1') {
|
5
|
|
- // arr[x].FatherId = 'root'
|
6
|
|
- // }
|
7
|
|
- // }
|
8
|
|
- // arr.unshift({
|
9
|
|
- // MenuId: 'root',
|
10
|
|
- // MenuName: '根目录',
|
11
|
|
- // Icon: '',
|
12
|
|
- // FatherID: '-1',
|
13
|
|
- // Url: 'system',
|
14
|
|
- // IsShow: 1
|
15
|
|
- // })
|
16
|
|
- // console.log(JSON.stringify(arr))
|
17
|
|
- // for (var n = 0; n < arr.length; n++) {
|
18
|
|
- // arr[n].children = []
|
19
|
|
- // for (var a = 0; a < arr.length; a++) {
|
20
|
|
- // if (arr[n].MenuId === arr[a].FatherId) {
|
21
|
|
- // arr[n].children.push(arr[a])
|
22
|
|
- // }
|
23
|
|
- // }
|
24
|
|
- // }
|
25
|
|
- // console.log(JSON.stringify(arr))
|
26
|
|
- // return arr[0].children
|
27
|
|
-
|
28
|
|
- let cp = data.slice()
|
29
|
|
- const res = []
|
30
|
|
-
|
31
|
|
- data.forEach((it, inx) => {
|
32
|
|
- let found = false
|
33
|
|
- for (let i = 0; i < cp.length; i += 1) {
|
34
|
|
- if (cp[i].MenuId === it.FatherId) {
|
35
|
|
- found = true
|
36
|
|
- cp[i].children = [...(cp[i].children || []), cp[inx]]
|
37
|
|
- break
|
38
|
|
- }
|
39
|
|
- }
|
40
|
|
-
|
41
|
|
- if (!found) {
|
42
|
|
- res.push(cp[inx])
|
43
|
|
- }
|
44
|
|
- })
|
45
|
|
-
|
46
|
|
- return res
|
47
|
|
-}
|
48
|
|
-
|
49
|
|
-export default {
|
50
|
|
- namespaced: true,
|
51
|
|
- state: {
|
52
|
|
- cases: [],
|
53
|
|
- menus: [],
|
54
|
|
- roles: [],
|
55
|
|
- user: {}
|
56
|
|
- },
|
57
|
|
- mutations: {
|
58
|
|
- init (state, data) { // 这里的state对应着上面这个state
|
59
|
|
- state.cases = data.cases
|
60
|
|
- state.menusRaw = data.menus
|
61
|
|
- state.roles = data.roles
|
62
|
|
- state.user = data.user
|
63
|
|
- state.menus = packChildren(data.menus)
|
64
|
|
- }
|
65
|
|
- },
|
66
|
|
- actions: {
|
67
|
|
- updateSystemInfo (context) { // 这里的context和我们使用的$store拥有相同的对象和方法
|
68
|
|
- this.$ajax(this.$api.system.init.url, {
|
69
|
|
- method: this.$api.system.init.method
|
70
|
|
- })
|
71
|
|
- .then(res => {
|
72
|
|
- context.commit('init', res)
|
73
|
|
- })
|
74
|
|
- }
|
75
|
|
- }
|
76
|
|
-}
|