| | |
| | | |
| | | //表头按钮 |
| | | toolbarConfig: { |
| | | buttons: [ |
| | | |
| | | ], |
| | | slots:{ |
| | | buttons: "toolbar_buttons" |
| | | buttons: "toolbar_buttons", |
| | | tools:'save_buttons' |
| | | |
| | | }, |
| | | buttons: [ |
| | | ], |
| | | zoom: true, |
| | | custom: true |
| | | }, |
| | |
| | | getPermissionList() |
| | | } |
| | | |
| | | const saveBatch = () => { |
| | | const $grid = pGrid.value |
| | | if($grid.getCheckboxRecords().length === 0){ |
| | | ElMessage.warning("请先选择权限") |
| | | return |
| | | } |
| | | ElMessageBox.confirm( |
| | | '确认修改角色权限?', |
| | | 'Warning', |
| | | { |
| | | confirmButtonText: '确认', |
| | | cancelButtonText: '取消', |
| | | type: 'warning', |
| | | } |
| | | ).then(() => { |
| | | const permission = { |
| | | id: checkId.value, |
| | | detail: $grid.getCheckboxRecords() |
| | | } |
| | | request.post(`/permissionRole/savePermissionRole`,permission).then(res=>{ |
| | | if(res.data=== true && res.code==='200'){ |
| | | ElMessage.success('保存成功') |
| | | dialogVisible.value = false |
| | | getPermissionList() |
| | | }else{ |
| | | ElMessage.error('保存失败') |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | </script> |
| | | |
| | | <template> |
| | |
| | | @change="selectChange" |
| | | /> |
| | | </template> |
| | | <template #save_buttons> |
| | | <vxe-button |
| | | @click="saveBatch" |
| | | status='primary' |
| | | style="margin-right: 1rem" |
| | | >新增</vxe-button> |
| | | </template> |
| | | |
| | | </vxe-grid> |
| | | |
| | |
| | | this.permissionBasicService = permissionBasicService; |
| | | } |
| | | |
| | | @PostMapping("getPermission/{userId}/{lang}") |
| | | public Result getPermission(@PathVariable Integer userId,@PathVariable String lang, @RequestBody List<Integer> selectPageId){ |
| | | return Result.seccess(permissionBasicService.getPermission(userId,lang,selectPageId)); |
| | | @PostMapping("getPermission/{roleId}/{lang}") |
| | | public Result getPermission(@PathVariable Integer roleId,@PathVariable String lang, @RequestBody List<Integer> selectPageId){ |
| | | return Result.seccess(permissionBasicService.getPermission(roleId,lang,selectPageId)); |
| | | } |
| | | |
| | | @PostMapping("getPermissionList/{lang}") |
New file |
| | |
| | | package com.example.erp.controller.userInfo; |
| | | |
| | | import com.example.erp.common.Result; |
| | | import com.example.erp.service.userInfo.PermissionRoleService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @RequestMapping("/permissionRole") |
| | | public class PermissionRoleController { |
| | | private final PermissionRoleService permissionRoleService; |
| | | |
| | | public PermissionRoleController(PermissionRoleService permissionRoleService) { |
| | | this.permissionRoleService = permissionRoleService; |
| | | } |
| | | |
| | | @RequestMapping("/savePermissionRole") |
| | | public Result savePermissionRole(@RequestBody Map<String, Object> permissionRole) { |
| | | return Result.seccess(permissionRoleService.savePermissionRole(permissionRole)); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | @Mapper |
| | | public interface PermissionBasicMapper extends BaseMapper<PermissionBasic> { |
| | | List<PermissionBasic> getPermission(Integer userId, String lang, Integer id); |
| | | List<PermissionBasic> getPermission(Integer roleId, String lang, Integer id); |
| | | |
| | | List<PermissionBasic> selectOneLevel(String lang); |
| | | |
| | |
| | | @Mapper |
| | | public interface PermissionRoleMapper extends BaseMapper<PermissionRole> { |
| | | List<String> getUserPermission(Integer loginId); |
| | | |
| | | Boolean saveBatch(List<PermissionRole> permissionRoles); |
| | | } |
| | |
| | | this.permissionBasicMapper = permissionBasicMapper; |
| | | } |
| | | |
| | | public List<PermissionBasic> getPermission(Integer userId, String lang, List<Integer> selectPageId) { |
| | | return permissionBasicMapper.getPermission(userId,lang, selectPageId.get(1)); |
| | | public List<PermissionBasic> getPermission(Integer roleId, String lang, List<Integer> selectPageId) { |
| | | return permissionBasicMapper.getPermission(roleId,lang, selectPageId.get(1)); |
| | | } |
| | | |
| | | public Object getPermissionList(String lang) { |
| | |
| | | package com.example.erp.service.userInfo; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.entity.userInfo.PermissionBasic; |
| | | import com.example.erp.entity.userInfo.PermissionRole; |
| | | import com.example.erp.mapper.userInfo.PermissionRoleMapper; |
| | | import com.example.erp.mapper.userInfo.UserMapper; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @DS("user_info") |
| | | @Service |
| | |
| | | public List<String> getUserRole(Integer id) { |
| | | return userMapper.getUserRole(id); |
| | | } |
| | | |
| | | public Boolean savePermissionRole(Map<String, Object> permissionRoleMap) { |
| | | JSONObject permissionRoleJson = new JSONObject(permissionRoleMap); |
| | | List<PermissionBasic> permissionBasics = |
| | | JSONArray.parseArray( |
| | | JSONObject.toJSONString(permissionRoleJson.get("detail")), |
| | | PermissionBasic.class); |
| | | Integer roleId = (Integer) permissionRoleMap.get("id"); |
| | | if(permissionBasics.isEmpty() || roleId == null ){ |
| | | return false; |
| | | } |
| | | |
| | | |
| | | List<PermissionRole> permissionRoles = new ArrayList<>(); |
| | | for (PermissionBasic permissionBasic : permissionBasics) { |
| | | PermissionRole permissionRole = new PermissionRole(); |
| | | permissionRole.setRoleId(roleId); |
| | | permissionRole.setPermissionId(permissionBasic.getId()); |
| | | permissionRoles.add(permissionRole); |
| | | } |
| | | permissionRoleMapper.delete(new QueryWrapper<PermissionRole>().eq("role_id", roleId)); |
| | | return permissionRoleMapper.saveBatch(permissionRoles); |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.example.erp.mapper.userInfo.PermissionBasicMapper"> |
| | | <select id="getPermission"> |
| | | select a.*, |
| | | CASE |
| | | WHEN b.id IS NULL THEN 0 |
| | | ELSE 1 |
| | | END as 'checked' |
| | | select a.id, |
| | | <if test="lang=='en'"> |
| | | a.menu, |
| | | </if> |
| | | <if test="lang=='zh'"> |
| | | c.itemName as menu, |
| | | </if> |
| | | a.page, |
| | | a.permission, |
| | | a.state, |
| | | IF(b.id IS NULL, 0, 1) as 'checked' |
| | | from permission_basic as a |
| | | left join permission_role as b |
| | | on a.id = b.permission_id |
| | | left join user_role as c |
| | | on b.role_id = c.role_id |
| | | left join user as d |
| | | on c.user_id = d.id |
| | | and d.id = #{userId} |
| | | where |
| | | a.id!=1 |
| | | and a.state=1 |
| | | on b.permission_id = a.id |
| | | and b.role_id = #{roleId} |
| | | <if test="lang=='zh'"> |
| | | left join sys_menu_item as c |
| | | on c.menu = a.menu |
| | | </if> |
| | | |
| | | where a.id!=1 and a.state=1 |
| | | <if test="id != null and id != ''"> |
| | | and a.page = (select page from permission_basic where id = #{id}) |
| | | </if> |
| | | |
| | | group by a.id |
| | | </select> |
| | | |
| | |
| | | <if test="lang=='en'"> |
| | | a.menu |
| | | </if> |
| | | |
| | | from permission_basic as a |
| | | left join sys_menu_item as b |
| | | on a.menu = b.menu |
| | |
| | | where a.id = #{loginId} |
| | | and d.state = 1 |
| | | </select> |
| | | |
| | | <insert id="saveBatch"> |
| | | insert into |
| | | permission_role( |
| | | role_id, |
| | | permission_id |
| | | ) |
| | | values |
| | | <foreach collection ="permissionRoles" item="permissionRole" separator =","> |
| | | ( |
| | | #{permissionRole.roleId}, |
| | | #{permissionRole.permissionId} |
| | | ) |
| | | </foreach> |
| | | |
| | | </insert> |
| | | |
| | | </mapper> |
| | |
| | | where a.id = #{loginId} |
| | | and d.state = 1 |
| | | </select> |
| | | |
| | | <insert id="saveBatch"> |
| | | insert into |
| | | permission_role( |
| | | role_id, |
| | | permission_id |
| | | ) |
| | | values |
| | | <foreach collection ="permissionRoles" item="permissionRole" separator =","> |
| | | ( |
| | | #{permissionRole.roleId}, |
| | | #{permissionRole.permissionId} |
| | | ) |
| | | </foreach> |
| | | |
| | | </insert> |
| | | |
| | | </mapper> |