许成详 6 년 전
부모
커밋
79f247204f
6개의 변경된 파일186개의 추가작업 그리고 155개의 파일을 삭제
  1. 2
    1
      src/components/breadCrumb/index.vue
  2. 3
    3
      src/components/siderBar/index.vue
  3. 2
    0
      src/main.js
  4. 168
    113
      src/pages/system/index.vue
  5. 4
    7
      src/router/index.js
  6. 7
    31
      src/store/app.js

+ 2
- 1
src/components/breadCrumb/index.vue 파일 보기

@@ -3,7 +3,8 @@
3 3
     <span>当前页面路径:</span>
4 4
     <el-breadcrumb separator="/">
5 5
       <el-breadcrumb-item v-for="(item,index) in list" :key="index">
6
-        <router-link :to="{name:item.pathName,query:{}}">{{item.title}}</router-link>
6
+        <router-link v-if="index==0" :to="{name:'',query:{}}">{{item.MenuName}}</router-link>
7
+        <router-link v-if="index!=0" :to="{name:item.Url,query:{}}">{{item.MenuName}}</router-link>
7 8
       </el-breadcrumb-item>
8 9
     </el-breadcrumb>
9 10
   </div>

+ 3
- 3
src/components/siderBar/index.vue 파일 보기

@@ -10,16 +10,16 @@
10 10
           <template v-for="(item,index) in menu">
11 11
             <el-submenu v-if="item.children.length" :index="String(index)" :key="index">
12 12
               <template slot="title">
13
-                <span>{{item.title}}</span>
13
+                <span>{{item.MenuName}}</span>
14 14
               </template>
15 15
               <el-menu-item-group>
16 16
                 <el-menu-item v-for="(subItem,subIndex) in item.children" :key="subIndex" :index="String(index)+'-'+String(subIndex)">
17
-                  <router-link :to="{name:subItem.pathName,query:{}}" active-class="active">{{subItem.title}}</router-link>
17
+                  <router-link :to="{name:subItem.Url,query:{}}" active-class="active">{{subItem.MenuName}}</router-link>
18 18
                 </el-menu-item>
19 19
               </el-menu-item-group>
20 20
             </el-submenu>
21 21
             <el-menu-item v-else :index="String(index)" :key="index">
22
-              <span slot="title">{{item.title}}</span>
22
+              <span slot="title">{{item.MenuName}}</span>
23 23
             </el-menu-item>
24 24
           </template>
25 25
         </el-menu>

+ 2
- 0
src/main.js 파일 보기

@@ -11,10 +11,12 @@ import router from './router'
11 11
 import Ajax from './util/ajax'
12 12
 import api from './util/api'
13 13
 import store from './store'
14
+import Vuex from 'vuex'
14 15
 
15 16
 Vue.use(ElementUI)
16 17
 Vue.use(Cookies)
17 18
 Vue.use(VueAMap)
19
+Vue.use(Vuex)
18 20
 
