Commit e8a075df8b6c0bd27be949ed1ccc66dda892e2e1
1 parent
940e83c67f
Exists in
master
用户角色树完成
Showing 5 changed files with 234 additions and 94 deletions
- center.manager/src/main/java/com/lyms/cm/controller/sys/SysUsersController.java
- center.manager/src/main/java/com/lyms/cm/service/sys/SysUsersService.java
- center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysUsersServiceImpl.java
- center.manager/src/main/webapp/WEB-INF/views/role/role_edit.html
- center.manager/src/main/webapp/WEB-INF/views/user/user_edit.html
center.manager/src/main/java/com/lyms/cm/controller/sys/SysUsersController.java
View file @
e8a075d
| 1 | 1 | package com.lyms.cm.controller.sys; |
| 2 | 2 | |
| 3 | +import java.util.List; | |
| 3 | 4 | import java.util.Map; |
| 4 | 5 | |
| 5 | 6 | import org.apache.commons.lang3.StringUtils; |
| 6 | 7 | |
| 7 | 8 | |
| ... | ... | @@ -13,9 +14,15 @@ |
| 13 | 14 | |
| 14 | 15 | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| 15 | 16 | import com.baomidou.mybatisplus.plugins.Page; |
| 17 | +import com.lyms.cm.entity.sys.SysRoles; | |
| 18 | +import com.lyms.cm.entity.sys.SysUserRoleMaps; | |
| 16 | 19 | import com.lyms.cm.entity.sys.SysUsers; |
| 20 | +import com.lyms.cm.service.sys.SysRolesService; | |
| 21 | +import com.lyms.cm.service.sys.SysUserRoleMapsService; | |
| 17 | 22 | import com.lyms.cm.service.sys.SysUsersService; |
| 18 | 23 | import com.lyms.constants.OperationName; |
| 24 | +import com.lyms.util.InstanceUtils; | |
| 25 | +import com.lyms.util.StrUtils; | |
| 19 | 26 | import com.lyms.web.bean.AjaxResult; |
| 20 | 27 | import com.lyms.web.controller.BaseController; |
| 21 | 28 | |
| ... | ... | @@ -33,6 +40,12 @@ |
| 33 | 40 | |
| 34 | 41 | @Autowired |
| 35 | 42 | private SysUsersService userService; |
| 43 | + | |
| 44 | + @Autowired | |
| 45 | + private SysRolesService sysRolesService; | |
| 46 | + @Autowired | |
| 47 | + private SysUserRoleMapsService sysUserRoleMapsService; | |
| 48 | + | |
| 36 | 49 | |
| 37 | 50 | /** |
| 38 | 51 | * 创建用户 |
| 39 | 52 | |
| ... | ... | @@ -45,12 +58,14 @@ |
| 45 | 58 | @RequestMapping(value = "/create", method = RequestMethod.POST) |
| 46 | 59 | @ResponseBody |
| 47 | 60 | public AjaxResult create(SysUsers user, AjaxResult ajaxResult) { |
| 48 | - if(userService.isExistAccount(user.getAccount())){ | |
| 61 | + if(!userService.isAllowUpdate(user.getAccount(),null)){ | |
| 49 | 62 | ajaxResult.setSuccess(true); |
| 50 | 63 | ajaxResult.setMessage("新增失败!" + user.getAccount() + " 已经存在,请修改登录账号!"); |
| 51 | 64 | return ajaxResult; |
| 52 | 65 | } |
| 53 | - boolean tag = userService.addUser(user); | |
| 66 | + String userid = StrUtils.uuid(); | |
| 67 | + user.setId(userid); | |
| 68 | + boolean tag = userService.addUser(user,getUserRoleList(userid, getParameter("roles"))); | |
| 54 | 69 | return handleAjaxResult(ajaxResult, tag, OperationName.CREATE); |
| 55 | 70 | } |
| 56 | 71 | |
| 57 | 72 | |
| ... | ... | @@ -91,7 +106,18 @@ |
| 91 | 106 | if (!StringUtils.isBlank(id)) { |
| 92 | 107 | SysUsers user = userService.selectById(id); |
| 93 | 108 | model.addAttribute("user", user); |
| 109 | + //当前用户角色数据 | |
| 110 | + List<SysUserRoleMaps> urList = sysUserRoleMapsService | |
| 111 | + .selectList(new EntityWrapper<SysUserRoleMaps>().where("user_id={0}", "'" + id + "'")); | |
| 112 | + StringBuilder urSB = new StringBuilder(); | |
| 113 | + for(SysUserRoleMaps urEntity : urList){ | |
| 114 | + urSB.append("," + urEntity.getRoleId()); | |
| 115 | + } | |
| 116 | + model.addAttribute("userRoles", urSB.toString().replaceFirst(",", "")); | |
| 94 | 117 | } |
| 118 | + //所有角色数据 | |
| 119 | + List<SysRoles> roleList = sysRolesService.selectList(new EntityWrapper<SysRoles>().where("ifDel=0")); | |
| 120 | + model.addAttribute("roleString",toJson(roleList)); | |
| 95 | 121 | return "/user/user_edit"; |
| 96 | 122 | } |
| 97 | 123 | |
| 98 | 124 | |
| ... | ... | @@ -101,12 +127,12 @@ |
| 101 | 127 | @RequestMapping(value = "/update", method = { RequestMethod.POST }) |
| 102 | 128 | @ResponseBody |
| 103 | 129 | public AjaxResult update(SysUsers user, AjaxResult ajaxResult) { |
| 104 | - if(userService.isExistAccount(user.getAccount())){ | |
| 130 | + if(!userService.isAllowUpdate(user.getAccount(),user.getId())){ | |
| 105 | 131 | ajaxResult.setSuccess(true); |
| 106 | 132 | ajaxResult.setMessage("修改失败! " + user.getAccount()+" 已经存在,请修改登录账号!"); |
| 107 | 133 | return ajaxResult; |
| 108 | 134 | } |
| 109 | - boolean tag = userService.updateUser(user); | |
| 135 | + boolean tag = userService.updateUser(user,getUserRoleList(user.getId(), getParameter("roles"))); | |
| 110 | 136 | return handleAjaxResult(ajaxResult, tag, OperationName.UPDATE); |
| 111 | 137 | |
| 112 | 138 | } |
| ... | ... | @@ -122,6 +148,34 @@ |
| 122 | 148 | int tag = userService.deleteLogicById(id); |
| 123 | 149 | return handleAjaxResult(ajaxResult, tag, OperationName.DELETE); |
| 124 | 150 | } |
| 151 | + | |
| 152 | + /** | |
| 153 | + * <li>@Description:获取用户角色对应关系列表 | |
| 154 | + * <li>@param roleId | |
| 155 | + * <li>@param permissionIds | |
| 156 | + * <li>@return | |
| 157 | + * <li>创建人:方承 | |
| 158 | + * <li>创建时间:2017年3月9日 | |
| 159 | + * <li>修改人: | |
| 160 | + * <li>修改时间: | |
| 161 | + */ | |
| 162 | + private List<SysUserRoleMaps> getUserRoleList(String userId, String roles) { | |
| 163 | + List<SysUserRoleMaps> urList = InstanceUtils.newArrayList(); | |
| 164 | + if (StrUtils.isNotEmpty(roles)) { | |
| 165 | + String[] roleArray = roles.split(","); | |
| 166 | + for (String roleId : roleArray) { | |
| 167 | + if (StrUtils.isNotEmpty(roleId)) { | |
| 168 | + SysUserRoleMaps urentity = new SysUserRoleMaps(); | |
| 169 | + urentity.setId(StrUtils.uuid()); | |
| 170 | + urentity.setIfdel(0); | |
| 171 | + urentity.setRoleId(roleId); | |
| 172 | + urentity.setUserId(userId); | |
| 173 | + urList.add(urentity); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + } | |
| 177 | + return urList; | |
| 178 | + } | |
| 125 | 179 | |
| 126 | 180 | } |
center.manager/src/main/java/com/lyms/cm/service/sys/SysUsersService.java
View file @
e8a075d
| 1 | 1 | package com.lyms.cm.service.sys; |
| 2 | 2 | |
| 3 | 3 | import java.io.Serializable; |
| 4 | +import java.util.List; | |
| 4 | 5 | |
| 6 | +import com.lyms.cm.entity.sys.SysUserRoleMaps; | |
| 5 | 7 | import com.lyms.cm.entity.sys.SysUsers; |
| 6 | 8 | import com.lyms.exception.SystemException; |
| 7 | 9 | import com.lyms.web.service.BaseService; |
| ... | ... | @@ -23,7 +25,7 @@ |
| 23 | 25 | * @return |
| 24 | 26 | * @author maliang |
| 25 | 27 | */ |
| 26 | - public boolean addUser(SysUsers user) throws SystemException; | |
| 28 | + public boolean addUser(SysUsers user,List<SysUserRoleMaps> userRoleMaps) throws SystemException; | |
| 27 | 29 | |
| 28 | 30 | /** |
| 29 | 31 | * 修改用户信息 |
| ... | ... | @@ -32,7 +34,7 @@ |
| 32 | 34 | * @return |
| 33 | 35 | * @author maliang |
| 34 | 36 | */ |
| 35 | - public boolean updateUser(SysUsers user) throws SystemException; | |
| 37 | + public boolean updateUser(SysUsers user,List<SysUserRoleMaps> userRoleMaps) throws SystemException; | |
| 36 | 38 | |
| 37 | 39 | /** |
| 38 | 40 | * 根据ID获取用户信息 |
| ... | ... | @@ -43,17 +45,6 @@ |
| 43 | 45 | */ |
| 44 | 46 | // public SysUsers getUserById(String userId) throws SystemException; |
| 45 | 47 | |
| 46 | - /** | |
| 47 | - * 启用/停用 | |
| 48 | - * <p> | |
| 49 | - * 根据用户ID操作 | |
| 50 | - * <p> | |
| 51 | - * | |
| 52 | - * @param userId | |
| 53 | - * @return | |
| 54 | - * @author maliang | |
| 55 | - */ | |
| 56 | - public boolean enabled(String userId) throws SystemException; | |
| 57 | 48 | |
| 58 | 49 | /** |
| 59 | 50 | * 删除用户信息 |
| 60 | 51 | |
| 61 | 52 | |
| ... | ... | @@ -73,15 +64,16 @@ |
| 73 | 64 | |
| 74 | 65 | |
| 75 | 66 | /** |
| 76 | - * <li>@Description:是否存在登录号 | |
| 77 | - * <li>@param username | |
| 67 | + * <li>@Description:是否允许添加和修改 | |
| 68 | + * <li>@param account 登录账户 | |
| 69 | + * <li>@param userid 如果不为null,则是修改, 否则为新增 | |
| 78 | 70 | * <li>@return |
| 79 | 71 | * <li>创建人:方承 |
| 80 | - * <li>创建时间:2017年3月8日 | |
| 72 | + * <li>创建时间:2017年3月9日 | |
| 81 | 73 | * <li>修改人: |
| 82 | 74 | * <li>修改时间: |
| 83 | 75 | */ |
| 84 | - public boolean isExistAccount(String username); | |
| 76 | + public boolean isAllowUpdate(String account,String userid); | |
| 85 | 77 | |
| 86 | 78 | } |
center.manager/src/main/java/com/lyms/cm/service/sys/impl/SysUsersServiceImpl.java
View file @
e8a075d
| 1 | 1 | package com.lyms.cm.service.sys.impl; |
| 2 | 2 | |
| 3 | 3 | import java.io.Serializable; |
| 4 | +import java.util.List; | |
| 4 | 5 | |
| 5 | 6 | import org.apache.commons.lang3.StringUtils; |
| 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | 8 | |
| 8 | 9 | |
| ... | ... | @@ -9,10 +10,14 @@ |
| 9 | 10 | |
| 10 | 11 | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| 11 | 12 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| 13 | +import com.lyms.cm.dao.sys.SysUserRoleMapsMapper; | |
| 12 | 14 | import com.lyms.cm.dao.sys.SysUsersMapper; |
| 15 | +import com.lyms.cm.entity.sys.SysRolePermissionMaps; | |
| 16 | +import com.lyms.cm.entity.sys.SysUserRoleMaps; | |
| 13 | 17 | import com.lyms.cm.entity.sys.SysUsers; |
| 14 | 18 | import com.lyms.cm.enums.StatusEnum; |
| 15 | 19 | import com.lyms.cm.enums.ValidityEnum; |
| 20 | +import com.lyms.cm.service.sys.SysUserRoleMapsService; | |
| 16 | 21 | import com.lyms.cm.service.sys.SysUsersService; |
| 17 | 22 | import com.lyms.exception.SystemException; |
| 18 | 23 | import com.lyms.util.MD5Utils; |
| ... | ... | @@ -31,6 +36,10 @@ |
| 31 | 36 | |
| 32 | 37 | @Autowired |
| 33 | 38 | private SysUsersMapper userMapper; |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + private SysUserRoleMapsService sysUserRoleMapsService; | |
| 42 | + | |
| 34 | 43 | |
| 35 | 44 | /** |
| 36 | 45 | * 系统默认密码 |
| 37 | 46 | |
| ... | ... | @@ -58,11 +67,10 @@ |
| 58 | 67 | |
| 59 | 68 | @Override |
| 60 | 69 | @Transactional |
| 61 | - public boolean addUser(SysUsers user) throws SystemException { | |
| 70 | + public boolean addUser(SysUsers user,List<SysUserRoleMaps> userRoleMapsList) throws SystemException { | |
| 62 | 71 | if (empty(user)) |
| 63 | 72 | return false; |
| 64 | 73 | // 设置user ID |
| 65 | - user.setId(StrUtils.uuid()); | |
| 66 | 74 | user.setIfdel(0); |
| 67 | 75 | if (null == user.getType()) {//没有勾选管理,就是用户 |
| 68 | 76 | user.setType(1); |
| 69 | 77 | |
| ... | ... | @@ -74,12 +82,15 @@ |
| 74 | 82 | this.initPwd(user); |
| 75 | 83 | |
| 76 | 84 | Integer tag = userMapper.insert(user); |
| 85 | + if (!userRoleMapsList.isEmpty()) { | |
| 86 | + sysUserRoleMapsService.insertBatch(userRoleMapsList); | |
| 87 | + } | |
| 77 | 88 | return tag != null && tag >= 1; |
| 78 | 89 | } |
| 79 | 90 | |
| 80 | 91 | @Override |
| 81 | 92 | @Transactional |
| 82 | - public boolean updateUser(SysUsers user) throws SystemException { | |
| 93 | + public boolean updateUser(SysUsers user,List<SysUserRoleMaps> userRoleMapsList) throws SystemException { | |
| 83 | 94 | if (empty(user)) |
| 84 | 95 | return false; |
| 85 | 96 | if (null == user.getType()) {//没有勾选管理,就是用户 |
| ... | ... | @@ -94,6 +105,12 @@ |
| 94 | 105 | } |
| 95 | 106 | |
| 96 | 107 | Integer tag = userMapper.updateById(user); |
| 108 | + EntityWrapper<SysUserRoleMaps> ew = new EntityWrapper<SysUserRoleMaps>(); | |
| 109 | + ew.where("user_id={0}", "'" + user.getId() + "'"); | |
| 110 | + sysUserRoleMapsService.delete(ew); | |
| 111 | + if (!userRoleMapsList.isEmpty()) { | |
| 112 | + sysUserRoleMapsService.insertBatch(userRoleMapsList); | |
| 113 | + } | |
| 97 | 114 | return tag != null && tag >= 1; |
| 98 | 115 | } |
| 99 | 116 | |
| 100 | 117 | |
| ... | ... | @@ -103,23 +120,7 @@ |
| 103 | 120 | * userMapper.selectById(userId); } |
| 104 | 121 | */ |
| 105 | 122 | |
| 106 | - @Override | |
| 107 | - @Transactional | |
| 108 | - public boolean enabled(String userId) throws SystemException { | |
| 109 | - // TODO 编写SQL 修改 | |
| 110 | - SysUsers user = this.selectById(userId); | |
| 111 | - if (empty(user)) | |
| 112 | - return false; | |
| 113 | 123 | |
| 114 | - // 判断当前用户的启用,禁用情况 | |
| 115 | - if (StatusEnum.isEnabled(user.getEnable())) { | |
| 116 | - user.setEnable(StatusEnum.DISENABLED.getStatus()); | |
| 117 | - } else { | |
| 118 | - user.setEnable(StatusEnum.ENABLED.getStatus()); | |
| 119 | - } | |
| 120 | - return this.updateUser(user); | |
| 121 | - } | |
| 122 | - | |
| 123 | 124 | @Override |
| 124 | 125 | @Transactional |
| 125 | 126 | public boolean delete(String userId) throws SystemException { |
| ... | ... | @@ -148,8 +149,30 @@ |
| 148 | 149 | } |
| 149 | 150 | |
| 150 | 151 | @Override |
| 151 | - public boolean isExistAccount(String username) { | |
| 152 | - SysUsers entity = selectOne(new EntityWrapper<SysUsers>().where("account={0}", "'" + username + "'")); | |
| 152 | + public boolean isAllowUpdate(String account,String userid) { | |
| 153 | + boolean flag = true; | |
| 154 | + if(StrUtils.isNotEmpty(userid) ){//修改用户 | |
| 155 | + SysUsers oldDbUser = selectById(userid); | |
| 156 | + if(!oldDbUser.getAccount().equalsIgnoreCase(account)){//登录账号改变 | |
| 157 | + flag = !isExistAccount(account); | |
| 158 | + } | |
| 159 | + }else{//新增 | |
| 160 | + flag = !isExistAccount(account); | |
| 161 | + } | |
| 162 | + return flag; | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * <li>@Description:是否存在登录名 | |
| 167 | + * <li>@param account | |
| 168 | + * <li>@return | |
| 169 | + * <li>创建人:方承 | |
| 170 | + * <li>创建时间:2017年3月9日 | |
| 171 | + * <li>修改人: | |
| 172 | + * <li>修改时间: | |
| 173 | + */ | |
| 174 | + private boolean isExistAccount(String account){ | |
| 175 | + SysUsers entity = selectOne(new EntityWrapper<SysUsers>().where("account={0}", "'" + account + "'").and("ifDel=0")); | |
| 153 | 176 | if (null == entity) { |
| 154 | 177 | return false; |
| 155 | 178 | } |
center.manager/src/main/webapp/WEB-INF/views/role/role_edit.html
View file @
e8a075d
| ... | ... | @@ -7,50 +7,6 @@ |
| 7 | 7 | var reNodes = ${perString}; |
| 8 | 8 | </script> |
| 9 | 9 | <script> |
| 10 | -function Scroll(w) { | |
| 11 | - var win = w || window; | |
| 12 | - var d = win.document; | |
| 13 | - if (d.documentElement && !(d.documentElement.scrollTop == undefined || d.documentElement.scrollTop == 0)) { | |
| 14 | - return { | |
| 15 | - 'top': win.document.documentElement.scrollTop, | |
| 16 | - 'left': win.document.documentElement.scrollLeft | |
| 17 | - }; | |
| 18 | - } else if (win.document.body) { | |
| 19 | - return { | |
| 20 | - 'top': win.document.body.scrollTop, | |
| 21 | - 'left': win.document.body.scrollLeft | |
| 22 | - }; | |
| 23 | - } | |
| 24 | -} | |
| 25 | -function BoundingClientRect(obj) { | |
| 26 | - if (navigator.product == 'Gecko') { | |
| 27 | - var objWin = null; | |
| 28 | - var top = obj.offsetTop; | |
| 29 | - var left = obj.offsetLeft; | |
| 30 | - var right = obj.offsetWidth; | |
| 31 | - var bottom = obj.offsetHeight; | |
| 32 | - while (obj = obj.offsetParent) { | |
| 33 | - top += obj.offsetTop; | |
| 34 | - left += obj.offsetLeft; | |
| 35 | - if (obj.tagName.toLowerCase() == 'body') { | |
| 36 | - objWin = obj.ownerDocument.defaultView; | |
| 37 | - } | |
| 38 | - } | |
| 39 | - var theScroll = Scroll(objWin); | |
| 40 | - left -= theScroll.left; | |
| 41 | - top -= theScroll.top; | |
| 42 | - right += left; | |
| 43 | - bottom += top; | |
| 44 | - return { | |
| 45 | - 'left': left, | |
| 46 | - 'top': top, | |
| 47 | - 'right': right, | |
| 48 | - 'bottom': bottom | |
| 49 | - }; | |
| 50 | - } else { | |
| 51 | - return obj.getBoundingClientRect(); | |
| 52 | - } | |
| 53 | -} | |
| 54 | 10 | var setting_resource = { |
| 55 | 11 | check: { |
| 56 | 12 | enable: true, |
| ... | ... | @@ -140,7 +96,9 @@ |
| 140 | 96 | var rpArray = rpValues.split(","); |
| 141 | 97 | for(var i = 0 ; i < rpArray.length ;i++){ |
| 142 | 98 | var node = zTree.getNodeByParam('id',rpArray[i]); |
| 143 | - zTree.checkNode(node,true,false); | |
| 99 | + if(node != null){ | |
| 100 | + zTree.checkNode(node,true,false); | |
| 101 | + } | |
| 144 | 102 | } |
| 145 | 103 | } |
| 146 | 104 | zTree.expandAll(true); |
| 147 | 105 | |
| ... | ... | @@ -184,11 +142,11 @@ |
| 184 | 142 | <div class="col-sm-8"> |
| 185 | 143 | <label class="checkbox-inline i-checks"> |
| 186 | 144 | <div class="icheckbox_square-green" style="position: relative;"> |
| 187 | - <input type="checkbox" value="1" name="enable" #if ($role.enable == 1) checked="checked" #end | |
| 145 | + <input type="checkbox" value="0" name="enable" #if ($role.enable == 0) checked="checked" #end | |
| 188 | 146 | style="position: absolute; opacity: 0;" > |
| 189 | 147 | <ins class="iCheck-helper" |
| 190 | 148 | style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins> |
| 191 | - </div>是否可用(选中可用,不选中不可用) | |
| 149 | + </div>是否禁用(选中禁用,不选中可用) | |
| 192 | 150 | </label> |
| 193 | 151 | </div> |
| 194 | 152 | </div> |
center.manager/src/main/webapp/WEB-INF/views/user/user_edit.html
View file @
e8a075d
| 1 | +#override("css") | |
| 2 | +<link rel="stylesheet" href="${ctx}/static/js/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css" /> | |
| 3 | +#end | |
| 4 | +#override("js") | |
| 5 | +<script src="${ctx}/static/js/zTree_v3/js/jquery.ztree.all-3.5.min.js" type="text/javascript"></script> | |
| 6 | +<script type="text/javascript"> | |
| 7 | +var reNodes = ${roleString}; | |
| 8 | +</script> | |
| 9 | +<script> | |
| 10 | +var setting_resource = { | |
| 11 | + check: { | |
| 12 | + enable: true, | |
| 13 | + chkboxType: { | |
| 14 | + 'Y': 's', | |
| 15 | + 'N': 's' | |
| 16 | + } | |
| 17 | + }, | |
| 18 | + view: { | |
| 19 | + dblClickExpand: false | |
| 20 | + }, | |
| 21 | + data: { | |
| 22 | + simpleData: { | |
| 23 | + enable: true, | |
| 24 | + idKey: "role_id" | |
| 25 | + } | |
| 26 | + }, | |
| 27 | + callback: { | |
| 28 | + beforeClick: beforeClick_resource, | |
| 29 | + onCheck: onCheck_resource | |
| 30 | + } | |
| 31 | +}; | |
| 32 | +function beforeClick_resource(treeId, treeNode) { | |
| 33 | + var zTree = $.fn.zTree.getZTreeObj('tree_resource'); | |
| 34 | + zTree.expandNode(treeNode); | |
| 35 | + zTree.checkNode(treeNode, !treeNode.checked, null, true); | |
| 36 | + return false; | |
| 37 | +} | |
| 38 | +function selectTreeNode_resource(id) { | |
| 39 | + var zTree = $.fn.zTree.getZTreeObj('tree_resource'); | |
| 40 | + var node = zTree.getNodeByParam('id', id); | |
| 41 | + var pNode = node.getParentNode(); | |
| 42 | + while (pNode != null) { | |
| 43 | + pNode = analParentNode(pNode, zTree); | |
| 44 | + } | |
| 45 | + zTree.cancelSelectedNode(); | |
| 46 | + zTree.checkNode(node, true); | |
| 47 | + zTree.selectNode(node, true); | |
| 48 | +} | |
| 49 | +function analParentNode(node, zTree) { | |
| 50 | + zTree.expandNode(node, true); | |
| 51 | + var pNode = node.getParentNode(); | |
| 52 | + if (pNode) { | |
| 53 | + return pNode; | |
| 54 | + } | |
| 55 | + return null; | |
| 56 | +} | |
| 57 | +function onClick_resource(e, treeId, treeNode) { | |
| 58 | + var zTree = $.fn.zTree.getZTreeObj('tree_resource'); | |
| 59 | + zTree.expandNode(treeNode); | |
| 60 | + zTree.checkNode(treeNode, !treeNode.checked, null, true); | |
| 61 | + return false; | |
| 62 | +} | |
| 63 | +function onCheck_resource(e, treeId, treeNode) { | |
| 64 | + var zTree = $.fn.zTree.getZTreeObj('tree_resource'), | |
| 65 | + nodes = zTree.getCheckedNodes(true), | |
| 66 | + v_txt = ''; | |
| 67 | + v_value = ''; | |
| 68 | + v_type = ''; | |
| 69 | + for (var i = 0, | |
| 70 | + l = nodes.length; i < l; i++) { | |
| 71 | + v_txt += nodes[i].name + ','; | |
| 72 | + v_value += nodes[i].id + ','; | |
| 73 | + if (nodes[i].type) { | |
| 74 | + v_type += nodes[i].type + ','; | |
| 75 | + } | |
| 76 | + } | |
| 77 | + if (v_txt.length > 0) { | |
| 78 | + v_txt = v_txt.substring(0, v_txt.length - 1); | |
| 79 | + v_value = v_value.substring(0, v_value.length - 1); | |
| 80 | + v_type = v_type.substring(0, v_type.length - 1); | |
| 81 | + } | |
| 82 | + $('#resource').attr('value', v_value); | |
| 83 | + $('#resource_txt').attr('value', v_txt); | |
| 84 | + $('#resource_type').attr('value', v_type); | |
| 85 | +} | |
| 86 | +var zNodes_resource = null; | |
| 87 | +var zTree_selectMode_resource = 'all'; | |
| 88 | +$(function() { | |
| 89 | + zNodes_resource = reNodes; | |
| 90 | + var zTree = $.fn.zTree.init($('#tree_resource'), setting_resource, zNodes_resource); | |
| 91 | + | |
| 92 | + //初始化勾选 | |
| 93 | + var rpValues = $('#resource').val(); | |
| 94 | + if(rpValues.length > 0){ | |
| 95 | + var rpArray = rpValues.split(","); | |
| 96 | + for(var i = 0 ; i < rpArray.length ;i++){ | |
| 97 | + var node = zTree.getNodeByParam('id',rpArray[i]); | |
| 98 | + if(node != null){ | |
| 99 | + zTree.checkNode(node,true,true); | |
| 100 | + } | |
| 101 | + } | |
| 102 | + } | |
| 103 | +}); | |
| 104 | + | |
| 105 | +</script> | |
| 106 | +#end | |
| 1 | 107 | #override("body") |
| 2 | 108 | <div class="ibox float-e-margins"> |
| 3 | 109 | <div class="ibox-content"> |
| 4 | - <form id="validForm" class="form-horizontal m-t" novalidate="novalidate"> | |
| 5 | - <input id="resource" name="resource" type="hidden" value="$!rolePermissions"/> | |
| 6 | - <input type="hidden" id="role.id" name="id" value="$!role.id"/> | |
| 110 | + <div class="col-sm-4"> | |
| 111 | + <form id="validForm" class="form-horizontal m-t" novalidate="novalidate"> | |
| 112 | + <input id="resource" name="roles" type="hidden" value="$!userRoles"/> | |
| 113 | + <input type="hidden" id="user.id" name="id" value="$!user.id"/> | |
| 7 | 114 | <div class="form-group"> |
| 8 | 115 | <label class="col-sm-3 control-label">账号:</label> |
| 9 | 116 | <div class="col-sm-8"> |
| 10 | 117 | |
| ... | ... | @@ -51,11 +158,11 @@ |
| 51 | 158 | <div class="col-sm-8"> |
| 52 | 159 | <label class="checkbox-inline i-checks"> |
| 53 | 160 | <div class="icheckbox_square-green" style="position: relative;"> |
| 54 | - <input type="checkbox" value="1" name="enable" #if ($user.enable == 1) checked="checked" #end | |
| 161 | + <input type="checkbox" value="0" name="enable" #if ($user.enable == 0) checked="checked" #end | |
| 55 | 162 | style="position: absolute; opacity: 0;" > |
| 56 | 163 | <ins class="iCheck-helper" |
| 57 | 164 | style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;"></ins> |
| 58 | - </div>是否可用(选中可用,不选中不可用) | |
| 165 | + </div>是否禁用(选中禁用,不选中可用) | |
| 59 | 166 | </label> |
| 60 | 167 | </div> |
| 61 | 168 | </div> |
| ... | ... | @@ -80,6 +187,12 @@ |
| 80 | 187 | </div> |
| 81 | 188 | </div> |
| 82 | 189 | </form> |
| 190 | + </div> | |
| 191 | + <div class="col-sm-6"> | |
| 192 | + <div id="treeContent_resource" class="menuContent"> | |
| 193 | + <ul id="tree_resource" class="ztree" style="margin-top:0; width:180px; height: 250px;"></ul> | |
| 194 | + </div> | |
| 195 | + </div> | |
| 83 | 196 | </div> |
| 84 | 197 | </div> |
| 85 | 198 | <script type="text/javascript"> |