Skip to content

Commit

Permalink
系统管理功能完善
Browse files Browse the repository at this point in the history
  • Loading branch information
penggle committed May 11, 2017
1 parent 7f58dee commit bd9f3d7
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AdminConstants extends AbstractConstants {
/**
* 用户默认头像
*/
public static final String DEFAULT_USER_ICON = valueOf("/resources/images/default-user-icon.png");
public static final String DEFAULT_USER_AVATAR = valueOf("/resources/images/default-user-avatar.png");

/**
* 用户头像默认保存路径,相对于#GlobalConstants.IMAGE_SERVER_ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Object addUser(HttpServletRequest request, HttpServletResponse response,
userAddForm.setUserType(AdminUserTypeEnum.ADMIN_USER_TYPE_NORMAL.getTypeCode());

if(StringUtils.isEmpty(userAddForm.getUserIcon())){
userAddForm.setUserIcon(AdminConstants.DEFAULT_USER_ICON);
userAddForm.setUserIcon(AdminConstants.DEFAULT_USER_AVATAR);
}else{
String userIcon = userAddForm.getUserIcon();
if(userIcon.toLowerCase().startsWith(GlobalConstants.DEFAULT_UPLOAD_SAVE_PATH)){
Expand Down Expand Up @@ -115,7 +115,7 @@ public Object editUser(HttpServletRequest request, HttpServletResponse response,
userEditForm.setUpdateTime(DateTimeUtils.formatNow());

if(StringUtils.isEmpty(userEditForm.getUserIcon())){
userEditForm.setUserIcon(AdminConstants.DEFAULT_USER_ICON);
userEditForm.setUserIcon(AdminConstants.DEFAULT_USER_AVATAR);
}else{
String userIcon = userEditForm.getUserIcon();
if(userIcon.toLowerCase().startsWith(GlobalConstants.DEFAULT_UPLOAD_SAVE_PATH)){
Expand All @@ -138,9 +138,9 @@ public Object editUser(HttpServletRequest request, HttpServletResponse response,
* @return
*/
@RequestMapping(value="/admin/user/del")
public Object delUser(HttpServletRequest request, HttpServletResponse response, Long userId) {
public Object delUser(HttpServletRequest request, HttpServletResponse response, Long id) {
AdminUser user = new AdminUser();
user.setUserId(userId);
user.setUserId(id);
adminUserService.deleteUserById(user);
return genSuccessResult("删除成功!", null);
}
Expand Down
49 changes: 48 additions & 1 deletion xproject-admin/src/main/webapp/admin/user/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ <h3 class="el-title">
</el-table-column>
<el-table-column label="状态" prop="status" width="100" align="center" sortable="custom">
<template scope="scope">
<el-tag class="el-tag-small" :type="getStatusTagType(scope.row.status)">{{scope.row.statusName}}</el-tag>
<el-switch :value="scope.row.status" on-color="#27c24c" off-color="#f05050" :on-value="1" :off-value="0" on-text="启用" off-text="禁用" @click.native="changeUserStatus($event, scope.row)"></el-switch>
</template>
</el-table-column>
<el-table-column label="创建时间" prop="createTime" width="100" align="center" sortable="custom"></el-table-column>
Expand All @@ -124,6 +124,7 @@ <h3 class="el-title">
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="view">查看详情</el-dropdown-item>
<el-dropdown-item command="edit">修改用户</el-dropdown-item>
<el-dropdown-item command="changepwd">修改密码</el-dropdown-item>
<el-dropdown-item command="conf">配置用户角色</el-dropdown-item>
<el-dropdown-item command="del" divided>删除用户</el-dropdown-item>
</el-dropdown-menu>
Expand Down Expand Up @@ -379,6 +380,52 @@ <h3 class="el-title">
<el-button icon="fa-ban" @click="closeUserViewConfigDialog">关 闭</el-button>
</div>
</el-dialog>
<el-dialog v-model="changePwdDialogVisible" class="el-dialog-form el-dialog-center" size="large" @close="closeChangePwdDialog">
<span class="el-dialog__title" slot="title"><i class="el-icon-fa-th-large"></i>修改用户密码</span>
<div>
<el-form ref="changePwdForm" :model="changePwdForm" :rules="changePwdRules" label-width="220px">
<el-row>
<el-col :span="24">
<el-form-item label="用户名" prop="userName">
<el-col :span="14">
<span style="line-height:32px;font-weight:bold;color:#000;">{{changePwdForm.userName}}</span>
</el-col>
<el-col :span="10">
</el-col>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="账户密码" prop="password">
<el-col :span="14">
<el-input v-model="changePwdForm.password" :maxlength="20" type="password"></el-input>
</el-col>
<el-col :span="10">
<p class="el-form-item-tips">由6~20位个字母或数字组成.</p>
</el-col>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="重复密码" prop="repassword">
<el-col :span="14">
<el-input v-model="changePwdForm.repassword" :maxlength="20" type="password"></el-input>
</el-col>
<el-col :span="10">
<p class="el-form-item-tips">请再次确认您输入的密码.</p>
</el-col>
</el-form-item>
</el-col>
</el-row>
</el-form>
</div>
<div slot="footer">
<el-button icon="fa-ban" @click="closeChangePwdDialog">取 消</el-button>
<el-button type="primary" icon="fa-save" @click="changePasswd" :loading="submiting">确 定</el-button>
</div>
</el-dialog>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ html, body, .el-container {
float: right;
font-size: 12px;
color: #999;
line-height: 30px;
}
.admin-login-forgotpwd:hover {
color: #337ab7;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
148 changes: 134 additions & 14 deletions xproject-admin/src/main/webapp/resources/scripts/admin/user/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var ADMIN_USER_TYPE_SYSTEM = 0;
var IMAGE_TYPES = ['image/jpeg', 'image/jpg', 'image/png'];
var USER_STATUS = {
1: '启用',
0: '禁用'
};
var vm = null;
Vue.onDocumentReady(function() {
vm = new Vue({
Expand All @@ -24,6 +28,7 @@ Vue.onDocumentReady(function() {
userList: [],
editDialogVisible: false,
viewConfigDialogVisible: false,
changePwdDialogVisible: false,
viewConfigActiveTabName: 'userDetail',
uploadHeaders: {
Accept: 'application/json'
Expand Down Expand Up @@ -66,6 +71,12 @@ Vue.onDocumentReady(function() {
lastLoginTime: '',
loginTimes: ''
},
changePwdForm: {
userId: '',
userName: '',
password: '',
repassword: ''
},
userEditRules: {
userName: [{
required: true,
Expand Down Expand Up @@ -119,6 +130,32 @@ Vue.onDocumentReady(function() {
message: 'EMAIL不合法!'
}]
},
changePwdRules: {
password: [{
required: true,
message: '请输入账户密码!'
},{
validator: regex,
regex: /^[a-zA-Z0-9]{6,20}$/,
message: '账户密码由6~20个字母或数字组成!'
}],
repassword: [{
required: true,
message: '请再次输入账户密码!'
},{
validator: regex,
regex: /^[a-zA-Z0-9]{6,20}$/,
message: '账户密码由6~20个字母或数字组成!'
},{
validator: equalTo,
compareTarget: {
vue: 'vm',
form: 'changePwdForm',
field: 'password'
},
message: '两次密码不一致!'
}]
},
roleQuering: false,
userRoleQueryForm: {
userId: '',
Expand Down Expand Up @@ -259,6 +296,8 @@ Vue.onDocumentReady(function() {
this.deleteUser(row);
}else if(cmd == 'conf'){
this.openUserViewConfigDialog(cmd, row);
}else if(cmd == 'changepwd'){
this.openChangePwdDialog(cmd, row);
}
},
openUserEditDialog: function(cmd, row){
Expand All @@ -274,6 +313,10 @@ Vue.onDocumentReady(function() {
}
this.editDialogVisible = true;
},
closeEditDialog: function(){
this.editDialogVisible = false;
this.$refs.userEditForm.resetFields();
},
openUserViewConfigDialog: function(cmd, row){
this.currentActionType = cmd;
this.userViewConfigForm.userId = row.userId;
Expand Down Expand Up @@ -302,6 +345,26 @@ Vue.onDocumentReady(function() {
}
this.viewConfigDialogVisible = true;
},
closeUserViewConfigDialog: function(){
this.viewConfigDialogVisible = false;
this.resetUserRoleQueryForm();
this.userRoleList = [];
if(this.currentActionType == 'conf'){
this.resetRoleQueryForm();
this.roleList = [];
this.selectedRoleIds = [];
}
},
openChangePwdDialog: function(cmd, row){
this.currentActionType = cmd;
this.changePwdForm.userId = row.userId;
this.changePwdForm.userName = row.userName;
this.changePwdDialogVisible = true;
},
closeChangePwdDialog: function(){
this.changePwdDialogVisible = false;
this.$refs.changePwdForm.resetFields();
},
saveUser: function(){
var url = '';
if(this.currentActionType == 'add'){
Expand Down Expand Up @@ -364,10 +427,77 @@ Vue.onDocumentReady(function() {
});
}
},
closeEditDialog: function(){
this.editDialogVisible = false;
this.$refs.userEditForm.resetFields();
},
changePasswd: function(){
var url = ADMIN_CONTEXT_PATH + '/admin/user/changepwd/submit?forceUpdate=true';
var _this = this;
this.$refs.changePwdForm.validate(function(valid){
if(valid && !_this.submiting){
_this.$confirm('你确定要修改该用户的密码?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: function(action, instance){
if(action == 'confirm'){
_this.submiting = true;
setTimeout(function(){
axios.post(url, _this.changePwdForm).then(function(response){
_this.submiting = false;
var result = response.data;
if(result.success){
_this.closeChangePwdDialog();
_this.$message.success('修改成功!');
}else{
_this.$message.error(result.message);
}
}).catch(function(error){
_this.submiting = false;
_this.$message.error('请求出错!');
});
}, 1500);
}
}
});
}else{
return false;
}
});
},
changeUserStatus: function(event, row){
if(ADMIN_USER_TYPE_SYSTEM == row.userType){
this.$message.error('系统用户禁止此操作!');
}else{
//var switchVm = event.currentTarget.__vue__;
var targetStatus = row.status == 1 ? 0 : 1;
var url = '';
if(targetStatus == 1){
url = ADMIN_CONTEXT_PATH + '/admin/user/enable?userId=' + row.userId;
}else{
url = ADMIN_CONTEXT_PATH + '/admin/user/disable?userId=' + row.userId;
}
this.$confirm('你确定要' + USER_STATUS[targetStatus] + '该用户?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: function(action, instance){
if(action == 'confirm'){
axios.get(url).then(function(response){
var result = response.data;
if(result.success){
//_this.$message.success('操作成功!');
row.status = targetStatus;
}else{
_this.$message.error(result.message);
}
}).catch(function(error){
_this.$message.error('请求出错!');
});
}
}
});
}
event.preventDefault();
return false;
},
queryUserRoleList: function(loading){
this.userRoleQueryForm.userId = this.userViewConfigForm.userId;
var _this = this;
Expand Down Expand Up @@ -445,16 +575,6 @@ Vue.onDocumentReady(function() {
resetRoleQueryForm: function(){
this.$refs.roleQueryForm.resetFields();
},
closeUserViewConfigDialog: function(){
this.viewConfigDialogVisible = false;
this.resetUserRoleQueryForm();
this.userRoleList = [];
if(this.currentActionType == 'conf'){
this.resetRoleQueryForm();
this.roleList = [];
this.selectedRoleIds = [];
}
},
delUserRoleConfig: function(){
if(this.selectedRoleIds.length){
var userId = this.userViewConfigForm.userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ public interface AdminUserDAO
*/
public void deleteUserRoles(Long userId, List<Long> roleIdList);

/**
* 删除用户的所有角色
*
* @param userId
* @param roleIdList
*/
public void deleteUserAllRoles(Long userId);

/**
* 根据用户名获取用户信息
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ public void deleteUserRoles(Long userId, List<Long> roleIdList) {
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("userId", userId);
paramMap.put("roleIdList", roleIdList);
getSqlSessionTemplate().insert(getMapperKey("deleteUserRoles"), paramMap);
getSqlSessionTemplate().delete(getMapperKey("deleteUserRoles"), paramMap);
}

public AdminUser getUserByUserName(String userName, boolean fatUser) {
public void deleteUserAllRoles(Long userId) {
getSqlSessionTemplate().delete(getMapperKey("deleteUserAllRoles"), userId);
}

public AdminUser getUserByUserName(String userName, boolean fatUser) {
if (fatUser) {
return getSqlSessionTemplate().selectOne(getMapperKey("getUserByUserName"), userName, new AdminUserModelHandler());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public void deleteRoleById(Long roleId) {
ValidationAssert.notNull(role, "该角色已经不存在了!");
BusinessAssert.isTrue(!AdminRoleTypeEnum.ADMIN_ROLE_TYPE_SYSTEM.getTypeCode().equals(role.getRoleType()), "删除角色失败,系统角色不允许删除!");
BusinessAssert.isTrue(!role.isInuse(), "删除角色失败,该角色已经在使用不允许删除!");
roleDAO.deleteRoleById(roleId);
roleDAO.deleteRoleById(roleId); //删除角色信息
roleDAO.deleteRoleResourcesByRoleId(roleId); //删除该角色下的所有资源关系
}

public AdminRole getRoleById(Long roleId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public void deleteUserById(AdminUser user) {
ValidationAssert.notNull(puser, "该用户已经不存在了!");
BusinessAssert.isTrue(!AdminUserTypeEnum.ADMIN_USER_TYPE_SYSTEM.getTypeCode().equals(puser.getUserType()), "系统级用户不能被删除!");
user.setUserName(puser.getUserName());
userDAO.deleteUserById(user.getUserId());
userDAO.deleteUserById(user.getUserId()); //删除用户信息
userDAO.deleteUserAllRoles(user.getUserId()); //删除用户的所有角色关系
}

@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@
</foreach>
</insert>

<delete id="deleteUserAllRoles" parameterType="java.lang.Long" statementType="PREPARED">
DELETE a FROM admin_user_role a
WHERE a.user_id = #{userId, jdbcType=BIGINT}
</delete>

<delete id="deleteUserRoles" parameterType="java.util.Map" statementType="PREPARED">
DELETE a FROM admin_user_role a
WHERE a.user_id = #{userId, jdbcType=BIGINT}
Expand Down

0 comments on commit bd9f3d7

Please sign in to comment.