How to solve the permission problem in the grain online education project

1. First, after all the front and back ends are copied and integrated, then modify the database path

2. Modify the routing path in the previous uindex.js

3. The permission is unsuccessfully displayed because there is no key data in the database table acl_role_permission,
that is, the current role permission must have a data whose permission_id is 1. It is as shown in the figure below: after
each role has added relevant permissions, one more piece of data with permission_id of 1 must be added. If not, the menu cannot be displayed.

Insert picture description here
Specific code:
1. Front end, add this code in acl/role.js

      save2(roleId) {
    
    
        return request({
    
    
          url: `${
     
     api_name}/save2`,
          method: 'post',
          params: {
    
    roleId}
        })
      }, 

2. In the views/acl/role/roleForm.vue page

     //插入该角色id附属permission_id=1,固定值,否则菜单不会出现
      saveData() {
    
    
         roleApi.save2(this.roleId).then(
         response =>{
    
    
              if(response.success){
    
    
                this.saveData()
               }
           })
      } 

3. Add another line of method call:
Insert picture description here

4. Backend:

//新增加一个角色信息
@PostMapping("save2")
public R save2(@RequestParam String roleId) {
    
    
    rolePerService.save2(roleId);
    return R.ok();
}
//新增加一个角色信息
void save2(String roleId);
public void save2(String roleId) {
    
    
    QueryWrapper<RolePermission> wrapper=new QueryWrapper<RolePermission>();
    RolePermission r=new RolePermission();
    r.setPermissionId("1");
    r.setRoleId(roleId);
    System.out.println(r);
    QueryWrapper<RolePermission> wrapper2=new QueryWrapper<RolePermission>();
    wrapper2.eq("permission_id",1);
    wrapper2.eq("role_id",roleId);
    RolePermission selectOne = baseMapper.selectOne(wrapper2);
    if(selectOne==null){
    
    
        baseMapper.insert(r);
    }
}

Guess you like

Origin blog.csdn.net/qq_34134299/article/details/109307716