You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
361 lines
13 KiB
361 lines
13 KiB
<!DOCTYPE html>
|
|
<html lang="zh-cn">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<!--#include file="/widget/head.html"-->
|
|
<!--#include file="/widget/email-tail.html"-->
|
|
<style>
|
|
/*.layui-table-cell {*/
|
|
/* height: auto;*/
|
|
/*}*/
|
|
|
|
</style>
|
|
</head>
|
|
<body class="layui-layout-body" layadmin-themealias="default" >
|
|
<div id="wrapper">
|
|
<!-- Navigation -->
|
|
<!--#include file="/widget/nav.html"-->
|
|
<div id="page-wrapper" class="layui-body layadmin-tabsbody-item layui-show layui-fluid layui-row layui-col-space15">
|
|
<div class="layui-card">
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
<h2 class="page-header">系统账号</h2>
|
|
</div>
|
|
</div>
|
|
<div style="width:1400px;">
|
|
<div role="tabpanel" class="tab-pane" id="send">
|
|
<div class="layui-form">
|
|
|
|
<div class="layui-form-item layui-inline">
|
|
|
|
<label class="layui-form-label">用户</label>
|
|
<div class="layui-input-inline">
|
|
<input type="text" name="position" autocomplete="off" class="layui-input" id="account">
|
|
</div>
|
|
|
|
<div class="layui-inline" style="width:100px;">
|
|
<button class="layui-btn" type="button" id="query">查询</button>
|
|
</div>
|
|
<div class="layui-inline" style="width:100px;">
|
|
<button class="layui-btn" type="button" id="addAccount" lay-event="addAccount">添加账号</button>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="Datatab" lay-filter="Datatab" style="width:1100px;"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="crateAccount" style="display: none">
|
|
<div class="demo-login-container" >
|
|
<div class="form-group" data-id="djdiv">
|
|
|
|
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">account:</label>
|
|
<div class="layui-input-inline">
|
|
<input type="text" name="account" lay-verify="required" data-id="account" id="add_account" autocomplete="off"
|
|
class="layui-input">
|
|
</div>
|
|
</div>
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">name:</label>
|
|
<div class="layui-input-inline">
|
|
<input type="text" name="name" lay-verify="required" data-id="name" id="name" autocomplete="off"
|
|
class="layui-input">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">password:</label>
|
|
<div class="layui-input-inline">
|
|
<input type="text" name="password" lay-verify="required" data-id="password" id="password" autocomplete="off" class="layui-input">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">角色</label>
|
|
<div class="layui-input-inline" >
|
|
<div data-id="role" class="xm-select-demo" xm-select="role" id="role" lay-filter="select2">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
|
var tableIns;
|
|
var allRoles
|
|
$(function () {
|
|
$("#query").click(function () {
|
|
tableIns.reload({
|
|
where: {
|
|
token: cookie.get("token"),
|
|
name: $("#account").val(),
|
|
}
|
|
});
|
|
});
|
|
$("#addAccount").click(function () {
|
|
|
|
$("#crateAccount").show();
|
|
layer.open({
|
|
content: $("#crateAccount"),
|
|
type: 1,
|
|
title: "添加账号",
|
|
area: ['500px', '550px'],
|
|
btn:['保存', '关闭'],
|
|
yes: function () {
|
|
let account = $("#add_account").val();
|
|
let name = $("#name").val();
|
|
let password = $("#password").val();
|
|
|
|
|
|
if (account == "" || name == "" || password == "") {
|
|
layer.msg("请输入正确的参数")
|
|
return
|
|
}
|
|
if (!/^[a-zA-Z]+$/.test(account)) {
|
|
|
|
layer.msg('账号只能输入英文')
|
|
return ;
|
|
}
|
|
if (!/^[a-zA-Z]+$/.test(name)) {
|
|
|
|
layer.msg('账号只能输入英文')
|
|
return ;
|
|
}
|
|
|
|
if(password.length<6){
|
|
layer.msg("密码过于简单");
|
|
return ;
|
|
}
|
|
let roles = addRoleXm.getValue();
|
|
let roleIds=[];
|
|
roles.map(function(d){
|
|
roleIds.push(d.value);
|
|
})
|
|
var encrypted = CryptoJS.enc.Hex.stringify(CryptoJS.SHA1(password));
|
|
|
|
$.get(Page.SvrIp + "/api/create_account",
|
|
{token: cookie.get("token"),
|
|
account:account,
|
|
name:name,
|
|
password:encrypted,
|
|
roles:roleIds.join(","),
|
|
},
|
|
function (d) {
|
|
if(d.ret!=0);
|
|
|
|
layer.msg("添加失败")
|
|
return;
|
|
});
|
|
layer.closeAll();
|
|
$("#crateAccount").hide();
|
|
window.location.reload();
|
|
},
|
|
btn2:function(){
|
|
$("#crateAccount").hide();
|
|
},
|
|
end:function (){
|
|
$("#crateAccount").hide();
|
|
}
|
|
});
|
|
})
|
|
|
|
|
|
LoadAllRoles();
|
|
|
|
layui.table.on('tool(Datatab)', function(obj){
|
|
debugger;
|
|
var account = obj.data.account ;
|
|
var id =obj.data.id;
|
|
if(obj.event=="DelAccount"){
|
|
layer.msg('确定要删除?', {
|
|
time: 200000, //20s后自动关闭
|
|
btn: ['删除', '再想想'],
|
|
yes: function(index, layero){
|
|
DeleteAccount(account)
|
|
layer.msg('删除');
|
|
window.location.reload();
|
|
},
|
|
btn2:function(index, layero){
|
|
layer.msg('再想想');
|
|
},
|
|
|
|
});
|
|
}
|
|
|
|
if(obj.event=="UpdateAccount"){
|
|
layer.msg('确定要更新吗?', {
|
|
time: 200000, //20s后自动关闭
|
|
btn: ['更新', '再想想'],
|
|
yes: function(index, layero){
|
|
var rs=obj.data.xm.getValue();
|
|
let roleIds=[];
|
|
rs.map(function(d){
|
|
roleIds.push(d.value)
|
|
})
|
|
|
|
UpdateAccount({token: cookie.get("token"),account:account,roles:roleIds.join(",")})
|
|
layer.msg('更新成功');
|
|
},
|
|
btn2:function(index, layero){
|
|
layer.msg('再想想');
|
|
},
|
|
|
|
});
|
|
}
|
|
})
|
|
});
|
|
|
|
function DeleteAccount(account){
|
|
$.get(Page.SvrIp + "/api/delete_account", {token: cookie.get("token"),account:account},
|
|
function (d) {
|
|
|
|
});
|
|
}
|
|
|
|
//更新账号角色
|
|
function UpdateAccount(data){
|
|
$.ajax({
|
|
type: "get",
|
|
url: Page.SvrIp + "/api/update_account_role",
|
|
data: data,
|
|
dataType: "json",
|
|
success: function (d) {
|
|
parent.layer.msg(d.msg);
|
|
parent.layer.close(loadIndex);
|
|
if (d.code == 0) {
|
|
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
|
parent.location.reload();
|
|
}
|
|
},
|
|
error: function (status) {
|
|
console.dir(status)
|
|
parent.layer.close(loadIndex);
|
|
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
|
parent.location.reload();
|
|
}
|
|
});
|
|
}
|
|
function InitTable() {
|
|
tableIns = layui.table.render({
|
|
elem: '#Datatab',
|
|
height:500
|
|
, url: Page.SvrIp +'/api/all_account' //数据接口
|
|
, where: {
|
|
token: cookie.get("token"),
|
|
name: $("#account").val()
|
|
}
|
|
, page: true
|
|
, cols: [[
|
|
{field: 'account', title: '账号', width: 100,},
|
|
{ field: 'name', title: '名字', width: 100 },
|
|
{ field: 'valid', title: '是否有效', width: 100 },
|
|
{ field: 'role', title: '角色', width: 500,
|
|
templet: function (d) {
|
|
return '<div class="xm-select-demo" id="'+ d.account +'" xm-select="select' + d.account + '">' + '</div>';
|
|
}},
|
|
{ field: 'lastLoginTime', title: '登陆时间', width: 200 },
|
|
{ field: 'cTime', title: '创建时间', width: 200 },
|
|
{field: 'op',title: '操作',width:200,templet:function (d){
|
|
|
|
let roles=d.roles;
|
|
let isAdmin=false;
|
|
if(roles!=undefined){
|
|
roles.forEach(function (role) {
|
|
if(role.Name=="Administrator"){
|
|
isAdmin=true;
|
|
}
|
|
})
|
|
}
|
|
if(isAdmin){
|
|
return '<button type="button" class="layui-btn get" lay-event="UpdateAccount">更新</button>';
|
|
}
|
|
return '<button type="button" class="layui-btn get" lay-event="UpdateAccount">更新</button>' +
|
|
'<button type="button" class="layui-btn layui-btn-danger del" lay-event="DelAccount">删除</button>';
|
|
}}
|
|
]]
|
|
|
|
, parseData: function (res) { //res 即为原始返回的数据
|
|
if (res.ret == 1) {
|
|
location.href = "/pages/login.html";
|
|
}
|
|
return {
|
|
"code": res.ret, //解析接口状态
|
|
"msg": res.msg, //解析提示文本
|
|
"count": res.count, //解析数据长度
|
|
"data": res.data //解析数据列表
|
|
};
|
|
},
|
|
done: function(data){
|
|
var cells = document.querySelectorAll('div[lay-id="Datatab"] .layui-table-cell');
|
|
for(var i = 0 ; i < cells.length ; i++ ){
|
|
cells[i].style.overflow = 'unset';
|
|
//cells[i].style.height = 'auto';
|
|
}
|
|
data.data.forEach(d=>{
|
|
xm=xmSelect.render({
|
|
el: '#' + d.account,
|
|
name: 'options',
|
|
data: getOptionsData(d),
|
|
autoRow: true,
|
|
filterable: true,
|
|
height: '250px',
|
|
});
|
|
d.xm=xm;
|
|
})
|
|
}
|
|
});
|
|
}
|
|
function getOptionsData(data) {
|
|
// debugger
|
|
let roles=data.roles;
|
|
let ids=[];
|
|
if(roles!=undefined){
|
|
roles.forEach(function (role) {
|
|
ids.push(role.Id);
|
|
})
|
|
}
|
|
var op= allRoles.map(function (option) {
|
|
return { name: option.Name, value: option.Id ,selected:ids.includes(option.Id)};
|
|
});
|
|
return op;
|
|
}
|
|
let addRoleXm
|
|
function LoadAllRoles() {
|
|
$.get(Page.SvrIp + "/api/all_role",
|
|
{token: cookie.get("token")}
|
|
, function (d) {
|
|
allRoles = d.data;
|
|
InitTable();
|
|
|
|
xm=xmSelect.render({
|
|
el: '#role',
|
|
name: 'options',
|
|
data: getOptionsData([]),
|
|
autoRow: true,
|
|
filterable: true,
|
|
height: '350px',
|
|
});
|
|
addRoleXm=xm;
|
|
});
|
|
}
|
|
|
|
</script>
|
|
<script src="../bower_components/crypto-js/crypto-js.js"></script>
|
|
<script type="text/javascript" src="../js/template-web.js"></script>
|
|
<script type="text/javascript" src="../js/notice/xm-select.js"></script>
|
|
<!--<link href="../bower_components/select2/select2.min.css" rel="stylesheet" type="text/css">-->
|
|
<!--<script type="text/javascript" src="../bower_components/select2/select2.min.js"></script>-->
|
|
|
|
</body>
|
|
</html>
|
|
|