lrf402788946 4 anni fa
parent
commit
4b4ff4af01
1 ha cambiato i file con 16 aggiunte e 1 eliminazioni
  1. 16 1
      app/service/role.js

+ 16 - 1
app/service/role.js

@@ -14,6 +14,18 @@ class RoleService extends CrudService {
     this.Menumodel = this.ctx.model.Menu;
   }
 
+  async update(data) {
+    const { menu, id } = data;
+    // 将有子目录的目录删除掉,保存
+    let haveChild = await this.Menumodel.find({ _id: menu.map(i => ObjectId(i)) });
+    haveChild = JSON.parse(JSON.stringify(haveChild));
+    //  过滤出子目录是父级目录的目录项
+    const nmenu = haveChild.filter(f => !haveChild.find(cf => cf.pid === f._id));
+    data.menu = nmenu.map(i => i._id);
+    const res = await this.model.update({ _id: id }, data);
+    return res;
+
+  }
   async getRoleMenuTree({ project, type, userid }) {
     assert(project, '缺少需要查找的项目信息');
     assert(type, '缺少需要查找角色代码');
@@ -21,8 +33,9 @@ class RoleService extends CrudService {
     const res = await this.model.findOne({ project, type });
     if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定角色');
     let { menu } = res;
+    // console.log(res);
     const object = {};
-    // 找到用户的角色对应的权限
+    // // 找到用户的角色对应的权限
     let roleMenu = await this.Menumodel.find({ project }).sort({ sort: -1 });
     if (roleMenu.length > 0) {
       // 将用户角色部分得到权限限制住,不允许改,必须有
@@ -32,6 +45,7 @@ class RoleService extends CrudService {
         if (menu.includes(_id)) i.disabled = true;
         return i;
       });
+      // 需要查看所有有子目录的目录,子目录disabled是否全为true,全为true,则他自己也是true,否则不用变
       // 整理成树状图格式
       roleMenu = await this.ctx.service.menu.toFindChildren(roleMenu);
     }
@@ -47,6 +61,7 @@ class RoleService extends CrudService {
     object.selected = menu;
     return object;
   }
+
 }
 
 module.exports = RoleService;