Commit da03709b by fengshuonan

更新用户添加和修改页面

parent 3707b074
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package cn.stylefeng.guns.modular.system.controller; package cn.stylefeng.guns.modular.system.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.stylefeng.guns.config.properties.GunsProperties; import cn.stylefeng.guns.config.properties.GunsProperties;
import cn.stylefeng.guns.core.common.annotion.BussinessLog; import cn.stylefeng.guns.core.common.annotion.BussinessLog;
import cn.stylefeng.guns.core.common.annotion.Permission; import cn.stylefeng.guns.core.common.annotion.Permission;
...@@ -35,6 +36,7 @@ import cn.stylefeng.roses.core.base.controller.BaseController; ...@@ -35,6 +36,7 @@ import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.datascope.DataScope; import cn.stylefeng.roses.core.datascope.DataScope;
import cn.stylefeng.roses.core.reqres.response.ResponseData; import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil; import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import cn.stylefeng.roses.kernel.model.exception.ServiceException; import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -44,10 +46,9 @@ import org.springframework.validation.BindingResult; ...@@ -44,10 +46,9 @@ import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.naming.NoPermissionException;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.File; import java.io.File;
import java.util.Date; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
...@@ -89,10 +90,9 @@ public class UserMgrController extends BaseController { ...@@ -89,10 +90,9 @@ public class UserMgrController extends BaseController {
/** /**
* 跳转到角色分配页面 * 跳转到角色分配页面
*/ */
//@RequiresPermissions("/mgr/role_assign") //利用shiro自带的权限检查
@Permission @Permission
@RequestMapping("/role_assign/{userId}") @RequestMapping("/role_assign")
public String roleAssign(@PathVariable Integer userId, Model model) { public String roleAssign(@RequestParam Integer userId, Model model) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
} }
...@@ -106,16 +106,12 @@ public class UserMgrController extends BaseController { ...@@ -106,16 +106,12 @@ public class UserMgrController extends BaseController {
* 跳转到编辑管理员页面 * 跳转到编辑管理员页面
*/ */
@Permission @Permission
@RequestMapping("/user_edit/{userId}") @RequestMapping("/user_edit")
public String userEdit(@PathVariable Integer userId, Model model) { public String userEdit(@RequestParam Integer userId) {
if (ToolUtil.isEmpty(userId)) { if (ToolUtil.isEmpty(userId)) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
} }
assertAuth(userId);
User user = this.userService.selectById(userId); User user = this.userService.selectById(userId);
model.addAttribute(user);
model.addAttribute("roleName", ConstantFactory.me().getRoleName(user.getRoleid()));
model.addAttribute("deptName", ConstantFactory.me().getDeptName(user.getDeptid()));
LogObjectHolder.me().set(user); LogObjectHolder.me().set(user);
return PREFIX + "user_edit.html"; return PREFIX + "user_edit.html";
} }
...@@ -146,6 +142,27 @@ public class UserMgrController extends BaseController { ...@@ -146,6 +142,27 @@ public class UserMgrController extends BaseController {
} }
/** /**
* 获取用户详情
*/
@RequestMapping("/getUserInfo")
@ResponseBody
public Object getUserInfo(@RequestParam Integer userId) {
if (ToolUtil.isEmpty(userId)) {
throw new RequestEmptyException();
}
assertAuth(userId);
User user = this.userService.selectById(userId);
Map<String, Object> map = UserFactory.removeUnSafeFields(user);
HashMap<Object, Object> hashMap = CollectionUtil.newHashMap();
hashMap.putAll(map);
hashMap.put("roleName", ConstantFactory.me().getRoleName(user.getRoleid()));
hashMap.put("deptName", ConstantFactory.me().getDeptName(user.getDeptid()));
return ResponseData.success(hashMap);
}
/**
* 修改当前用户的密码 * 修改当前用户的密码
*/ */
@RequestMapping("/changePwd") @RequestMapping("/changePwd")
...@@ -173,7 +190,10 @@ public class UserMgrController extends BaseController { ...@@ -173,7 +190,10 @@ public class UserMgrController extends BaseController {
@RequestMapping("/list") @RequestMapping("/list")
@Permission @Permission
@ResponseBody @ResponseBody
public Object list(@RequestParam(required = false) String name, @RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) Integer deptid) { public Object list(@RequestParam(required = false) String name,
@RequestParam(required = false) String beginTime,
@RequestParam(required = false) String endTime,
@RequestParam(required = false) Integer deptid) {
if (ShiroKit.isAdmin()) { if (ShiroKit.isAdmin()) {
List<Map<String, Object>> users = userService.selectUsers(null, name, beginTime, endTime, deptid); List<Map<String, Object>> users = userService.selectUsers(null, name, beginTime, endTime, deptid);
return new UserWarpper(users).wrap(); return new UserWarpper(users).wrap();
...@@ -203,24 +223,20 @@ public class UserMgrController extends BaseController { ...@@ -203,24 +223,20 @@ public class UserMgrController extends BaseController {
} }
// 完善账号信息 // 完善账号信息
user.setSalt(ShiroKit.getRandomSalt(5)); String salt = ShiroKit.getRandomSalt(5);
user.setPassword(ShiroKit.md5(user.getPassword(), user.getSalt())); String password = ShiroKit.md5(user.getPassword(), salt);
user.setStatus(ManagerStatus.OK.getCode());
user.setCreatetime(new Date());
this.userService.insert(UserFactory.createUser(user)); this.userService.insert(UserFactory.createUser(user, password, salt));
return SUCCESS_TIP; return SUCCESS_TIP;
} }
/** /**
* 修改管理员 * 修改管理员
*
* @throws NoPermissionException
*/ */
@RequestMapping("/edit") @RequestMapping("/edit")
@BussinessLog(value = "修改管理员", key = "account", dict = UserDict.class) @BussinessLog(value = "修改管理员", key = "account", dict = UserDict.class)
@ResponseBody @ResponseBody
public ResponseData edit(@Valid UserDto user, BindingResult result) throws NoPermissionException { public ResponseData edit(@Valid UserDto user, BindingResult result) {
if (result.hasErrors()) { if (result.hasErrors()) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL); throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
} }
......
...@@ -15,11 +15,18 @@ ...@@ -15,11 +15,18 @@
*/ */
package cn.stylefeng.guns.modular.system.factory; package cn.stylefeng.guns.modular.system.factory;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.stylefeng.guns.core.common.constant.state.ManagerStatus;
import cn.stylefeng.guns.modular.system.model.User; import cn.stylefeng.guns.modular.system.model.User;
import cn.stylefeng.guns.modular.system.transfer.UserDto; import cn.stylefeng.guns.modular.system.transfer.UserDto;
import cn.stylefeng.roses.core.util.ToolUtil; import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/** /**
* 用户创建工厂 * 用户创建工厂
* *
...@@ -28,16 +35,26 @@ import org.springframework.beans.BeanUtils; ...@@ -28,16 +35,26 @@ import org.springframework.beans.BeanUtils;
*/ */
public class UserFactory { public class UserFactory {
public static User createUser(UserDto userDto) { /**
* 根据请求创建实体
*/
public static User createUser(UserDto userDto, String md5Password, String salt) {
if (userDto == null) { if (userDto == null) {
return null; return null;
} else { } else {
User user = new User(); User user = new User();
BeanUtils.copyProperties(userDto, user); BeanUtils.copyProperties(userDto, user);
user.setCreatetime(new Date());
user.setStatus(ManagerStatus.OK.getCode());
user.setPassword(md5Password);
user.setSalt(salt);
return user; return user;
} }
} }
/**
* 更新user
*/
public static User editUser(UserDto newUser, User oldUser) { public static User editUser(UserDto newUser, User oldUser) {
if (newUser == null || oldUser == null) { if (newUser == null || oldUser == null) {
return oldUser; return oldUser;
...@@ -66,4 +83,19 @@ public class UserFactory { ...@@ -66,4 +83,19 @@ public class UserFactory {
return oldUser; return oldUser;
} }
} }
/**
* 过滤不安全字段并转化为map
*/
public static Map<String, Object> removeUnSafeFields(User user) {
if (user == null) {
return new HashMap<>();
} else {
Map<String, Object> map = BeanUtil.beanToMap(user);
map.remove("password");
map.remove("salt");
map.put("birthday", DateUtil.formatDate(user.getBirthday()));
return map;
}
}
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package cn.stylefeng.guns.modular.system.transfer; package cn.stylefeng.guns.modular.system.transfer;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
...@@ -25,12 +26,12 @@ import java.util.Date; ...@@ -25,12 +26,12 @@ import java.util.Date;
* @author stylefeng * @author stylefeng
* @Date 2017/5/5 22:40 * @Date 2017/5/5 22:40
*/ */
@Data
public class UserDto { public class UserDto {
private Integer id; private Integer id;
private String account; private String account;
private String password; private String password;
private String salt;
private String name; private String name;
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
...@@ -41,128 +42,6 @@ public class UserDto { ...@@ -41,128 +42,6 @@ public class UserDto {
private String roleid; private String roleid;
private Integer deptid; private Integer deptid;
private Integer status; private Integer status;
private Date createtime;
private Integer version;
private String avatar; private String avatar;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getRoleid() {
return roleid;
}
public void setRoleid(String roleid) {
this.roleid = roleid;
}
public Integer getDeptid() {
return deptid;
}
public void setDeptid(Integer deptid) {
this.deptid = deptid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getCreatetime() {
return createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
} }
...@@ -72,12 +72,14 @@ ...@@ -72,12 +72,14 @@
<script type="text/javascript"> <script type="text/javascript">
var ZTreeDlg = { var ZTreeDlg = {
index: parent.layer.getFrameIndex(window.name) index: parent.layer.getFrameIndex(window.name),
tempName: "",
tempId: ""
}; };
ZTreeDlg.onClickItem = function (e, treeId, treeNode) { ZTreeDlg.onClickItem = function (e, treeId, treeNode) {
${formName} = ZTreeDlg.instance.getSelectedVal(); ZTreeDlg.tempName = ZTreeDlg.instance.getSelectedVal();
${formId} = treeNode.id; ZTreeDlg.tempId = treeNode.id;
}; };
ZTreeDlg.onDBClickItem = function (e, treeId, treeNode) { ZTreeDlg.onDBClickItem = function (e, treeId, treeNode) {
...@@ -88,11 +90,13 @@ ...@@ -88,11 +90,13 @@
$(function () { $(function () {
$("#closeButton").bind("click", function () { $("#saveButton").bind("click", function () {
${formName} = ZTreeDlg.tempName;
${formId} = ZTreeDlg.tempId;
parent.layer.close(ZTreeDlg.index); parent.layer.close(ZTreeDlg.index);
}); });
$("#saveButton").bind("click", function () { $("#closeButton").bind("click", function () {
parent.layer.close(ZTreeDlg.index); parent.layer.close(ZTreeDlg.index);
}); });
......
@layout("/common/_dialog.html",{plugins:["laydate","sweet-alert","layer"],js:["/assets/modular/system/user/user_info.js"]}){ @layout("/common/_dialog.html",{plugins:["laydate","sweet-alert","layer"],js:["/assets/modular/system/user/user_add.js"]}){
<div class="container-fluid"> <div class="container-fluid">
<form id="userAddForm" \@submit="submitForm"> <form id="userForm" \@submit="submitForm">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<div class="form-group"> <div class="form-group">
...@@ -36,6 +36,13 @@ ...@@ -36,6 +36,13 @@
</div> </div>
<div class="col-6"> <div class="col-6">
<div class="form-group"> <div class="form-group">
<h5>出生日期</h5>
<div class="controls">
<input v-model="birthday" id="birthday" type="hidden" class="form-control" autocomplete="off">
<input id="dateSelect" type="text" class="form-control" autocomplete="off">
</div>
</div>
<div class="form-group">
<h5>性别</h5> <h5>性别</h5>
<div class="controls"> <div class="controls">
<select v-model="sex" class="form-control"> <select v-model="sex" class="form-control">
...@@ -46,12 +53,6 @@ ...@@ -46,12 +53,6 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<h5>出生日期</h5>
<div class="controls">
<input v-model="birthday" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<h5>部门 <span class="text-danger">*</span></h5> <h5>部门 <span class="text-danger">*</span></h5>
<div class="controls"> <div class="controls">
<input v-model="deptName" id="detpName" \@click="showDeptSelectTree" type="text" class="form-control" autocomplete="off"> <input v-model="deptName" id="detpName" \@click="showDeptSelectTree" type="text" class="form-control" autocomplete="off">
...@@ -75,8 +76,8 @@ ...@@ -75,8 +76,8 @@
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<div class="text-xs-right"> <div class="text-xs-right">
<button class="btn btn-info normal-button-width">提交</button> <button class="btn btn-info normal-button-width" \@click="ensure">提交</button>
<button class="btn btn-inverse normal-button-width m-l-10" onclick="UserInfoDlg.close()">取消</button> <button class="btn btn-inverse normal-button-width m-l-10" \@click="close">取消</button>
</div> </div>
</div> </div>
</div> </div>
......
@layout("/common/_container.html"){ @layout("/common/_container.html",{plugins:["sweet-alert"],js:["/assets/modular/system/user/user_chpwd.js"]}){
<div class="col-sm-4 col-sm-offset-4"> <div class="col-sm-4 col-sm-offset-4">
<div class="ibox float-e-margins"> <div class="ibox float-e-margins">
<div class="ibox-title"> <div class="ibox-title">
...@@ -30,5 +30,4 @@ ...@@ -30,5 +30,4 @@
</div> </div>
</div> </div>
</div> </div>
<script src="${ctxPath}/static/modular/system/user/user_info.js"></script>
@} @}
@layout("/common/_dialog.html",{plugins:["laydate","sweet-alert","layer"],js:["/assets/modular/system/user/user_info.js"]}){ @layout("/common/_dialog.html",{plugins:["laydate","sweet-alert","layer"],js:["/assets/modular/system/user/user_edit.js"]}){
<div class="container-fluid"> <div class="container-fluid">
<form id="userAddForm" \@submit="submitForm"> <form id="userForm" \@submit="submitForm">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<input v-model="id" type="hidden" id="id">
<div class="form-group"> <div class="form-group">
<h5>账号 <span class="text-danger">*</span></h5> <h5>账号 <span class="text-danger">*</span></h5>
<div class="controls"> <div class="controls">
...@@ -13,18 +10,6 @@ ...@@ -13,18 +10,6 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<h5>密码 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="password" type="password" class="form-control">
</div>
</div>
<div class="form-group">
<h5>重复密码 <span class="text-danger">*</span></h5>
<div class="controls">
<input v-model="rePassword" type="password" class="form-control">
</div>
</div>
<div class="form-group">
<h5>姓名 <span class="text-danger">*</span></h5> <h5>姓名 <span class="text-danger">*</span></h5>
<div class="controls"> <div class="controls">
<input v-model="name" type="text" class="form-control"> <input v-model="name" type="text" class="form-control">
...@@ -36,8 +21,6 @@ ...@@ -36,8 +21,6 @@
<input v-model="email" type="email" class="form-control"> <input v-model="email" type="email" class="form-control">
</div> </div>
</div> </div>
</div>
<div class="col-6">
<div class="form-group"> <div class="form-group">
<h5>性别</h5> <h5>性别</h5>
<div class="controls"> <div class="controls">
...@@ -48,12 +31,16 @@ ...@@ -48,12 +31,16 @@
</select> </select>
</div> </div>
</div> </div>
</div>
<div class="col-6">
<div class="form-group"> <div class="form-group">
<h5>出生日期</h5> <h5>出生日期</h5>
<div class="controls"> <div class="controls">
<input v-model="birthday" type="text" class="form-control"> <input v-model="birthday" id="birthday" type="hidden" class="form-control" autocomplete="off">
<input id="dateSelect" type="text" class="form-control" autocomplete="off">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<h5>部门 <span class="text-danger">*</span></h5> <h5>部门 <span class="text-danger">*</span></h5>
<div class="controls"> <div class="controls">
...@@ -78,8 +65,8 @@ ...@@ -78,8 +65,8 @@
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<div class="text-xs-right"> <div class="text-xs-right">
<button class="btn btn-info normal-button-width">提交</button> <button class="btn btn-info normal-button-width" \@click="ensure">提交</button>
<button class="btn btn-inverse normal-button-width m-l-10" onclick="UserInfoDlg.close()">取消</button> <button class="btn btn-inverse normal-button-width m-l-10" \@click="close">取消</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -10,52 +10,60 @@ ...@@ -10,52 +10,60 @@
}; };
$ax.prototype = { $ax.prototype = {
start : function () { start: function () {
var me = this; var me = this;
var result = "";
if (this.url.indexOf("?") == -1) { if (this.url.indexOf("?") === -1) {
this.url = this.url + "?jstime=" + new Date().getTime(); this.url = this.url + "?jstime=" + new Date().getTime();
} else { } else {
this.url = this.url + "&jstime=" + new Date().getTime(); this.url = this.url + "&jstime=" + new Date().getTime();
} }
$.ajax({ $.ajax({
type: this.type, type: me.type,
url: this.url, url: me.url,
dataType: this.dataType, dataType: me.dataType,
async: this.async, async: me.async,
data: this.data, data: me.data,
beforeSend: function(data) { beforeSend: function (data) {
}, },
success: function(data) { success: function (data) {
result = data;
if (me.success !== undefined) {
me.success(data); me.success(data);
}
}, },
error: function(data) { error: function (data) {
me.error(data); if (me.success !== undefined) {
me.success(data);
}
} }
}); });
return result;
}, },
set : function (key, value) { set: function (key, value) {
if (typeof key == "object") { if (typeof key === "object") {
for (var i in key) { for (var i in key) {
if (typeof i == "function") if (typeof i === "function")
continue; continue;
this.data[i] = key[i]; this.data[i] = key[i];
} }
} else { } else {
this.data[key] = (typeof value == "undefined") ? $("#" + key).val() : value; this.data[key] = (typeof value === "undefined") ? $("#" + key).val() : value;
} }
return this; return this;
}, },
setData : function(data){ setData: function (data) {
this.data = data; this.data = data;
return this; return this;
}, },
clear : function () { clear: function () {
this.data = {}; this.data = {};
return this; return this;
} }
...@@ -63,4 +71,4 @@ ...@@ -63,4 +71,4 @@
window.$ax = $ax; window.$ax = $ax;
} ()); }());
\ No newline at end of file \ No newline at end of file
...@@ -207,5 +207,23 @@ var Feng = { ...@@ -207,5 +207,23 @@ var Feng = {
testEmail: function (email) { testEmail: function (email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email); return re.test(email);
},
getUrlParam: function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
} else {
return null;
}
},
initLaydate: function (dateValue) {
laydate.render({
elem: '#dateSelect'
});
$("#dateSelect").val(dateValue);
},
getLaydate: function () {
return $("#dateSelect").val();
} }
}; };
...@@ -33,7 +33,7 @@ MgrUser.initColumn = function () { ...@@ -33,7 +33,7 @@ MgrUser.initColumn = function () {
*/ */
MgrUser.check = function () { MgrUser.check = function () {
var selected = $('#' + this.id).bootstrapTable('getSelections'); var selected = $('#' + this.id).bootstrapTable('getSelections');
if (selected.length == 0) { if (selected.length === 0) {
Feng.info("请先选中表格中的某一记录!"); Feng.info("请先选中表格中的某一记录!");
return false; return false;
} else { } else {
...@@ -46,7 +46,7 @@ MgrUser.check = function () { ...@@ -46,7 +46,7 @@ MgrUser.check = function () {
* 点击添加管理员 * 点击添加管理员
*/ */
MgrUser.openAddMgr = function () { MgrUser.openAddMgr = function () {
var index = layer.open({ this.layerIndex = layer.open({
type: 2, type: 2,
title: '添加管理员', title: '添加管理员',
area: ['800px', '580px'], //宽高 area: ['800px', '580px'], //宽高
...@@ -54,7 +54,6 @@ MgrUser.openAddMgr = function () { ...@@ -54,7 +54,6 @@ MgrUser.openAddMgr = function () {
maxmin: true, maxmin: true,
content: Feng.ctxPath + '/mgr/user_add' content: Feng.ctxPath + '/mgr/user_add'
}); });
this.layerIndex = index;
}; };
/** /**
...@@ -62,15 +61,14 @@ MgrUser.openAddMgr = function () { ...@@ -62,15 +61,14 @@ MgrUser.openAddMgr = function () {
*/ */
MgrUser.openChangeUser = function () { MgrUser.openChangeUser = function () {
if (this.check()) { if (this.check()) {
var index = layer.open({ this.layerIndex = layer.open({
type: 2, type: 2,
title: '编辑管理员', title: '编辑管理员',
area: ['800px', '500px'], //宽高 area: ['800px', '500px'], //宽高
fix: false, //不固定 fix: false,
maxmin: true, maxmin: true,
content: Feng.ctxPath + '/mgr/user_edit/' + this.seItem.id content: Feng.ctxPath + '/mgr/user_edit?userId=' + this.seItem.id
}); });
this.layerIndex = index;
} }
}; };
...@@ -79,15 +77,14 @@ MgrUser.openChangeUser = function () { ...@@ -79,15 +77,14 @@ MgrUser.openChangeUser = function () {
*/ */
MgrUser.roleAssign = function () { MgrUser.roleAssign = function () {
if (this.check()) { if (this.check()) {
var index = layer.open({ this.layerIndex = layer.open({
type: 2, type: 2,
title: '角色分配', title: '角色分配',
area: ['300px', '400px'], //宽高 area: ['300px', '400px'], //宽高
fix: false, //不固定 fix: false, //不固定
maxmin: true, maxmin: true,
content: Feng.ctxPath + '/mgr/role_assign/' + this.seItem.id content: Feng.ctxPath + '/mgr/role_assign?userId=' + this.seItem.id
}); });
this.layerIndex = index;
} }
}; };
......
/**
* 用户详情对话框(可用于添加和修改对话框)
*/
var UserInfoDlg = {
data: {
id: "",
account: "",
sex: "",
password: "",
rePassword: "",
avatar: "",
email: "",
name: "",
birthday: "",
deptid: "",
deptName: "",
phone: ""
}
};
/**
* 关闭此对话框
*/
UserInfoDlg.close = function () {
parent.layer.close(window.parent.MgrUser.layerIndex);
};
/**
* 验证表单
*/
UserInfoDlg.validateForm = function () {
var data = UserInfoDlg.data;
if (data.account && data.password && data.name && data.deptid) {
return true;
}
if (!data.account) {
return "请输入账号";
}
if (!(data.password === data.rePassword)) {
return "两次密码输入不一致";
}
if (!data.name) {
return "请输入姓名";
}
if (!data.deptid) {
return "请选择部门";
}
};
/**
* 提交添加用户
*/
UserInfoDlg.addSubmit = function () {
//注意!vue的model绑定和layui有冲突!手动赋值一下!
UserInfoDlg.data.birthday = Feng.getLaydate();
var ajax = new $ax(Feng.ctxPath + "/mgr/add", function (data) {
window.parent.Feng.success("添加成功!");
window.parent.MgrUser.table.refresh();
UserInfoDlg.close();
}, function (data) {
window.parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
});
ajax.set(this.data);
ajax.start();
};
$(function () {
UserInfoDlg.app = new Vue({
el: '#userForm',
data: UserInfoDlg.data,
methods: {
submitForm: function (e) {
e.preventDefault();
},
showDeptSelectTree: function () {
var formName = encodeURIComponent("parent.UserInfoDlg.app.deptName");
var formId = encodeURIComponent("parent.UserInfoDlg.app.deptid");
var treeUrl = encodeURIComponent(Feng.ctxPath + "/dept/tree");
layer.open({
type: 2,
title: '部门选择',
area: ['300px', '400px'],
content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl
});
},
ensure: function () {
var result = UserInfoDlg.validateForm();
if (result === true) {
UserInfoDlg.addSubmit();
} else {
Feng.alert(result);
}
},
close: function () {
UserInfoDlg.close();
}
}
});
//注意!vue的model绑定和layui有冲突!
Feng.initLaydate(UserInfoDlg.data.birthday);
});
/**
* 用户详情对话框(可用于添加和修改对话框)
*/
var UserInfoDlg = {
data: {
id: "",
account: "",
sex: "",
password: "",
rePassword: "",
avatar: "",
email: "",
name: "",
birthday: "",
deptid: "",
deptName: "",
phone: ""
}
};
/**
* 关闭此对话框
*/
UserInfoDlg.close = function () {
parent.layer.close(window.parent.MgrUser.layerIndex);
};
/**
* 验证表单
*/
UserInfoDlg.validateForm = function () {
var data = UserInfoDlg.data;
if (data.account && data.password && data.name && data.deptid) {
return true;
}
if (!data.account) {
return "请输入账号";
}
if (!(data.password === data.rePassword)) {
return "两次密码输入不一致";
}
if (!data.name) {
return "请输入姓名";
}
if (!data.deptid) {
return "请选择部门";
}
};
/**
* 修改密码
*/
UserInfoDlg.chPwd = function () {
var ajax = new $ax(Feng.ctxPath + "/mgr/changePwd", function (data) {
Feng.success("修改成功!");
}, function (data) {
Feng.error("修改失败!" + data.responseJSON.message + "!");
});
ajax.set("oldPwd");
ajax.set("newPwd");
ajax.set("rePwd");
ajax.start();
};
$(function () {
UserInfoDlg.app = new Vue({
el: '#userForm',
data: UserInfoDlg.data,
methods: {
submitForm: function (e) {
var result = UserInfoDlg.validateForm();
if (result === true) {
UserInfoDlg.addSubmit();
} else {
Feng.alert(result);
e.preventDefault();
}
},
showDeptSelectTree: function () {
var formName = encodeURIComponent("parent.UserInfoDlg.app.deptName");
var formId = encodeURIComponent("parent.UserInfoDlg.app.deptid");
var treeUrl = encodeURIComponent(Feng.ctxPath + "/dept/tree");
layer.open({
type: 2,
title: '部门选择',
area: ['300px', '400px'],
content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl
});
}
}
});
});
/**
* 用户详情对话框(可用于添加和修改对话框)
*/
var UserInfoDlg = {
data: {
id: "",
account: "",
sex: "",
email: "",
name: "",
birthday: "",
deptid: "",
deptName: "",
phone: "",
roleName: ""
}
};
/**
* 关闭此对话框
*/
UserInfoDlg.close = function () {
parent.layer.close(window.parent.MgrUser.layerIndex);
};
/**
* 验证表单
*/
UserInfoDlg.validateForm = function () {
var data = UserInfoDlg.data;
if (data.account && data.name && data.deptid) {
return true;
}
if (!data.account) {
return "请输入账号";
}
if (!data.name) {
return "请输入姓名";
}
if (!data.deptid) {
return "请选择部门";
}
};
/**
* 提交修改
*/
UserInfoDlg.editSubmit = function () {
//注意!vue的model绑定和layui有冲突!手动赋值一下!
UserInfoDlg.data.birthday = Feng.getLaydate();
var ajax = new $ax(Feng.ctxPath + "/mgr/edit", function (data) {
window.parent.Feng.success("修改成功!");
if (window.parent.MgrUser !== undefined) {
window.parent.MgrUser.table.refresh();
UserInfoDlg.close();
}
}, function (data) {
Feng.error("修改失败!" + data.responseJSON.message + "!");
});
ajax.set(UserInfoDlg.data);
ajax.start();
};
$(function () {
//获取用户信息
var ajax = new $ax(Feng.ctxPath + "/mgr/getUserInfo?userId=" + Feng.getUrlParam("userId"));
var result = ajax.start();
UserInfoDlg.data = result.data;
UserInfoDlg.app = new Vue({
el: '#userForm',
data: UserInfoDlg.data,
methods: {
submitForm: function (e) {
e.preventDefault();
},
showDeptSelectTree: function () {
var formName = encodeURIComponent("parent.UserInfoDlg.app.deptName");
var formId = encodeURIComponent("parent.UserInfoDlg.app.deptid");
var treeUrl = encodeURIComponent(Feng.ctxPath + "/dept/tree");
layer.open({
type: 2,
title: '部门选择',
area: ['300px', '400px'],
content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl
});
},
ensure: function () {
var result = UserInfoDlg.validateForm();
if (result === true) {
UserInfoDlg.editSubmit();
} else {
Feng.alert(result);
}
},
close: function () {
UserInfoDlg.close();
}
}
});
//注意!vue的model绑定和layui有冲突!
Feng.initLaydate(UserInfoDlg.data.birthday);
});
...@@ -100,7 +100,7 @@ UserInfoDlg.chPwd = function () { ...@@ -100,7 +100,7 @@ UserInfoDlg.chPwd = function () {
$(function () { $(function () {
UserInfoDlg.app = new Vue({ UserInfoDlg.app = new Vue({
el: '#userAddForm', el: '#userForm',
data: UserInfoDlg.data, data: UserInfoDlg.data,
methods: { methods: {
submitForm: function (e) { submitForm: function (e) {
...@@ -128,4 +128,8 @@ $(function () { ...@@ -128,4 +128,8 @@ $(function () {
} }
}); });
laydate.render({
elem: '#birthday'
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment