ah_sz_gqj/src/main/resources/static/js/system/userMge.js

322 lines
10 KiB
JavaScript
Raw Normal View History

2024-07-20 14:56:38 +08:00
let form, layer, dtree, table, tableIns;
2024-07-17 09:44:55 +08:00
let pageNum = 1, limitSize = 10; // 默认第一页分页数量为10
2024-07-20 14:56:38 +08:00
let orgData,selectOrgId;
layui.config({
base: "../../js/layui-v2.6.8/dtree/", //此处路径请自行处理, 可以使用绝对路径
}).extend({
dtree: 'dtree'
}).use(['form', 'layer', 'table','dtree', 'laydate'], function () {
2024-07-17 09:44:55 +08:00
form = layui.form;
layer = layui.layer;
table = layui.table;
2024-07-20 14:56:38 +08:00
dtree = layui.dtree;
2024-07-17 09:44:55 +08:00
layui.form.render();
2024-07-20 14:56:38 +08:00
orgData = getOrgTree();
2024-07-17 09:44:55 +08:00
pages(1, 10, 1);
2024-07-20 14:56:38 +08:00
form.on('switch(is-state)', function (obj) {
console.log(obj);
let url = dataUrl + "/users/updateEnableState";
let params = {
'id': this.value,
'state': obj.elem.checked ? 1 : 0
}
params={
encryptedData:encryptCBC(JSON.stringify(params))
}
ajaxRequest(url, "POST", params, true, function () {}, function (result) {
console.log(result)
reloadData();
if (result.status === 200) {
parent.layer.msg(result.data, {icon: 1})
} else if (result.status === 204) {
parent.layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
});
});
2024-07-17 09:44:55 +08:00
})
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
let url = dataUrl + "/users/getList"
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
console.log(result);
if (result.code === 200) {
if (result.data) {
initTable(result.data, result.limit, result.curr)
laypages(result.count, result.curr, result.limit)
}
} else if (result.code === 500) {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
});
2024-07-20 14:56:38 +08:00
2024-07-17 09:44:55 +08:00
}
function laypages(total, page, limit) {
layui.use(['laypage'], function () {
let laypage = layui.laypage;
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limit: limit,
limits: [10, 20, 50, 100, 200, 500],
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
groups: 5,
jump: function (obj, first) {
if (!first) {
pageNum = obj.curr, limitSize = obj.limit;
pages(obj.curr, obj.limit, null);
}
}
});
})
}
/*初始化表格*/
function initTable(dataList, limit, page) {
let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
tableIns = table.render({
elem: "#table_data",
height: "full-130",
data: dataList,
limit: limit,
cols: [
[
//表头
{title: "序号", width: 80, unresize: true, align: "center",
templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
},
{field: "loginName", title: "登录名", unresize: true, align: "center"},
2024-07-20 14:56:38 +08:00
{field: "username", title: "用户名", unresize: true, align: "center"},
{field: "userCode", title: "工号", unresize: true, align: "center"},
{field: "sex", title: "性别", unresize: true, align: "center",
templet: function (d) {
if (d.sex == 0) {
return "女";
} else if (d.sex == 1) {
return "男";
2024-07-17 09:44:55 +08:00
}
2024-07-20 14:56:38 +08:00
}
},
{field: "orgName", title: "单位部门", unresize: true, align: "center"},
{field: "roleName", title: "角色", unresize: true, align: "center"},
{field: "phone", title: "联系电话", unresize: true, align: "center"},
{field: "userType", title: "用户类型", unresize: true, align: "center"},
{field: "state", title: "启用状态", align: "center",templet: '#is-state'},
2024-07-17 09:44:55 +08:00
{title: "操作", unresize: true, width: 300, align: "center",
templet: function (d) {
let html = '';
2024-07-20 14:56:38 +08:00
// let updaetpwd="<a class=\"layui-icon layui-icon-password\" style='cursor:pointer;' title='修改密码' onclick=\"resetPwd('" + d.id + "')\"></a>";
2024-07-17 09:44:55 +08:00
let del="<a class=\"layui-icon layui-icon-delete\" style='cursor:pointer;' title='删除' onclick=\"delData('" + d.id + "')\"></a>"
let edit="<a class=\"layui-icon layui-icon-edit\" style='cursor:pointer;' title='修改' onclick=\"addData('" + d.id + "')\"></a>";
2024-07-20 14:56:38 +08:00
html=edit+del;
2024-07-17 09:44:55 +08:00
if(d.delFlag==1){
2024-07-20 14:56:38 +08:00
return '';
2024-07-17 09:44:55 +08:00
}
return html;
}
},
],
],
done: function (res, curr, count) {
layer.close(loadingMsg);
table.resize("table_data");
count || this.elem.next(".layui-table-view").find(".layui-table-header").css("display", "inline-block");
count || this.elem.next(".layui-table-view").find(".layui-table-box").css("overflow", "auto");
},
});
}
// 获取参数
function getReqParams(page, limit, type) {
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
userName: $('#userName').val(),
2024-07-20 14:56:38 +08:00
phone: $('#phone').val(),
orgId: $('#orgId').val(),
userType: $('#userType').val(),
2024-07-17 09:44:55 +08:00
};
} else {
obj = {
page: '1',
limit: '10',
userName: '',
2024-07-20 14:56:38 +08:00
phone:'',
orgId:'',
userType: '',
2024-07-17 09:44:55 +08:00
};
}
console.log(obj)
obj={
encryptedData:encryptCBC(JSON.stringify(obj))
}
return obj;
}
// 查询/重置
function query() {
let pattern = new RegExp("[%_<>]");
if (pattern.test($("#loginName").val())) {
$("#loginName").val('');
return layer.msg('用户名查询包含特殊字符,请重新输入', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
if (pattern.test($("#phone").val())) {
$("#phone").val('');
return layer.msg('手机号查询包含特殊字符,请重新输入', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
pageNum = 1;
pages(1, limitSize);
}
2024-07-20 14:56:38 +08:00
//重置
function reset() {
pages(1, limitSize, 1)
}
2024-07-17 09:44:55 +08:00
function reloadData() {
pages(pageNum, limitSize);
}
// 新增/修改平台用户
function addData(id) {
let title = '新增用户'
if (id) {
title = '修改用户';
}
let param = {
'id': id
}
openIframe2("addOrEditUser", title, "child/userForm.html", '1000px', '625px', param);
}
/*删除用户*/
function delData(id) {
layer.confirm("确定删除吗?", {
move: false
}, function () {
let loadingMsg = layer.msg('数据删除中,请稍候...', {icon: 16, scrollbar: false, time: 0});
let url = dataUrl + "/users/delById";
let params = {
'id': id
}
params={
encryptedData:encryptCBC(JSON.stringify(params))
}
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
layer.close(loadingMsg); // 关闭提示层
if (result.code === 200) {
parent.layer.msg(result.msg, {icon: 1})
query()
} else if (result.code === 500) {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
layer.close(loadingMsg); // 关闭提示层
error(xhr)
});
})
}
// 启用/停用/解除锁定
function editUserAccountStatus(id, status, type) {
let url = dataUrl + "/sys/user/editUserAccountStatus?token=" + token;
let params = {
'id': id,
'accountStatus': status,
'type': type
}
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
if (result.code === 200) {
if(type){
reloadData();
}
parent.layer.msg(result.msg, {icon: 1})
} else if (result.code === 500) {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
});
}
// 管理员修改密码
function resetPwd(id) {
let param = {
'id': id,
'type': '1'
}
openIframe2("addOrEditUnifyUser", '修改密码', "password.html", '770px', '400px', param);
}
2024-07-20 14:56:38 +08:00
function getOrgTree() {
let data = [];
let url = dataUrl + '/users/getOrg';
2024-07-17 09:44:55 +08:00
ajaxRequest(url, "POST", null, true, function () {
}, function (result) {
if (result.code === 200) {
2024-07-20 14:56:38 +08:00
console.log(result,"getOrgTree")
data = result.data;
setOrgTree(data)
2024-07-17 09:44:55 +08:00
} else {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
});
2024-07-20 14:56:38 +08:00
return data;
}
function setOrgTree(data){
console.log("data",data)
orgTree = dtree.renderSelect({
elem: "#orgId",
data: data,
dataFormat: "list",
skin: "laySimple",
line: true, // 显示树线
checkbar: false, //开启复选框
done: function (data, url, first) {
console.log($('#orgId').val())
if (first) {
var params = dtree.dataInit("orgId", $('#orgId').val());
var selectParam = dtree.selectVal("orgId");
console.log(params)
}
}
});
2024-07-17 09:44:55 +08:00
}
/*下拉选表单赋值*/
function setSelectValue(list, selectName) {
2024-07-20 14:56:38 +08:00
let html = '<option value="" selected>单位部门</option>';
2024-07-17 09:44:55 +08:00
$.each(list, function (index, item) {
html += '<option value="' + item.id + '">' + item.name + '</option>';
})
$('#' + selectName).empty().append(html);
layui.form.render();
}