dingxin 6 年之前
父節點
當前提交
037f527fe0
共有 19 個檔案被更改,包括 236 行新增114 行删除
  1. 5
    1
      CODE/smart-community/operate-api/src/main/java/com/community/huiju/dao/ToUserMapper.java
  2. 31
    1
      CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ToUserServerImpl.java
  3. 6
    0
      CODE/smart-community/operate-api/src/main/java/com/community/huiju/vo/ToUserVO.java
  4. 24
    0
      CODE/smart-community/operate-api/src/main/resources/mapper/ToUserMapper.xml
  5. 0
    13
      CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/UserController.java
  6. 7
    1
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserMapper.java
  7. 0
    9
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserService.java
  8. 22
    10
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserServiceImpl.java
  9. 6
    1
      CODE/smart-community/property-api/src/main/java/com/community/huiju/vo/UserVO.java
  10. 12
    1
      CODE/smart-community/property-api/src/main/resources/mapper/UserMapper.xml
  11. 33
    3
      VUECODE/smart-operate-manage/src/permission.js
  12. 23
    29
      VUECODE/smart-operate-manage/src/router/index.js
  13. 3
    0
      VUECODE/smart-operate-manage/src/store/modules/app.js
  14. 1
    1
      VUECODE/smart-operate-manage/src/views/layout/components/Sidebar/index.vue
  15. 35
    3
      VUECODE/smart-property-manage/src/permission.js
  16. 22
    28
      VUECODE/smart-property-manage/src/router/index.js
  17. 5
    1
      VUECODE/smart-property-manage/src/store/modules/app.js
  18. 0
    11
      VUECODE/smart-property-manage/src/views/layout/components/AppMain.vue
  19. 1
    1
      VUECODE/smart-property-manage/src/views/layout/components/Sidebar/index.vue

+ 5
- 1
CODE/smart-community/operate-api/src/main/java/com/community/huiju/dao/ToUserMapper.java 查看文件

6
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.beans.factory.annotation.Autowired;
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Map;
9
 
10
 
10
 @Mapper
11
 @Mapper
11
 public interface ToUserMapper {
12
 public interface ToUserMapper {
39
      * @return
40
      * @return
40
      */
41
      */
41
     List<ToUser>  selectRole(@Param("id") Integer id);
42
     List<ToUser>  selectRole(@Param("id") Integer id);
42
-
43
+	
44
+	List<Map<String, Object>> getPermission(@Param("userId") Integer userId);
45
+    
46
+    List<Map<String, Object>> selectByPermissionList(@Param("array") List<String> parentIdList);
43
 }
47
 }

+ 31
- 1
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ToUserServerImpl.java 查看文件

4
 import com.alibaba.fastjson.JSONObject;
4
 import com.alibaba.fastjson.JSONObject;
5
 import com.beust.jcommander.internal.Maps;
5
 import com.beust.jcommander.internal.Maps;
6
 import com.community.commom.mode.ResponseBean;
6
 import com.community.commom.mode.ResponseBean;
7
+import com.community.commom.session.UserElement;
7
 import com.community.commom.utils.AccountValidatorUtil;
8
 import com.community.commom.utils.AccountValidatorUtil;
8
 import com.community.huiju.common.code.cache.AppkeyCache;
9
 import com.community.huiju.common.code.cache.AppkeyCache;
9
 import com.community.huiju.dao.ToSysRoleMapper;
10
 import com.community.huiju.dao.ToSysRoleMapper;
88
 
89
 
89
         List<ToSysRole> sysRoleList = toSysRoleMapper.selectRoleByUserId(userId);
90
         List<ToSysRole> sysRoleList = toSysRoleMapper.selectRoleByUserId(userId);
90
         toUserVO.setRoles(sysRoleList);
91
         toUserVO.setRoles(sysRoleList);
91
-
92
+        // 菜单权限
93
+        toUserVO.setPermissionList(getPermission(userId));
92
         response.addSuccess(toUserVO);
94
         response.addSuccess(toUserVO);
93
 
95
 
94
         return response;
96
         return response;
95
     }
97
     }
