320 lines
8.2 KiB
JavaScript
320 lines
8.2 KiB
JavaScript
let urlIds=new Array();
|
||
initMenu();
|
||
initsy();
|
||
getExpireData();
|
||
|
||
function getExpireData(){
|
||
let url = dataUrl + "/home/getExpireData";
|
||
ajaxRequest(url, "POST", null, true, function () {
|
||
}, function (result) {
|
||
if (result.status === 200) {
|
||
setExpireData(result.data);
|
||
} else if (result.status === 500) {
|
||
layer.alert(result.msg, {icon: 2,move:false})
|
||
}
|
||
}, function (xhr) {
|
||
error(xhr)
|
||
});
|
||
}
|
||
|
||
function setExpireData(data){
|
||
console.log(data)
|
||
console.log(data.length)
|
||
if (data.length>0){
|
||
|
||
openIframe2("expireDataList", '临期数据', "pages/expireDataList.html", '80%', '80%','');
|
||
|
||
|
||
// layer.open({
|
||
// type: 2, // 表示iframe层
|
||
// title: '临期数据',
|
||
// content: 'pages/expireDataList.html?l=' + localStorage.getItem("lang") + '&token=' + localStorage.getItem("token"),
|
||
// area: ['800px', '600px'], // 宽高
|
||
// success: function(layero, index){
|
||
// // 可以在这里做一些操作,比如监听iframe内部的事件
|
||
// }
|
||
// });
|
||
}
|
||
}
|
||
function initMenu(){
|
||
$.ajax({
|
||
url: ctxPath + "/permissions/current",
|
||
type:"get",
|
||
async:false,
|
||
success:function(result){
|
||
if (result.status === 200) {
|
||
var data = result.data
|
||
console.log(data);
|
||
if(!$.isArray(data)){
|
||
location.href=ctxPath + '/login.html';
|
||
return;
|
||
}
|
||
var menu = $("#menu");
|
||
|
||
$.each(data, function(i,item){
|
||
var a = $("<a href='javascript:;'></a>");
|
||
var css = item.css;
|
||
if(css!=null && css!=""){
|
||
a.append("<i aria-hidden='true' class='fa " + css +"'></i>");
|
||
}
|
||
a.append("<cite>"+item.name+"</cite>");
|
||
a.attr("lay-id", item.id);
|
||
urlIds.push(item.id);
|
||
var href = item.href;
|
||
if(href != null && href != ""){
|
||
a.attr("data-url", href);
|
||
}
|
||
|
||
var li = $("<li class='layui-nav-item'></li>");
|
||
if (i == 0) {
|
||
li.addClass("layui-nav-itemed");
|
||
}
|
||
li.append(a);
|
||
menu.append(li);
|
||
//多级菜单
|
||
setChild(li, item.child)
|
||
});
|
||
localStorage.setItem("uelData",urlIds.join("@"));
|
||
} else if (result.status === 500) {
|
||
layer.alert(result.msg, {icon: 2})
|
||
}
|
||
|
||
}, error : function(xhr, textStatus, errorThrown) {
|
||
var msg = xhr.responseText;
|
||
var response = JSON.parse(msg);
|
||
var status = response.status;
|
||
var code = response.code;
|
||
if (status == 401 || code == 401) {
|
||
localStorage.removeItem("token");
|
||
}
|
||
}
|
||
});
|
||
}
|
||
function initsy() {
|
||
var $tabs=$('#menu');
|
||
var $tabsTitle = $tabs.find('.layui-nav-item a');
|
||
$.each($tabsTitle,function(idx, ele){
|
||
var id=$(ele).attr("lay-id");
|
||
$("#sy").attr("src","pages/home/home.html?token="+localStorage.getItem("token"));
|
||
})
|
||
}
|
||
function setChild(parentElement, child){
|
||
if(child != null && child.length > 0){
|
||
$.each(child, function(j,item2){
|
||
var ca = $("<a href='javascript:;'></a>");
|
||
ca.attr("data-url", item2.href);
|
||
ca.attr("lay-id", item2.id);
|
||
urlIds.push(item2.id)
|
||
var css2 = item2.css;
|
||
if(css2!=null && css2!=""){
|
||
ca.append("<i aria-hidden='true' class='fa " + css2 +"'></i>");
|
||
}
|
||
|
||
ca.append("<cite>"+item2.name+"</cite>");
|
||
|
||
var dd = $("<dd></dd>");
|
||
dd.append(ca);
|
||
|
||
var dl = $("<dl class='layui-nav-child'></dl>");
|
||
dl.append(dd);
|
||
parentElement.append(dl);
|
||
// 递归
|
||
setChild(dd, item2.child);
|
||
});
|
||
}
|
||
}
|
||
|
||
// 登陆用户头像昵称
|
||
showLoginInfo();
|
||
function showLoginInfo(){
|
||
$.ajax({
|
||
type : 'get',
|
||
url : ctxPath + '/users/current',
|
||
async : false,
|
||
success : function(result) {
|
||
if (result.status === 200) {
|
||
let data = result.data
|
||
$(".admin-header-user span").text(data.nickname);
|
||
|
||
var pro = window.location.protocol;
|
||
var host = window.location.host;
|
||
var domain = pro + "//" + host;
|
||
|
||
var sex = data.sex;
|
||
var url = data.headImgUrl;
|
||
if(url == null || url == ""){
|
||
if(sex == 1){
|
||
url = ctxPath + "/img/avatars/sunny.png";
|
||
} else {
|
||
url = ctxPath + "/img/avatars/1.png";
|
||
}
|
||
|
||
url = domain + url;
|
||
} else {
|
||
url = domain + "/statics" + url;
|
||
}
|
||
var img = $(".admin-header-user img");
|
||
img.attr("src", url);
|
||
}else if (result.status === 500) {
|
||
layer.alert(result.msg, {icon: 2})
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
|
||
|
||
function logout(){
|
||
$.ajax({
|
||
type : 'get',
|
||
url : ctxPath + '/logout',
|
||
success : function(data) {
|
||
localStorage.removeItem("token");
|
||
location.href= ctxPath + '/login.html';
|
||
}
|
||
});
|
||
}
|
||
|
||
function changeUserPwd(){
|
||
|
||
let param = {
|
||
'id': '',
|
||
'type': '2'
|
||
}
|
||
openIframe2("addOrEditUnifyUser", '修改密码', "pages/user/changeMessage.html", '770px', '400px', param);
|
||
}
|
||
|
||
|
||
var active;
|
||
var element ;
|
||
|
||
layui.use(['layer', 'element'], function() {
|
||
var $ = layui.jquery,
|
||
layer = layui.layer;
|
||
element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
|
||
element.on('nav(demo)', function(elem){
|
||
//layer.msg(elem.text());
|
||
});
|
||
|
||
//触发事件
|
||
active = {
|
||
tabAdd: function(obj){
|
||
var lay_id = $(this).attr("lay-id");
|
||
var title = $(this).html() + '<i class="layui-icon" data-id="' + lay_id + '"></i>';
|
||
//新增一个Tab项
|
||
element.tabAdd('admin-tab', {
|
||
title: title,
|
||
content: '<iframe src="' + $(this).attr('data-url')+'?token='+localStorage.getItem("token") + '"></iframe>',
|
||
id: lay_id
|
||
});
|
||
element.tabChange("admin-tab", lay_id);
|
||
},
|
||
tabDelete: function(lay_id){
|
||
element.tabDelete("admin-tab", lay_id);
|
||
},
|
||
tabChange: function(lay_id){
|
||
element.tabChange('admin-tab', lay_id);
|
||
}
|
||
};
|
||
//添加tab
|
||
$(document).on('click','a',function(){
|
||
if(!$(this)[0].hasAttribute('data-url') || $(this).attr('data-url')===''){
|
||
return;
|
||
}
|
||
var tabs = $(".layui-tab-title").children();
|
||
var lay_id = $(this).attr("lay-id");
|
||
|
||
for(var i = 0; i < tabs.length; i++) {
|
||
if($(tabs).eq(i).attr("lay-id") == lay_id) {
|
||
active.tabChange(lay_id);
|
||
return;
|
||
}
|
||
}
|
||
active["tabAdd"].call(this);
|
||
resize();
|
||
});
|
||
|
||
|
||
$(window).on('resize', function() {
|
||
var $content = $('.admin-nav-card .layui-tab-content');
|
||
$content.height($(this).height() - 147);
|
||
$content.find('iframe').each(function() {
|
||
$(this).height($content.height());
|
||
});
|
||
}).resize();
|
||
|
||
//toggle左侧菜单
|
||
$('.admin-side-toggle').on('click', function() {
|
||
var sideWidth = $('#admin-side').width();
|
||
if(sideWidth === 200) {
|
||
$('#admin-body').animate({
|
||
left: '0'
|
||
});
|
||
$('#admin-footer').animate({
|
||
left: '0'
|
||
});
|
||
$('#admin-side').animate({
|
||
width: '0'
|
||
});
|
||
} else {
|
||
$('#admin-body').animate({
|
||
left: '200px'
|
||
});
|
||
$('#admin-footer').animate({
|
||
left: '200px'
|
||
});
|
||
$('#admin-side').animate({
|
||
width: '200px'
|
||
});
|
||
}
|
||
});
|
||
|
||
//手机设备的简单适配
|
||
var treeMobile = $('.site-tree-mobile'),
|
||
shadeMobile = $('.site-mobile-shade');
|
||
treeMobile.on('click', function () {
|
||
$('body').addClass('site-mobile');
|
||
});
|
||
shadeMobile.on('click', function () {
|
||
$('body').removeClass('site-mobile');
|
||
});
|
||
});
|
||
|
||
/**
|
||
* 打开新页面
|
||
* @param url
|
||
* @param lay_id
|
||
* @param title
|
||
*/
|
||
function parentOpen(url,lay_id,title){
|
||
const isContained = urlIds.includes(lay_id);
|
||
if(!isContained){
|
||
return;
|
||
}
|
||
|
||
if ($(".layui-tab-title li[lay-id='" + lay_id + "']").length > 0) {
|
||
active.tabChange(lay_id);
|
||
return;
|
||
}
|
||
element.tabAdd('admin-tab', {
|
||
title: title,
|
||
content: '<iframe src="' + url+'?token='+localStorage.getItem("token") + '"></iframe>',
|
||
id: lay_id
|
||
});
|
||
|
||
element.tabChange("admin-tab", lay_id);
|
||
resize();
|
||
}
|
||
|
||
//iframe自适应
|
||
function resize(){
|
||
var $content = $('.admin-nav-card .layui-tab-content');
|
||
$content.height($(this).height() - 147);
|
||
$content.find('iframe').each(function() {
|
||
$(this).height($content.height());
|
||
});
|
||
}
|
||
|
||
|