ah_jjzhgd_webscreen/js/pages/home/navigation.js

113 lines
4.0 KiB
JavaScript

let element, layer, form, bidCode;
layui.use(['layer', 'element'], function () {
element = layui.element;
layer = layui.layer;
form = layui.form;
// 获取地址栏上的参数
const bidCodeParam = GetQueryString('bidCode');
const tokenParam = GetQueryString('token');
if (bidCodeParam && tokenParam) {
// 省侧大屏跳转施工大屏 调用后台返回用户信息
bidCode = decryptCBC(bidCodeParam);
const token = decryptCBC(tokenParam);
ajaxRequest2(page_jump, "GET", token, function (result) {
if (result.code === 200) {
sessionStorage.setItem("zhgd_token", result.data.access_token);
sessionStorage.setItem("zhgd_us", result.data.us.sysUser);
sessionStorage.setItem("zhgd_type", result.data.us.sysUser.jumpType);
reloadMenuData(result.data.us.sysUser, bidCode);
$('#nav-left button').removeAttr('style')
} else if (result.code === 500) {
layer.msg(result.msg, { icon: 2 }, function () {
window.location.href = login_sc_index;
});
} else if (result.code === 401) {
layer.msg(result.msg, { icon: 2 }, function () {
loginout(1);
});
}
}, function (xhr) {
error(xhr)
});
} else {
// 由施工大屏登录
reloadMenuData(JSON.parse(us), bidCode);
}
// 标段工程下拉选监听
form.on('select(bidPro)', function (data) {
$('#nav-right ul li').each(function (index, item) {
if ($(this).hasClass('checked')) {
const hrefValue = $(this).attr('hrefValue');
$('#indexIframe').attr('src', hrefValue);
}
})
});
});
/* 页面数据加载 */
function reloadMenuData(us, bidCode) {
let menus = us.menus;
let bidCodeList = us.bidProVoList;
setBandingPro(bidCodeList, bidCode);
setMenusData(menus);
if ($('#nav-right ul li').length > 0) {
let hrefValue = $('#nav-right ul li').eq(0).attr('hrefValue');
$('#indexIframe').attr('src', hrefValue);
}
$('#nav-right ul li').on('click', function () {
$('#nav-right ul li').each(function (index, item) {
if ($(this).hasClass('checked')) {
$(this).removeClass('checked').addClass('nocheck');
}
})
$(this).removeClass('nocheck').addClass('checked');
const hrefValue = $(this).attr('hrefValue');
$('#indexIframe').attr('src', hrefValue);
})
}
/* 初始化菜单 */
function setMenusData(menus) {
let html = '';
if (menus && menus.length > 0) {
$.each(menus[0].childer, function (index, item) {
if (index === 0) {
html += '<li class="layout checked" hrefValue="' + item.url + '"><p>' + item.menuName + '</p></li>'
} else {
html += '<li class="layout nocheck" hrefValue="' + item.url + '"><p>' + item.menuName + '</p></li>'
}
})
}
$('#nav-right ul').empty().append(html);
}
/* 初始化用户绑定标段工程 */
function setBandingPro(bidCodeList) {
let html = '';
if (bidCodeList && bidCodeList.length > 0) {
$.each(bidCodeList, function (index, item) {
if (bidCode && bidCode === item.bidCode) {
html += '<option value="' + item.bidCode + '" selected>' + item.proName + '</option>'
} else {
html += '<option value="' + item.bidCode + '">' + item.proName + '</option>'
}
})
}
$('#bidPro').empty().append(html);
layui.form.render();
}
/* 获取地址栏后的参数 */
const GetQueryString = (name) => {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
let r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURIComponent(r[2]);
return null;
};
/* 返回省侧大屏 */
$('#nav-left button').on('click', function () {
window.location.href = login_sc_index;
})