IntelligentRecognition/ah-jjsp-web/.svn/pristine/59/597ea2efb3d0416ffd6b721dccb...

248 lines
6.2 KiB
Plaintext
Raw Normal View History

2024-05-24 16:09:40 +08:00
let table;
var logTable;
let form;
var per;
let page = 1, limit = 10;
layui.use(['layer', 'form', 'laydate', 'element'], function () {
var layer = layui.layer; //弹层
var laypage = layui.laypage; //分页
table = layui.table; //表格
form = layui.form;
laydate = layui.laydate;
laydate.render({
elem: '#workDay', //指定元素 元素选择器
type: 'date', //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
trigger: 'click',
range: true,
format: 'yyyy-MM-dd', //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss
max: Date.parse(new Date()),
btns: ['now', 'confirm'], //选择框右下角显示的按钮 清除-现在-确定
});
//注册权限
// per = getPer();
// console.log(per);
//初始化下拉选
pages(1,10,1);
// initTable();
// 查询按钮
$("#query").off().click(function () {
// 筛选校验
inputTest1('roleName', 20, '用户身份')
inputTest2('detail', 200, '操作内容')
ipTest()
pages(1,10)
return;
})
// 重置
$("#reset").off().click(function () {
pages(1,10,1)
})
})
// 输入框校验
function inputTest1 (field, length, fieldName) {
console.log('field----'+field);
console.log('length----'+length);
console.log(typeof length);
let query = $("#"+field).val()
console.log(query);
if (query.trim() === '') return
if (query && query.length > length) {
layer.alert(`${fieldName}长度大于${length}个字符!`, {icon: 2});
}
// 禁止输入表情
const reg = /[^0-9a-zA-Z\u4E00-\u9FA5]/g
if (!reg.test(query)) {
return
} else {
layer.alert(`${fieldName}内容包含特殊字符!`, {icon: 2});
// $("#"+field).val("")
return
}
}
function inputTest2 (field, length, fieldName) {
let query = $("#"+field).val()
if (query.trim() === '') return
if (!query && query.length > length) {
layer.alert(`${fieldName}长度大于${length}个字符!`, {icon: 2});
}
}
// IP地址校验
function ipTest () {
const operIp = $("#operIp").val()
if (operIp.trim() === '') return
const regStr = /^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$/
if (regStr.test(operIp)) {
return
} else {
layer.alert("IP地址格式不正确",{icon: 2});
// $("#operIp").val("")
return
}
}
// 备份
function handleBackup() {
$.ajax({
headers:{
"encrypt":sm3(JSON.stringify({
logType: '系统日志'
}))
},
url: dataUrl + 'system/sys/logs/copyLog' + '?token=' + token,
type: 'get',
data: {
logType: '系统日志'
},
success: function (res) {
console.log(res);
if (res.code === 200) {
layer.alert("备份成功",{icon: 1});
} else {
layer.alert("备份失败",{icon: 2});
}
}
});
}
// 恢复
function handleRecover() {
$.ajax({
headers:{
"encrypt":sm3(JSON.stringify({
logType: '系统日志'
}))
},
url: dataUrl + 'system/sys/logs/restoreLog' + '?token=' + token,
type: 'get',
data: {
logType: '系统日志'
},
success: function (res) {
console.log(res);
if (res.code === 200) {
layer.alert("恢复成功",{icon: 1});
} else {
layer.alert("恢复失败",{icon: 2});
}
}
});
}
function pages(page, limit,type) {
let params = getReqParamss(page,limit,type);
$.ajax({
headers:{
"encrypt":sm3(JSON.stringify(params))
},
url: dataUrl + 'system/sys/logs/getByPage?token=' + token, //数据接口(此处为静态数据,仅作演示)
data: params,
//content:'applicatiopn/json',
type: 'POST',
async: false,
success: function (result) {
if(result.code === 500){
layer.alert(result.msg,{icon:2})
}
if (result.data) {
//console.log(result.data)
initTable(result.data,result.limit,result.curr)
laypages(result.count, result.curr, result.limit)
}
}, error: function () {
}
});
}
function laypages(total, page, limit) {
layui.use(['laypage'], function () {
let laypage = layui.laypage;
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limit: limit,
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
groups: 5,
jump: function (obj, first) {
if (!first) {
page = obj.curr, limit = obj.limit;
pages(obj.curr, obj.limit,null);
}
}
});
})
}
// 获取参数
function getReqParamss(page,limit,type) {
let obj = {};
if(!type){
obj = {
page: page + "",
limit: limit + "",
roleName: $("#roleName").val(),
operIp: $("#operIp").val(),
workDay: $("#workDay").val(),
startTime: $("#workDay").val().split(' ')[0],
endTime: $("#workDay").val().split(' ')[2],
detail: $("#detail").val(),
status: $("#status").val(),
grade: $("#grade").val(),
orderType: $("#orderType").val() || 'create_time',
orderBy: $("#orderBy").val() || 'DESC',
logType: '系统日志',
};
}else{
obj = {
page: '1',
limit: '10',
roleName: "",
operIp: "",
workDay: "",
startTime: "",
endTime: "",
detail: "",
status: "",
grade: "",
orderType: "create_time",
orderBy: "DESC",
logType: '系统日志',
};
}
return obj;
}
function initTable(dataList,limit,page) {
// 执行一个 table 实例
logTable = table.render({
id: 'logTable',
elem: '#log-table',
height: $(window).height() - ($(window).height() * 0.25),
title: '日志表',
data:dataList,
cols: [[ //表头
{ field: "number", type: "numbers", title: "序号", width: 100, unresize: true, align: "center", },
{ field: 'roleName', title: '用户身份', align: 'center', unresize: true, },
{ field: 'operName', title: '操作用户名', align: 'center', unresize: true, },
{ field: 'operTime', title: '操作时间', align: 'center', unresize: true, },
{ field: 'operIp', title: 'IP地址', align: 'center', unresize: true, },
{ field: 'title', title: '业务模块', align: 'center', unresize: true, },
// { field: 'title', title: '所属菜单', align: 'center', unresize: true, },
{ field: 'detail', title: '操作内容', align: 'center', unresize: true, },
{ field: 'grade', title: '操作类型', align: 'center', unresize: true, },
{
field: 'status', title: '操作结果', align: 'center', unresize: true, templet: function (d) {
if (d.status == '0') {
return '成功'
} else if(d.status == '1') {
return '失败'
} else {
return ''
}
} },
]],
limit:limit
});
}