var testList=[
|
{"user":"admin","name":"admin","phone":"180","passwd":"123"},
|
{"user":"1000","name":"张三","phone":"180","passwd":"123"},
|
{"user":"1002","name":"李四","phone":"180","passwd":"123"}];
|
var form;
|
var table;
|
var element;
|
var userList = [];
|
var userData = null;
|
layui.use(['layer'], function () {
|
layer = layui.layer;
|
});
|
|
if (TEST_TAG) {
|
userList = testList;
|
|
renderUser();
|
}else{
|
//查询用户信息并渲染
|
queryUserList();
|
}
|
|
|
function rowClick(index) {
|
$("#userList tr:nth-child(odd)").css("background-color","#262d33");
|
$("#userList tr:nth-child(even)").css("background-color","#22282e");
|
$("#userList tr:nth-child("+(index+1)+")").css("background-color","#e45163");
|
userData = userList[index];
|
}
|
|
|
|
//查询用户信息
|
function queryUserList() {
|
userData = null;
|
$.get("./cgi-bin/user-manage/query", function (data, status) {
|
if ("success" == status) {
|
userList = data;
|
renderUser();
|
} else {
|
window.parent.notify("系统获取扩展设备列表出错!");
|
}
|
}, "json");
|
}
|
|
//渲染用户列表
|
function renderUser() {
|
var html = "";
|
// console.log(deviceList);
|
$.each(userList, function (index, item) {
|
html += "<tr onclick='rowClick("+index+")'><td>" + item.user + "</td>";
|
html += "<td>" + item.name + "</td>";
|
html += "<td>" + item.phone + "</td></tr>";
|
});
|
$("#userList").html(html);
|
}
|
|
//用户编辑
|
function userUpdate(state) {
|
$(".pop-btn").hide();
|
if(state=="edit"){
|
if(!userData){
|
layer.msg("请先选择用户信息!");
|
return ;
|
}
|
if(userData.user == "admin"){
|
layer.msg("admin账户是系统管理员账户,不能修改!");
|
return ;
|
}
|
$(".pop-name").html("编辑用户信息");
|
$("#edit").show();
|
$("#user-user").attr("readOnly",true);
|
$("#user-user").val(userData.user);
|
$("#user-name").val(userData.name);
|
$("#user-phone").val(userData.phone);
|
$("#user-passwd").val(userData.passwd);
|
}else{
|
$("#device-id").attr("readOnly",false);
|
$(".pop-name").html("新增用户信息");
|
$("#add").show();
|
}
|
|
layer.open({
|
skin: 'mypop',
|
type: 1,
|
title: false,
|
area: ['50%', '45%'],
|
closeBtn: 0,
|
shade: 0,
|
scrollbar: false,
|
content: $('#editDeviceDom')
|
});
|
}
|
|
//执行保存
|
function save(btn) {
|
var data = {
|
user : $("#user-user").val(),
|
name : $("#user-name").val(),
|
phone : $("#user-phone").val(),
|
passwd : $("#user-passwd").val()
|
};
|
console.log("----------需要执行保存的数据信息--------");
|
console.log(JSON.stringify(data));
|
|
if (!data.user) {
|
window.parent.notify("用户的登录账户不能为空!");
|
return;
|
}
|
if (!data.passwd) {
|
window.parent.notify("用户的密码不能为空!");
|
return;
|
}
|
|
var url = "./cgi-bin/user-manage/add";
|
if ("edit" == btn) {
|
url = "./cgi-bin/user-manage/edit";
|
}
|
$.post(url, JSON.stringify(data), function (data, status) {
|
if (data.code == "success") {
|
//关闭弹窗
|
closepopBtn();
|
window.parent.notify("数据保存成功,数据自动刷新!");
|
queryUserList();
|
} else {
|
window.parent.notify("数据保存失败,请重新操作!原因"+data.msg+"!");
|
}
|
}, "json");
|
}
|
|
//数据删除
|
function userDel() {
|
if(!userData){
|
layer.msg("请先选择用户信息!");
|
return ;
|
}
|
if(userData.user == "admin"){
|
layer.msg("admin账户是系统管理员账户,不能修改!");
|
return ;
|
}
|
var param = {"user": userData.user};
|
layer.confirm("确定删除用户"+userData.name+"的数据吗?", function (index) {
|
$.post("./cgi-bin/user-manage/delete", JSON.stringify(param), function (data, status) {
|
if ("success" == data.code) {
|
//关闭弹窗
|
closepopBtn();
|
window.parent.notify("数据删除成功,数据自动刷新!");
|
queryUserList();
|
} else {
|
//关闭弹窗
|
closepopBtn();
|
window.parent.notify("数据删除失败!");
|
}
|
}, "json");
|
},function (index) {
|
//关闭弹窗
|
closepopBtn();
|
});
|
}
|
|
//重置密码
|
function resetPasswd() {
|
if(!userData){
|
layer.msg("请先选择用户信息!");
|
return ;
|
}
|
if(userData.user == "admin"){
|
layer.msg("admin账户是系统管理员账户,不能修改!");
|
return ;
|
}
|
var param = {"user": userData.user};
|
layer.confirm("是否将用户"+userData.name+"的密码重置为:123456?", function (index) {
|
$.post("./cgi-bin/user-manage/reset-passwd", JSON.stringify(param), function (data, status) {
|
if ("success" == data.code) {
|
//关闭弹窗
|
closepopBtn();
|
window.parent.notify("操作成功,页面自动刷新!");
|
queryUserList();
|
} else {
|
//关闭弹窗
|
closepopBtn();
|
window.parent.notify("数据操作失败,请重新尝试!");
|
}
|
}, "json");
|
},function (index) {
|
//关闭弹窗
|
closepopBtn();
|
});
|
}
|
|
function closepopBtn() {
|
//清空表单信息
|
$("#device-expand")[0].reset();
|
userData = null;
|
$("#userList tr:nth-child(odd)").css("background-color","#262d33");
|
$("#userList tr:nth-child(even)").css("background-color","#22282e");
|
layer.closeAll();
|
}
|
|