19 21
 VueAMap.initAMapApiLoader({
20 22
   key: 'f0d1d4f82432504003ebf46e5e36ff03',

+ 168
- 113
src/pages/system/index.vue 파일 보기

@@ -30,132 +30,187 @@
30 30
 <script>
31 31
 import breadCrumb from '@/components/breadCrumb/index'
32 32
 import siderBar from '@/components/siderBar/index'
33
+import routerData from '@/router/router'
34
+
35
+import { mapState, mapMutations } from 'vuex'
33 36
 
34 37
 export default {
35 38
   name: '',
36 39
   data () {
37 40
     return {
38
-      breadCrumb: [{
39
-        title: '导航1',
40
-        pathName: ''
41
-      }, {
42
-        title: '导航2',
43
-        pathName: ''
44
-      }, {
45
-        title: '导航3',
46
-        pathName: ''
47
-      }, {
48
-        title: '导航4',
49
-        pathName: ''
50
-      }, {
51
-        title: '导航5',
52
-        pathName: ''
53
-      }],
54
-      pageMenu: [{
55
-        title: '系统设置',
56
-        pathName: '',
57
-        children: [{
58
-          title: '用户管理',
59
-          pathName: 'userManager',
60
-          children: [],
61
-        }, {
62
-          title: '角色管理',
63
-          pathName: 'roleManager',
64
-          children: [],
65
-        }],
66
-      }, {
67
-        title: '案场管理',
68
-        pathName: '',
69
-        children: [{
70
-          title: '案场信息',
71
-          pathName: 'caseInfo',
72
-          children: [],
73
-        }, {
74
-          title: '钥匙管理',
75
-          pathName: 'keyManager',
76
-          children: [],
77
-        }, {
78
-          title: '案场区域管理',
79
-          pathName: 'caseAreaManager',
80
-          children: [],
81
-        }, {
82
-          title: '案场桌位管理',
83
-          pathName: 'caseTableManager',
84
-          children: [],
85
-        }],
86
-      }, {
87
-        title: '商品管理',
88
-        pathName: '',
89
-        children: [{
90
-          title: '商品类型管理',
91
-          pathName: 'goodsTypeManager',
92
-          children: [],
93
-        }, {
94
-          title: '商品规格管理',
95
-          pathName: 'goodsSpecManager',
96
-          children: [],
97
-        }],
98
-      }, {
99
-        title: 'CMS管理',
100
-        pathName: '',
101
-        children: [{
102
-          title: '轮播图管理',
103
-          pathName: 'bannerManager',
104
-          children: [],
105
-        }, {
106
-          title: '售楼处项目专题',
107
-          pathName: 'majorProjects',
108
-          children: [],
109
-        }, {
110
-          title: '首页消息',
111
-          pathName: 'indexMsg',
112
-          children: [],
113
-        }, {
114
-          title: '资讯管理',
115
-          pathName: 'newsManager',
116
-          children: [],
117
-        }],
118
-      }, {
119
-        title: '渠道管理',
120
-        pathName: '',
121
-        children: [{
122
-          title: '渠道列表',
123
-          pathName: 'channelList',
124
-          children: [],
125
-        }],
126
-      }, {
127
-        title: '课程管理',
128
-        pathName: '',
129
-        children: [{
130
-          title: '全龄生活5A',
131
-          pathName: 'fiveA',
132
-          children: [],
133
-        }, {
134
-          title: '课程标签',
135
-          pathName: 'courseTag',
136
-          children: [],
137
-        }],
138
-      }, {
139
-        title: '数据统计',
140
-        pathName: '',
141
-        children: [{
142
-          title: '前台用户列表',
143
-          pathName: 'frontEndUserList',
144
-          children: [],
145
-        }],
146
-      }]
41
+      pageMenu: [
42
+        // {
43
+        //   title: '系统设置',
44
+        //   pathName: '',
45
+        //   children: [{
46
+        //     title: '用户管理',
47
+        //     pathName: 'userManager',
48
+        //     children: [],
49
+        //   }, {
50
+        //     title: '角色管理',
51
+        //     pathName: 'roleManager',
52
+        //     children: [],
53
+        //   }],
54
+        // }, {
55
+        //   title: '案场管理',
56
+        //   pathName: '',
57
+        //   children: [{
58
+        //     title: '案场信息',
59
+        //     pathName: 'caseInfo',
60
+        //     children: [],
61
+        //   }, {
62
+        //     title: '钥匙管理',
63
+        //     pathName: 'keyManager',
64
+        //     children: [],
65
+        //   }, {
66
+        //     title: '案场区域管理',
67
+        //     pathName: 'caseAreaManager',
68
+        //     children: [],
69
+        //   }, {
70
+        //     title: '案场桌位管理',
71
+        //     pathName: 'caseTableManager',
72
+        //     children: [],
73
+        //   }],
74
+        // }, {
75
+        //   title: '商品管理',
76
+        //   pathName: '',
77
+        //   children: [{
78
+        //     title: '商品类型管理',
79
+        //     pathName: 'goodsTypeManager',
80
+        //     children: [],
81
+        //   }, {
82
+        //     title: '商品规格管理',
83
+        //     pathName: 'goodsSpecManager',
84
+        //     children: [],
85
+        //   }],
86
+        // }, {
87
+        //   title: 'CMS管理',
88
+        //   pathName: '',
89
+        //   children: [{
90
+        //     title: '轮播图管理',
91
+        //     pathName: 'bannerManager',
92
+        //     children: [],
93
+        //   }, {
94
+        //     title: '售楼处项目专题',
95
+        //     pathName: 'majorProjects',
96
+        //     children: [],
97
+        //   }, {
98
+        //     title: '首页消息',
99
+        //     pathName: 'indexMsg',
100
+        //     children: [],
101
+        //   }, {
102
+        //     title: '资讯管理',
103
+        //     pathName: 'newsManager',
104
+        //     children: [],
105
+        //   }],
106
+        // }, {
107
+        //   title: '渠道管理',
108
+        //   pathName: '',
109
+        //   children: [{
110
+        //     title: '渠道列表',
111
+        //     pathName: 'channelList',
112
+        //     children: [],
113
+        //   }],
114
+        // }, {
115
+        //   title: '课程管理',
116
+        //   pathName: '',
117
+        //   children: [{
118
+        //     title: '全龄生活5A',
119
+        //     pathName: 'fiveA',
120
+        //     children: [],
121
+        //   }, {
122
+        //     title: '课程标签',
123
+        //     pathName: 'courseTag',
124
+        //     children: [],
125
+        //   }],
126
+        // }, {
127
+        //   title: '数据统计',
128
+        //   pathName: '',
129
+        //   children: [{
130
+        //     title: '前台用户列表',
131
+        //     pathName: 'frontEndUserList',
132
+        //     children: [],
133
+        //   }],
134
+        // }
135
+      ]
147 136
     }
148 137
   },
138
+  computed: {
139
+    ...mapState({
140
+      breadCrumb: x => x.app.breadcrumb,
141
+    })
142
+  },
149 143
   components: {
150 144
     breadCrumb,
151 145
     siderBar,
152 146
   },
147
+  created () {
148
+    this.getMenuData()
149
+    this.updateBread({ routerData, Url: this.$route.name })
150
+  },
153 151
   methods: {
154
-    calcMenuData () {
155
-      console.log()
152
+    ...mapMutations([
153
+      'updateBread',
154
+    ]),
155
+    getMenuData () { // 获取用户角色权限内菜单
156
+      let menuData = [{
157
+        MenuId: '1',
158
+        MenuName: '系统',
159
+        Icon: '',
160
+        FatherID: '-1',
161
+        Url: 'system',
162
+        IsShow: 1
163
+      }, {
164
+        MenuId: '2',
165
+        MenuName: '系统设置',
166
+        Icon: '',
167
+        FatherID: '1',
168
+        Url: 'systemSet',
169
+        IsShow: 1
170
+      }, {
171
+        MenuId: '3',
172
+        MenuName: '用户管理',
173
+        Icon: '',
174
+        FatherID: '2',
175
+        Url: 'userManager',
176
+        IsShow: 1
177
+      }, {
178
+        MenuId: '4',
179
+        MenuName: '角色管理',
180
+        Icon: '',
181
+        FatherID: '2',
182
+        Url: 'roleManager',
183
+        IsShow: 1
184
+      }, {
185
+        MenuId: '5',
186
+        MenuName: '新增用户',
187
+        Icon: '',
188
+        FatherID: '3',
189
+        Url: 'addUser',
190
+        IsShow: 0
191
+      }, {
192
+        MenuId: '6',
193
+        MenuName: '编辑用户',
194
+        Icon: '',
195
+        FatherID: '3',
196
+        Url: 'editUser',
197
+        IsShow: 0
198
+      }]
199
+      this.$store.state.app.menusRaw = menuData // 写入权限菜单数据
200
+      this.creatSlideMenu([...menuData])
201
+    },
202
+    creatSlideMenu (arr) { // 创建左侧菜单
203
+      for (var n = 0; n < arr.length; n++) {
204
+        arr[n].children = []
205
+        for (var a = 0; a < arr.length; a++) {
206
+          if (arr[n].MenuId === arr[a].FatherID) {
207
+            arr[n].children.push(arr[a])
208
+          }
209
+        }
210
+      }
211
+      this.pageMenu = arr[0].children
156 212
     }
157
-  },
158
-  mounted () { }
213
+  }
159 214
 }
160 215
 </script>
161 216
 

+ 4
- 7
src/router/index.js 파일 보기

@@ -6,10 +6,9 @@ import store from './../store/index'
6 6
 Vue.use(Router)
7 7
 
8 8
 const flatten = (parent, data) => {
9
-  console.log(parent)
10
-  return data.reduce((acc, { path, name, component, title, children }) => {
9
+  return data.reduce((acc, { path, name, component, MenuName, children }) => {
11 10
     const pth = [parent, path].join('/').replace('//', '/')
12
-    const item = { path: pth, name, component, title, children: [] }
11
+    const item = { path: pth, name, component, MenuName, children: [] }
13 12
 
14 13
     if (children && children.length) {
15 14
       return acc.concat(item, flatten(pth, children))
@@ -24,21 +23,19 @@ const routes = routerData.reduce((acc, r) => {
24 23
   const { children, ...rest } = r
25 24
 
26 25
   if (children && children.length) {
27
-    return acc.concat({ ...rest, children: flatten([], children) })
26
+    return acc.concat({ ...rest, children: flatten('', children) })
28 27
   }
29 28
 
30 29
   return acc.concat(r)
31 30
 }, [])
32 31
 
33
-// console.log(routes)
34
-
35 32
 const router = new Router({
36 33
   routes,
37 34
   linkActiveClass: 'active',
38 35
 })
39 36
 
40 37
 router.beforeEach((to, from, next) => {
41
-  store.commit('updateBread', { routerData, name: to.name })
38
+  store.commit('updateBread', { routerData, Url: to.name })
42 39
   next()
43 40
 })
44 41
 

+ 7
- 31
src/store/app.js 파일 보기

@@ -1,15 +1,14 @@
1 1
 
2 2
 function flatten (parent, data = [], menusRaw = []) {
3
-  console.log(parent)
4 3
   return data.reduce((acc, { name, children }) => {
5 4
     const menu = menusRaw.filter(x => x.Url === name)[0]
6 5
     if (!menu) return acc
7 6
 
8
-    const title = menu.MenuName
9
-    const item = { name, title, parent }
7
+    const MenuName = menu.MenuName
8
+    const item = { Url: name, MenuName, parent }
10 9
 
11 10
     if (children && children.length) {
12
-      const p = parent.concat({ name, title })
11
+      const p = parent.concat({ Url: name, MenuName })
13 12
       return acc.concat(item, flatten(p, children, menusRaw))
14 13
     }
15 14
 
@@ -19,44 +18,21 @@ function flatten (parent, data = [], menusRaw = []) {
19 18
 
20 19
 export default {
21 20
   state: {
22
-    menusRaw: [{
23
-      MenuId: '1',
24
-      MenuName: '菜单1',
25
-      Icon: 'menu1',
26
-      FatherID: '-1',
27
-      Url: 'system',
28
-      IsShow: 1
29
-    }, {
30
-      MenuId: '2',
31
-      MenuName: '菜单1-1',
32
-      Icon: 'menu2',
33
-      FatherID: '1',
34
-      Url: 'systemSet',
35
-      IsShow: 1
36
-    }, {
37
-      MenuId: '3',
38
-      MenuName: '菜单1-1-1',
39
-      Icon: '',
40
-      FatherID: '2',
41
-      Url: 'userManager',
42
-      IsShow: 1
43
-    }],
21
+    menusRaw: [],
44 22
     menus: [],
45 23
     breadcrumb: [],
46 24
   },
47 25
   mutations: {
48
-    updateBread (state, { routerData, name }) {
26
+    updateBread (state, { routerData, Url }) {
49 27
       // 扁平 routerData
50 28
       // 同时构造出 含有 title 的 parent 数据
51 29
       const routeList = flatten([], routerData, state.menusRaw)
52 30
 
53 31
       // 过滤出与 name 相同的 route 节点
54
-      const currentRoute = routeList.filter(x => x.name === name)[0]
55
-
56
-      // console.log(currentRoute, routeList, routerData, state.menusRaw)
32
+      const currentRoute = routeList.filter(x => x.Url === Url)[0]
57 33
 
58 34
       // 获取 面包屑
59
-      state.breadcrumb = currentRoute.parent
35
+      if (currentRoute) state.breadcrumb = currentRoute.parent.slice(1).concat(currentRoute)
60 36
     }
61 37
   }
62 38
 }