فهرست منبع

增加权限查询方法

liuyu 5 سال پیش
والد
کامیت
d71ee933ac
3فایلهای تغییر یافته به همراه23 افزوده شده و 0 حذف شده
  1. 5 0
      app/controller/user.js
  2. 3 0
      app/router.js
  3. 15 0
      app/service/user.js

+ 5 - 0
app/controller/user.js

@@ -17,6 +17,11 @@ class UserController extends Controller {
     const res = await this.service.uppasswd(this.ctx.request.body);
     this.ctx.ok({ data: res });
   }
+
+  async querymenus() {
+    const res = await this.service.querymenus(this.ctx.query);
+    this.ctx.ok({ data: res });
+  }
 }
 
 module.exports = CrudController(UserController, meta);

+ 3 - 0
app/router.js

@@ -7,6 +7,9 @@ module.exports = app => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
 
+  // 取得用户权限列表
+  router.get('/api/auth/user/menus', controller.user.querymenus);
+
   // 权限表设置路由
   router.resources('role', '/api/auth/role', controller.role); // index、create、show、destroy
   router.post('role', '/api/auth/role/update/:id', controller.role.update);

+ 15 - 0
app/service/user.js

@@ -91,6 +91,21 @@ class UserService extends CrudService {
     await user.save();
   }
 
+  async querymenus({ id }) {
+    const user = await this.model.findById(id);
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    const _menus = [];
+    for (const elm of user.menus) {
+      const _menu = await this.rmodel.findById({ _id: ObjectId(elm) });
+      if (_menu) {
+        _menus.push({ id: elm, role_name: _menu.role_name, url: _menu.url });
+      }
+    }
+    return { id, menus: _menus };
+  }
+
 }
 
 module.exports = UserService;