98
+    
99
+    /**
100
+     * 获取当前用户的权限列表
101
+     *
102
+     * @param userId
103
+     * @return
104
+     */
105
+    public List<Map<String, Object>> getPermission(Integer userId) {
106
+        List<Map<String,Object>> permissionList = new ArrayList<>();
107
+        permissionList = toUserMapper.getPermission(userId);
108
+        //构造id集合
109
+        List<String> parentIdList = new ArrayList<>();
110
+        permissionList.forEach(e -> {
111
+            parentIdList.add(e.get("parent_id").toString());
112
+        });
113
+        List<Map<String,Object>> parentPermissionList = toUserMapper.selectByPermissionList(parentIdList);
114
+        //构造权限
115
+        List<Map<String,Object>> allList = new ArrayList<>();
116
+        permissionList.stream().forEach(e -> {
117
+            allList.add(e);
118
+            parentPermissionList.stream().forEach(m -> {
119
+                if (!e.get("id").equals(m.get("id"))){
120
+                    allList.add(m);
121
+                }
122
+            });
123
+        });
124
+        return permissionList;
125
+    }
96
 
126
 
97
     @Override
127
     @Override
98
     public ResponseBean userList(String parameter) {
128
     public ResponseBean userList(String parameter) {

+ 6
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/vo/ToUserVO.java 查看文件

7
 
7
 
8
 import java.util.Date;
8
 import java.util.Date;
9
 import java.util.List;
9
 import java.util.List;
10
+import java.util.Map;
10
 
11
 
11
 /**
12
 /**
12
  * @author weiximei
13
  * @author weiximei
56
 
57
 
57
     /** 角色 **/
58
     /** 角色 **/
58
     private List<ToSysRole> roles;
59
     private List<ToSysRole> roles;
60
+    
61
+    /**
62
+     * 权限相关
63
+     */
64
+    private List<Map<String,Object>> permissionList;
59
 
65
 
60
 }
66
 }

+ 24
- 0
CODE/smart-community/operate-api/src/main/resources/mapper/ToUserMapper.xml 查看文件

256
       LEFT JOIN to_sys_role sr ON to_sys_user_role.role_id = sr.id
256
       LEFT JOIN to_sys_role sr ON to_sys_user_role.role_id = sr.id
257
       WHERE tu.id=#{id,jdbcType=INTEGER}
257
       WHERE tu.id=#{id,jdbcType=INTEGER}
258
   </select>
258
   </select>
259
+
260
+  <select id="getPermission" resultType="java.util.Map">
261
+        SELECT
262
+            r.id,
263
+            r.menu_name AS menuName,
264
+            r.menu_url AS menuUrl,
265
+            r.parent_id
266
+        FROM
267
+            to_sys_user_role t
268
+            LEFT JOIN to_sys_role_menu m ON t.role_id = m.role_id
269
+            LEFT JOIN to_sys_menu r ON m.menu_id = r.id
270
+            AND r.STATUS = 0
271
+        WHERE
272
+            t.user_id = #{userId}
273
+        GROUP BY
274
+            r.id
275
+    </select>
276
+
277
+  <select id="selectByPermissionList" resultType="java.util.Map">
278
+    SELECT id,menu_name as menuName,menu_url as menuUrl,parent_id FROM to_sys_menu WHERE id in
279
+    <foreach item="item" index="index" collection="array" open="(" separator="," close=")">
280
+      #{item}
281
+    </foreach>
282
+  </select>
259
 </mapper>
283
 </mapper>

+ 0
- 13
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/UserController.java 查看文件

154
 		return responseBean;
154
 		return responseBean;
155
 	}
155
 	}
156
 
156
 
157
-	@ApiOperation(value = "获取用户权限列表", notes = "获取用户权限列表")
158
-	@ApiImplicitParams({
159
-			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
160
-			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "Login-Type", value = "值为 web"),
161
-	})
162
-	@RequestMapping(value = "/user/permission", method = RequestMethod.GET)
163
-	public ResponseBean getPermission(HttpSession session){
164
-		ResponseBean responseBean = new ResponseBean();
165
-		UserElement userElement = getUserElement(session);
166
-		responseBean = userService.getPermission(userElement);
167
-		return responseBean;
168
-	}
169
-
170
 	@ApiOperation(value = "查看所有角色", notes = "查看所有角色")
157
 	@ApiOperation(value = "查看所有角色", notes = "查看所有角色")
