【user.js】修改新版js

pull/65/head
chenjinlong 4 years ago
parent b117523caf
commit 8cc435d112

@ -1,107 +1,59 @@
layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'HttpRequest', 'func', 'tree', 'util'], function () { layui.use(['layer', 'form', 'table', 'util', 'admin', 'tree', 'dropdown', 'xmSelect', 'treeTable', 'func', 'HttpRequest'], function () {
var $ = layui.jquery;
var layer = layui.layer; var layer = layui.layer;
var form = layui.form; var form = layui.form;
var table = layui.table; var table = layui.table;
var HttpRequest = layui.HttpRequest; var admin = layui.admin;
var laydate = layui.laydate;
var func = layui.func;
var tree = layui.tree; var tree = layui.tree;
var func = layui.func;
var util=layui.util; var HttpRequest = layui.HttpRequest;
var xmSelect = layui.xmSelect;
var selObj, treeData; // 左树选中数据
/** /**
* 系统管理--用户管理 * 系统管理--用户管理
*/ */
var MgrUser = { var OrganizationUser = {
tableId: "userTable", //表格id tableId: "userTable", //表格id
condition: {
realName: "",
orgId: "",
account: ""
}
};
/**
* 初始化表格的列
*/
MgrUser.initColumn = function () {
//获取多语言
//var langs = layui.data('system').lang;
return [[
{type: 'checkbox'},
{field: 'userId', hide: true, sort: true, title: '用户id'},
{field: 'account', align: "center", sort: true, title: '账号'},
{field: 'realName', align: "center", sort: true, title: '姓名'},
{field: 'orgId', align: "center", sort: true, title: '机构'},
{field: 'positionId', align: "center", sort: true, title: '职务'},
{field: 'phone', align: "center", sort: true, title: '电话'},
{field: 'createTime', align: "center", sort: true, title: '创建时间', minWidth: 160},
{field: 'status', align: "center", sort: true, templet: '#statusTpl', title: '状态'},
{align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 350}
]];
};
/**
* 选择部门时
*/
MgrUser.onClickDept = function (obj) {
MgrUser.condition.orgId = obj.data.id;
MgrUser.search();
}; };
/** /* 点击新增对话框 */
* 点击查询按钮 OrganizationUser.openAddDlg = function () {
*/
MgrUser.search = function () {
var queryData = {};
queryData['orgId'] = MgrUser.condition.orgId;
queryData['account'] = $("#account").val();
queryData['realName'] = $("#realName").val();
table.reload(MgrUser.tableId, {
where: queryData, page: {curr: 1}
});
};
// 添加按钮
MgrUser.openAddUser = function () {
func.open({ func.open({
height: 680, height: 680,
title: '添加用户', title: '添加用户',
content: Feng.ctxPath + '/view/user/addView', content: Feng.ctxPath + '/view/user/addView',
tableId: MgrUser.tableId tableId: OrganizationUser.tableId
}); });
}; };
// 修改按钮 /* 点击编辑对话框 */
MgrUser.onEditUser = function (data) { OrganizationUser.openEditDlg = function (data) {
func.open({ func.open({
height: 680, height: 680,
title: '修改用户', title: '修改用户',
content: Feng.ctxPath + '/view/user/editView?userId=' + data.userId, content: Feng.ctxPath + '/view/user/editView?userId=' + data.userId,
tableId: MgrUser.tableId tableId: OrganizationUser.tableId
}); });
}; };
/** /* 修改用户状态 */
* 导出excel按钮 OrganizationUser.changeUserStatus = function (userId, checked) {
*/ new HttpRequest(Feng.ctxPath + "/sysUser/changeStatus", 'post', function (data) {
MgrUser.exportExcel = function () { table.reload(OrganizationUser.tableId);
var checkRows = table.checkStatus(MgrUser.tableId); Feng.success("修改成功!");
if (checkRows.data.length === 0) { }, function (data) {
Feng.error("请选择要导出的数据"); table.reload(OrganizationUser.tableId);
} else { Feng.error("修改失败!" + data.message);
table.exportFile(tableResult.config.id, checkRows.data, 'xls'); }).set({"userId": userId, "statusFlag": checked}).start(true);
}
}; };
// 删除用户 /* 点击删除 */
MgrUser.onDeleteUser = function (data) { OrganizationUser.onDeleteUser = function (data) {
var operation = function () { var operation = function () {
var httpRequest = new HttpRequest(Feng.ctxPath + "/sysUser/delete", 'post', function (data) { var httpRequest = new HttpRequest(Feng.ctxPath + "/sysUser/delete", 'post', function (data) {
Feng.success("删除成功!"); Feng.success("删除成功!");
table.reload(MgrUser.tableId); table.reload(OrganizationUser.tableId);
}, function (data) { }, function (data) {
Feng.error("删除失败!" + data.message + "!"); Feng.error("删除失败!" + data.message + "!");
}); });
@ -110,23 +62,22 @@ layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'HttpRequest',
}; };
Feng.confirm("是否删除用户" + data.account + "?", operation); Feng.confirm("是否删除用户" + data.account + "?", operation);
}; };
// 分配角色 // 分配角色
MgrUser.roleAssign = function (data) { OrganizationUser.roleAssign = function (data) {
func.open({ func.open({
title: '授权角色', title: '授权角色',
height: 470, height: 470,
content: Feng.ctxPath + '/view/user/roleView?userId=' + data.userId, content: Feng.ctxPath + '/view/user/roleView?userId=' + data.userId,
tableId: MgrUser.tableId tableId: OrganizationUser.tableId
}); });
}; };
// 重置密码 // 重置密码
MgrUser.resetPassword = function (data) { OrganizationUser.resetPassword = function (data) {
Feng.confirm("是否重置密码为" + $("#defaultPassword").val() + "?", function () { Feng.confirm("是否重置密码为" + $("#defaultPassword").val() + "?", function () {
var httpRequest = new HttpRequest(Feng.ctxPath + "/sysUser/resetPwd", 'post', function (data) { var httpRequest = new HttpRequest(Feng.ctxPath + "/sysUser/resetPwd", 'post', function (data) {
Feng.success("重置密码成功!"); Feng.success("重置密码成功!");
table.reload(MgrUser.tableId); table.reload(OrganizationUser.tableId);
}, function (data) { }, function (data) {
Feng.error("重置密码失败!" + data.message + "!"); Feng.error("重置密码失败!" + data.message + "!");
}); });
@ -135,70 +86,82 @@ layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'HttpRequest',
}); });
}; };
// 修改用户状态 /* 渲染树形 */
MgrUser.changeUserStatus = function (userId, checked) { function renderTree() {
$.get(Feng.ctxPath + '/hrOrganization/treeLayui', function (res) {
var httpRequest = new HttpRequest(Feng.ctxPath + "/sysUser/changeStatus", 'post', function (data) { tree.render({
table.reload(MgrUser.tableId); elem: '#organizationTree',
Feng.success("修改成功!"); onlyIconControl: true,
}, function (data) { data: res.data,
table.reload(MgrUser.tableId); click: function (obj) {
Feng.error("修改失败!" + data.message); selObj = obj;
$('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
$(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
insTb.reload({
where: {orgId: obj.data.id},
page: {curr: 1},
url: Feng.ctxPath + '/sysUser/page',
});
}
});
$('#organizationTree').find('.layui-tree-entry:first>.layui-tree-main>.layui-tree-txt').trigger('click');
}); });
httpRequest.set({"userId": userId, "statusFlag": checked}); }
httpRequest.start(true);
};
// 渲染表格 renderTree();
var tableResult = table.render({
elem: '#' + MgrUser.tableId,
url: Feng.ctxPath + '/sysUser/page',
page: true,
height: "full-98",
cellMinWidth: 100,
cols: MgrUser.initColumn(),
parseData: Feng.parseData
});
// 初始化部门树 /* 添加 */
var request = new HttpRequest(Feng.ctxPath + '/hrOrganization/treeLayui', 'get', function (data) { $('#userAddBtn').click(function () {
tree.render({ OrganizationUser.openAddDlg();
elem: '#deptTree', return false;
data: data.data,
click: MgrUser.onClickDept,
onlyIconControl: true
});
}); });
request.start();
// 搜索按钮点击事件
$('#btnSearch').click(function () {
MgrUser.search();
});
// 添加按钮点击事件 /* 渲染表格 */
$('#btnAdd').click(function () { var insTb = table.render({
MgrUser.openAddUser(); elem: '#userTable',
data: [],
height: 'full-100',
page: true,
//toolbar: '#organizationUserTbToolBar',
cellMinWidth: 100,
cols: [[
{type: 'checkbox'},
{field: 'userId', hide: true, sort: true, title: '用户id'},
{field: 'account', align: "center", sort: true, title: '账号'},
{field: 'realName', align: "center", sort: true, title: '姓名'},
{field: 'positionId', align: "center", sort: true, title: '职务'},
{field: 'phone', align: "center", sort: true, title: '电话'},
{field: 'status', align: "center", templet: '#statusTpl', title: '状态'},
{title: '操作', toolbar: '#userTbBar'}
]],
done: function () {
// 表格搜索
form.on('submit(organizationUserTbSearch)', function (data) {
insTb.reload({where: data.field, page: {curr: 1}});
return false;
});
},
parseData: Feng.parseData
}); });
// 导出excel /* 点击搜索 */
$('#btnExp').click(function () { form.on('submit(userTbSearch)', function (data) {
MgrUser.exportExcel(); insTb.reload({where: data.field});
return false;
}); });
// 工具条点击事件 /* 表格工具条点击事件 */
table.on('tool(' + MgrUser.tableId + ')', function (obj) { table.on('tool(userTable)', function (obj) {
var data = obj.data; if (obj.event === 'edit') { // 修改
var layEvent = obj.event; OrganizationUser.openEditDlg(obj.data);
} else if (obj.event === 'delete') { // 删除
if (layEvent === 'edit') { OrganizationUser.onDeleteUser(obj.data);
MgrUser.onEditUser(data); } else if (obj.event === 'roleAssign') {
} else if (layEvent === 'delete') { OrganizationUser.roleAssign(obj.data);
MgrUser.onDeleteUser(data); } else if (obj.event === 'reset') {
} else if (layEvent === 'roleAssign') { OrganizationUser.resetPassword(obj.data);
MgrUser.roleAssign(data);
} else if (layEvent === 'reset') {
MgrUser.resetPassword(data);
} }
}); });
@ -206,15 +169,7 @@ layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'HttpRequest',
form.on('switch(status)', function (obj) { form.on('switch(status)', function (obj) {
var userId = obj.elem.value; var userId = obj.elem.value;
var checked = obj.elem.checked ? 1 : 2; var checked = obj.elem.checked ? 1 : 2;
MgrUser.changeUserStatus(userId, checked); OrganizationUser.changeUserStatus(userId, checked);
}); });
});
$(function () {
var panehHidden = false;
if ($(this).width() < 769) {
panehHidden = true;
}
$('#myContiner').layout({initClosed: panehHidden, west__size: 260});
}); });
Loading…
Cancel
Save