171
 	@ApiImplicitParams({
158
 	@ApiImplicitParams({
172
 			@ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter" )
159
 			@ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter" )

+ 7
- 1
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserMapper.java 查看文件

53
      * @return
53
      * @return
54
      */
54
      */
55
 	List<Map<String, Object>> getPermission(@Param("userId") Integer userId,@Param("communityId") Integer communityId);
55
 	List<Map<String, Object>> getPermission(@Param("userId") Integer userId,@Param("communityId") Integer communityId);
56
-
56
+    
57
+    /**
58
+     * 获取父权限
59
+     * @param permissionList
60
+     * @return
61
+     */
62
+    List<Map<String, Object>> selectByPermissionList(@Param("array") List<String> permissionList);
57
 }
63
 }

+ 0
- 9
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserService.java 查看文件

77
      */
77
      */
78
     ResponseBean upDateStatus(String parameter,Integer userID);
78
     ResponseBean upDateStatus(String parameter,Integer userID);
79
 
79
 
80
-    
81
-    /**
82
-     * 获取当前用户的权限列表
83
-     * @param userElement
84
-     * @return
85
-     */
86
-	ResponseBean getPermission(UserElement userElement);
87
-
88
-
89
     /**
80
     /**
90
      * 获取所有角色
81
      * 获取所有角色
91
      * @param parameter
82
      * @param parameter

+ 22
- 10
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserServiceImpl.java 查看文件

10
 import com.community.commom.session.UserElement;
10
 import com.community.commom.session.UserElement;
11
 import com.community.commom.utils.BeanTools;
11
 import com.community.commom.utils.BeanTools;
12
 import com.community.huiju.dao.*;
12
 import com.community.huiju.dao.*;
13
-import com.community.huiju.dao.TaUserMapper;
14
 import com.community.huiju.dao.UserMapper;
13
 import com.community.huiju.dao.UserMapper;
15
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
14
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
16
 import com.community.commom.utils.AccountValidatorUtil;
15
 import com.community.commom.utils.AccountValidatorUtil;
17
 import com.community.huiju.common.code.cache.AppkeyCache;
16
 import com.community.huiju.common.code.cache.AppkeyCache;
18
 import com.community.huiju.model.*;
17
 import com.community.huiju.model.*;
19
 import com.community.huiju.exception.WisdomException;
18
 import com.community.huiju.exception.WisdomException;
20
-import com.community.huiju.model.*;
21
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
22
-import com.community.commom.utils.AccountValidatorUtil;
23
-import com.community.huiju.common.code.cache.AppkeyCache;
24
 import com.community.huiju.service.IUserService;
19
 import com.community.huiju.service.IUserService;
25
 import com.community.huiju.vo.UserVO;
20
 import com.community.huiju.vo.UserVO;
26
 import com.google.common.collect.Lists;
21
 import com.google.common.collect.Lists;
125
         // 查询该用户的权限
120
         // 查询该用户的权限
126
         // 获取用户权限
121
         // 获取用户权限
127
         getUserRole(user,userVO);
122
         getUserRole(user,userVO);
123
+        
124
+        // 菜单权限
125
+        userVO.setPermissionList(getPermission(userElement));
128
 
126
 
129
         responseBean.addSuccess(userVO);
127
         responseBean.addSuccess(userVO);
130
 
128
 
364
      * @param userElement
362
      * @param userElement
365
      * @return
363
      * @return
366
      */
364
      */
367
-    @Override
368
-    public ResponseBean getPermission(UserElement userElement) {
369
-        ResponseBean responseBean = new ResponseBean();
365
+    public List<Map<String, Object>> getPermission(UserElement userElement) {
370
         List<Map<String,Object>> permissionList = new ArrayList<>();
366
         List<Map<String,Object>> permissionList = new ArrayList<>();
371
         permissionList = userMapper.getPermission(userElement.getId(),userElement.getCommunityId());
367
         permissionList = userMapper.getPermission(userElement.getId(),userElement.getCommunityId());
372
-        responseBean.addSuccess(permissionList);
373
-        return responseBean;
368
+        //构造id集合
369
+        List<String> parentIdList = new ArrayList<>();
370
+        permissionList.forEach(e -> {
371
+            parentIdList.add(e.get("parent_id").toString());
372
+        });
373
+        List<Map<String,Object>> parentPermissionList = userMapper.selectByPermissionList(parentIdList);
374
+        //构造权限
375
+        List<Map<String,Object>> allList = new ArrayList<>();
376
+        permissionList.stream().forEach(e -> {
377
+            allList.add(e);
378
+            parentPermissionList.stream().forEach(m -> {
379
+                if (!e.get("id").equals(m.get("id"))){
380
+                    allList.add(m);
381
+                }
382
+            });
383
+        });
384
+        
385
+        return permissionList;
374
     }
386
     }
375
     
387
     
376
 
388
 

+ 6
- 1
CODE/smart-community/property-api/src/main/java/com/community/huiju/vo/UserVO.java 查看文件

6
 
6
 
7
 
7
 
8
 import java.util.List;
8
 import java.util.List;
9
+import java.util.Map;
9
 
10
 
10
 @Data
11
 @Data
11
 public class UserVO extends User {
12
 public class UserVO extends User {
38
      * 角色ID
39
      * 角色ID
39
      */
40
      */
40
     private String roleId;
41
     private String roleId;
41
-
42
+    
43
+    /**
44
+     * 权限相关
45
+     */
46
+    private List<Map<String,Object>> permissionList;
42
 }
47
 }

+ 12
- 1
CODE/smart-community/property-api/src/main/resources/mapper/UserMapper.xml 查看文件

111
 
111
 
112
     <select id="getPermission" resultType="java.util.Map">
112
     <select id="getPermission" resultType="java.util.Map">
113
         SELECT
113
         SELECT
114
-            t.id,r.menu_name,r.menu_url
114
+            r.id,
115
+            r.menu_name as menuName,
116
+            r.menu_url as menuUrl,
117
+            r.parent_id
115
         FROM
118
         FROM
116
             tp_sys_user_role t
119
             tp_sys_user_role t
117
             LEFT JOIN tp_sys_role_menu m ON t.role_id = m.role_id AND m.community_id = #{communityId}
120
             LEFT JOIN tp_sys_role_menu m ON t.role_id = m.role_id AND m.community_id = #{communityId}
119
         WHERE
122
         WHERE
120
             t.user_id = #{userId}
123
             t.user_id = #{userId}
121
             AND t.community_id = #{communityId}
124
             AND t.community_id = #{communityId}
125
+        GROUP BY r.id
126
+    </select>
127
+
128
+    <select id="selectByPermissionList" resultType="java.util.Map">
129
+        SELECT id,menu_name as menuName,menu_url as menuUrl,parent_id FROM tp_sys_menu WHERE id in
130
+        <foreach item="item" index="index" collection="array" open="(" separator="," close=")">
131
+        #{item}
132
+        </foreach>
122
     </select>
133
     </select>
123
 </mapper>
134
 </mapper>

+ 33
- 3
VUECODE/smart-operate-manage/src/permission.js 查看文件

1
-import router from './router'
1
+import router, { constantRouterMap, currentRouterMap } from './router'
2
 import store from './store'
2
 import store from './store'
3
 import NProgress from 'nprogress' // Progress 进度条
3
 import NProgress from 'nprogress' // Progress 进度条
4
 import 'nprogress/nprogress.css'// Progress 进度条样式
4
 import 'nprogress/nprogress.css'// Progress 进度条样式
16
     } else {
16
     } else {
17
       if (store.getters.roles.length === 0) {
17
       if (store.getters.roles.length === 0) {
18
         store.dispatch('GetInfo').then(res => { // 拉取用户信息
18
         store.dispatch('GetInfo').then(res => { // 拉取用户信息
19
-          next()
19
+          const rounterMap = []
20
+          const permissionMap = res.data.permissionList
21
+          // 构造父路由
22
+          constantRouterMap.forEach(router => {
23
+            permissionMap.forEach(permission => {
24
+              if (router.name === permission['menuUrl']) {
25
+                rounterMap.push(router)
26
+              }
27
+            })
28
+          })
29
+
30
+          // 构造子路由
31
+          rounterMap.forEach(router => {
32
+            const childMap = []
33
+            router.children.forEach(child => {
34
+              if (child.hidden) {
35
+                childMap.push(child)
36
+              }
37
+              permissionMap.forEach(permission => {
38
+                if (child.name === permission['menuUrl']) {
39
+                  childMap.push(child)
40
+                }
41
+              })
42
+            })
43
+            router.children = childMap
44
+          })
45
+
46
+          router.addRoutes(rounterMap)
47
+
48
+          store.commit('AddRoutes', currentRouterMap.concat(rounterMap))
49
+
50
+          next({ ...to, replace: true })
20
         }).catch((err) => {
51
         }).catch((err) => {
21
           store.dispatch('FedLogOut').then(() => {
52
           store.dispatch('FedLogOut').then(() => {
22
             Message.error(err || 'Verification failed, please login again')
53
             Message.error(err || 'Verification failed, please login again')
39
       NProgress.done()
70
       NProgress.done()
40
     }
71
     }
41
   }
72
   }
42
-  next()
43
 })
73
 })
44
 
74
 
45
 router.afterEach(() => {
75
 router.afterEach(() => {

+ 23
- 29
VUECODE/smart-operate-manage/src/router/index.js 查看文件

22
   }
22
   }
23
 **/
23
 **/
24
 export const constantRouterMap = [
24
 export const constantRouterMap = [
25
-  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
26
-  { path: '/404', component: () => import('@/views/404'), hidden: true },
27
-  {
28
-    path: '/dashboard',
29
-    component: Layout,
30
-    redirect: '/dashboard',
31
-    name: 'Dashboard',
32
-    hidden: true,
33
-    children: [{
34
-      path: 'dashboard',
35
-      component: () => import('@/views/dashboard/index')
36
-    }]
37
-  },
38
-
39
-  {
40
-    path: '/',
41
-    component: Layout,
42
-    redirect: '/index',
43
-    children: [
44
-      {
45
-        path: '',
46
-        component: () => import('@/views/index/index'),
47
-        name: 'index',
48
-        meta: { title: '首页', icon: 'index' }
49
-      }
50
-    ]
51
-  },
52
-
53
   {
25
   {
54
     path: '/community',
26
     path: '/community',
55
     component: Layout,
27
     component: Layout,
56
     redirect: '/conmmunity/download',
28
     redirect: '/conmmunity/download',
29
+    name: 'community-parent',
57
     alwaysShow: true,
30
     alwaysShow: true,
58
     meta: { title: '社区数据', icon: 'zip' },
31
     meta: { title: '社区数据', icon: 'zip' },
59
     children: [
32
     children: [
70
     path: '/banner',
43
     path: '/banner',
71
     component: Layout,
44
     component: Layout,
72
     redirect: '/banner/index',
45
     redirect: '/banner/index',
46
+    name: 'banner',
73
     alwaysShow: true,
47
     alwaysShow: true,
74
     meta: { title: '运营数据', icon: 'zip' },
48
     meta: { title: '运营数据', icon: 'zip' },
75
     children: [
49
     children: [
106
     path: '/account',
80
     path: '/account',
107
     component: Layout,
81
     component: Layout,
108
     redirect: '/account/index',
82
     redirect: '/account/index',
83
+    name: 'account',
109
     alwaysShow: true,
84
     alwaysShow: true,
110
     meta: { title: '账号管理', icon: 'zip' },
85
     meta: { title: '账号管理', icon: 'zip' },
111
     children: [
86
     children: [
157
         meta: { title: '添加成员', icon: 'table' }
132
         meta: { title: '添加成员', icon: 'table' }
158
       }
133
       }
159
     ]
134
     ]
135
+  }
136
+]
137
+
138
+export const currentRouterMap = [
139
+  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
140
+  { path: '/404', component: () => import('@/views/404'), hidden: true },
141
+  {
142
+    path: '/',
143
+    component: Layout,
144
+    redirect: '/index',
145
+    children: [
146
+      {
147
+        path: '',
148
+        component: () => import('@/views/index/index'),
149
+        name: 'index',
150
+        meta: { title: '首页', icon: 'index' }
151
+      }
152
+    ]
160
   },
153
   },
154
+
161
   { path: '*', redirect: '/404', hidden: true }
155
   { path: '*', redirect: '/404', hidden: true }
162
 ]
156
 ]
163
 
157
 
164
 export default new Router({
158
 export default new Router({
165
   // mode: 'history', //后端支持可开
159
   // mode: 'history', //后端支持可开
166
   scrollBehavior: () => ({ y: 0 }),
160
   scrollBehavior: () => ({ y: 0 }),
167
-  routes: constantRouterMap
161
+  routes: currentRouterMap
168
 })
162
 })

+ 3
- 0
VUECODE/smart-operate-manage/src/store/modules/app.js 查看文件

9
     device: 'desktop'
9
     device: 'desktop'
10
   },
10
   },
11
   mutations: {
11
   mutations: {
12
+    AddRoutes(state, payload) {
13
+      state.routes = payload
14
+    },
12
     TOGGLE_SIDEBAR: state => {
15
     TOGGLE_SIDEBAR: state => {
13
       if (state.sidebar.opened) {
16
       if (state.sidebar.opened) {
14
         Cookies.set('sidebarStatus', 1)
17
         Cookies.set('sidebarStatus', 1)

+ 1
- 1
VUECODE/smart-operate-manage/src/views/layout/components/Sidebar/index.vue 查看文件

25
       'sidebar'
25
       'sidebar'
26
     ]),
26
     ]),
27
     routes() {
27
     routes() {
28
-      return this.$router.options.routes
28
+      return this.$store.state.app.routes
29
     },
29
     },
30
     isCollapse() {
30
     isCollapse() {
31
       return !this.sidebar.opened
31
       return !this.sidebar.opened

+ 35
- 3
VUECODE/smart-property-manage/src/permission.js 查看文件

1
-import router from './router'
1
+import router, { constantRouterMap, currentRouterMap } from './router'
2
 import store from './store'
2
 import store from './store'
3
 import NProgress from 'nprogress' // Progress 进度条
3
 import NProgress from 'nprogress' // Progress 进度条
4
 import 'nprogress/nprogress.css'// Progress 进度条样式
4
 import 'nprogress/nprogress.css'// Progress 进度条样式
16
     } else {
16
     } else {
17
       if (store.getters.roles.length === 0) {
17
       if (store.getters.roles.length === 0) {
18
         store.dispatch('GetInfo').then(res => { // 拉取用户信息
18
         store.dispatch('GetInfo').then(res => { // 拉取用户信息
19
-          next()
19
+          const rounterMap = []
20
+          const permissionMap = res.data.permissionList
21
+          // 构造父路由
22
+          constantRouterMap.forEach(router => {
23
+            permissionMap.forEach(permission => {
24
+              if (router.name === permission['menuUrl']) {
25
+                rounterMap.push(router)
26
+              }
27
+            })
28
+          })
29
+
30
+          // 构造子路由
31
+          rounterMap.forEach(router => {
32
+            const childMap = []
33
+            router.children.forEach(child => {
34
+              if (child.hidden) {
35
+                childMap.push(child)
36
+              }
37
+              permissionMap.forEach(permission => {
38
+                if (child.name === permission['menuUrl']) {
39
+                  childMap.push(child)
40
+                }
41
+              })
42
+            })
43
+            router.children = childMap
44
+          })
45
+
46
+          router.addRoutes(rounterMap)
47
+
48
+          store.commit('AddRoutes', currentRouterMap.concat(rounterMap))
49
+
50
+          next({ ...to, replace: true })
20
         }).catch((err) => {
51
         }).catch((err) => {
21
           store.dispatch('FedLogOut').then(() => {
52
           store.dispatch('FedLogOut').then(() => {
22
             Message.error(err || 'Verification failed, please login again')
53
             Message.error(err || 'Verification failed, please login again')
35
     if (whiteList.indexOf(to.path) !== -1) {
66
     if (whiteList.indexOf(to.path) !== -1) {
36
       next()
67
       next()
37
     } else {
68
     } else {
69
+      console.log('tologin')
70
+
38
       next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
71
       next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
39
       NProgress.done()
72
       NProgress.done()
40
     }
73
     }
41
   }
74
   }
42
-  next()
43
 })
75
 })
44
 
76
 
45
 router.afterEach(() => {
77
 router.afterEach(() => {

+ 22
- 28
VUECODE/smart-property-manage/src/router/index.js 查看文件

22
   }
22
   }
23
 **/
23
 **/
24
 export const constantRouterMap = [
24
 export const constantRouterMap = [
25
-  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
26
-  { path: '/404', component: () => import('@/views/404'), hidden: true },
27
-  {
28
-    path: '/dashboard',
29
-    component: Layout,
30
-    redirect: '/dashboard',
31
-    name: 'Dashboard',
32
-    hidden: true,
33
-    children: [{
34
-      path: 'dashboard',
35
-      component: () => import('@/views/dashboard/index')
36
-    }]
37
-  },
38
-
39
-  {
40
-    path: '/',
41
-    component: Layout,
42
-    redirect: '/index',
43
-    children: [
44
-      {
45
-        path: '',
46
-        component: () => import('@/views/index/index'),
47
-        name: 'index',
48
-        meta: { title: '首页', icon: 'index' }
49
-      }
50
-    ]
51
-  },
52
   {
25
   {
53
     path: '/building',
26
     path: '/building',
54
     component: Layout,
27
     component: Layout,
55
     redirect: '/building/index',
28
     redirect: '/building/index',
29
+    name: 'building',
56
     alwaysShow: true,
30
     alwaysShow: true,
57
     meta: { title: '业主/楼栋', icon: 'zip' },
31
     meta: { title: '业主/楼栋', icon: 'zip' },
58
     children: [
32
     children: [
95
     path: '/social',
69
     path: '/social',
96
     component: Layout,
70
     component: Layout,
97
     redirect: '/social/index',
71
     redirect: '/social/index',
72
+    name: 'social',
98
     alwaysShow: true,
73
     alwaysShow: true,
99
     meta: { title: '论坛内容', icon: 'zip' },
74
     meta: { title: '论坛内容', icon: 'zip' },
100
     children: [
75
     children: [
178
     path: '/account',
153
     path: '/account',
179
     component: Layout,
154
     component: Layout,
180
     redirect: '/account/index',
155
     redirect: '/account/index',
156
+    name: 'account',
181
     alwaysShow: true,
157
     alwaysShow: true,
182
     meta: { title: '账号管理', icon: 'zip' },
158
     meta: { title: '账号管理', icon: 'zip' },
183
     children: [
159
     children: [
229
         meta: { title: '编辑成员', icon: 'table' }
205
         meta: { title: '编辑成员', icon: 'table' }
230
       }
206
       }
231
     ]
207
     ]
208
+  }
209
+]
210
+
211
+export const currentRouterMap = [
212
+  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
213
+  { path: '/404', component: () => import('@/views/404'), hidden: true },
214
+  {
215
+    path: '/',
216
+    component: Layout,
217
+    redirect: '/index',
218
+    children: [
219
+      {
220
+        path: '',
221
+        component: () => import('@/views/index/index'),
222
+        name: 'index',
223
+        meta: { title: '首页', icon: 'index' }
224
+      }
225
+    ]
232
   },
226
   },
233
 
227
 
234
   { path: '*', redirect: '/404', hidden: true }
228
   { path: '*', redirect: '/404', hidden: true }
237
 export default new Router({
231
 export default new Router({
238
   // mode: 'history', //后端支持可开
232
   // mode: 'history', //后端支持可开
239
   scrollBehavior: () => ({ y: 0 }),
233
   scrollBehavior: () => ({ y: 0 }),
240
-  routes: constantRouterMap
234
+  routes: currentRouterMap
241
 })
235
 })

+ 5
- 1
VUECODE/smart-property-manage/src/store/modules/app.js 查看文件

6
       opened: !+Cookies.get('sidebarStatus'),
6
       opened: !+Cookies.get('sidebarStatus'),
7
       withoutAnimation: false
7
       withoutAnimation: false
8
     },
8
     },
9
-    device: 'desktop'
9
+    device: 'desktop',
10
+    routes: [],
10
   },
11
   },
11
   mutations: {
12
   mutations: {
13
+    AddRoutes(state, payload) {
14
+      state.routes = payload
15
+    },
12
     TOGGLE_SIDEBAR: state => {
16
     TOGGLE_SIDEBAR: state => {
13
       if (state.sidebar.opened) {
17
       if (state.sidebar.opened) {
14
         Cookies.set('sidebarStatus', 1)
18
         Cookies.set('sidebarStatus', 1)

+ 0
- 11
VUECODE/smart-property-manage/src/views/layout/components/AppMain.vue 查看文件

15
     // key() {
15
     // key() {
16
     //   return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date()
16
     //   return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date()
17
     // }
17
     // }
18
-  },
19
-  created() {
20
-    this.$store.dispatch('GetPermission').then((res) => {
21
-      if (res.code === '0') {
22
-        alert(1)
23
-      } else {
24
-        this.$message.error(res.message)
25
-      }
26
-    }).catch(() => {
27
-        this.$message.error(res.message)
28
-    })
29
   }
18
   }
30
 }
19
 }
31
 </script>
20
 </script>

+ 1
- 1
VUECODE/smart-property-manage/src/views/layout/components/Sidebar/index.vue 查看文件

25
       'sidebar'
25
       'sidebar'
26
     ]),
26
     ]),
27
     routes() {
27
     routes() {
28
-      return this.$router.options.routes
28
+      return this.$store.state.app.routes
29
     },
29
     },
30
     isCollapse() {
30
     isCollapse() {
31
       return !this.sidebar.opened
31
       return !this.sidebar.opened