2018-06-03 22:26:41 +08:00

554 lines
19 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var menuUtil=function(swidth,strJsonMenu,strJsonParam,webPath){
this.leftTip=$("#main_menu_left");
this.rightTip=$("#main_menu_right");
this.leftTipShow=false; //是否显示左边的菜单条
this.rightTipShow=false; //是否显示左边的菜单条
this.menuBody=$("#main_menu_body");//菜单的对象
this.menuItemBody=$("#main_top_menu_info");
this.logoWidth=180;
this.sysWidth=140;
this.titleHight=60;//当前一级菜单的高度
this.titleWidth=90;//当前一级菜单的宽度
this.secondeWidth=140;//二级菜单的宽度
this.menuData=[];//菜单数据
this.menuWidth=swidth;//当前的宽带
this.menuLength=0;//当前一级菜单的长度
this.menuShowSartIndex=0;//当前显示一级菜单的开始位置
this.menuMayShowNumber;//当前显示一级菜单的结束位置
this.menuItem=[];//当前一级菜单对象
this.mentuJson=null;//当前菜单的JSON
this.curMayShowNumber=0;//当前可显示的条数
this.curSelectIndex=-1;//当前选中的位置
this.curSelectItem=null;
this.webPath=webPath;
// this.initMenu();
this.addHomePageClick();
this.mentuJson=JSON.parse(strJsonMenu);
this.menuLength=this.mentuJson.length;
this.urlparm=JSON.parse(strJsonParam);
this.initMenuItem();
this.initMenuItemCheckFunciton();
this.initMenuShowTip();
this.initMenuShowTipCheckFunction();
this.initWindowResize();
// this.resizeFirstPageBody();
this.loadUserInfo();
};
menuUtil.prototype.addHomePageClick=function(){
var tempMenuUtil=this;
//增加返回首页
$("#main_logo").click(function(){
AsControl.OpenView("/Tenwa/HomePage/DefaultHome/HomePage.jsp","","right");
})
//增显示用户信息
$("#main_sys_exitout").click(function(){
if(!confirm(getMessageText("AWEW1014"))) return; // 你确实要退出吗?
AsControl.OpenComp("/AppMain/SignOut.jsp","","_top");
})
$("#main_top").click(function(){
tempMenuUtil.hideSelectShowMenuItem();
});
$("#main_menu").click(function(event){
event.stopPropagation();
});
}
menuUtil.prototype.initMenu=function(){
//加载菜单的数据
var strMenuJson=$.ajax({
type:"GET",
url:"../data/mainmenu.txt",
dataType:"txt",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
async: false}).responseText;
if(strMenuJson==""){
this.menuLength=0;
}else{
this.mentuJson=JSON.parse(strMenuJson);
this.menuLength=this.mentuJson.length;
}
}
menuUtil.prototype.initMenuItem=function(){
var curMenuWidth=this.loadMenuWidth();
this.menuMayShowNumber=parseInt(curMenuWidth/ this.titleWidth);
if(this.menuMayShowNumber<this.menuLength){
this.menuMayShowNumber=parseInt((curMenuWidth-50)/ this.titleWidth);
}
this.menuBody.empty();
for(var i=0;i<this.mentuJson.length;i++){
var showType=""
if(i>=this.menuMayShowNumber){showType='style="display:none"';}
var tempItem=$('<li '+showType+' cindex="'+i+'" menuid="'+this.mentuJson[i].id+'" ><img src="./Tenwa/HomePage/Skip/Default/image/'+this.mentuJson[i].menuicon+'"></img><br><span>'+this.mentuJson[i].menuname+'</span></li>')
this.menuItem.push(tempItem)
this.menuBody.append(tempItem);
}
}
menuUtil.prototype.loadMenuWidth=function(){
var curMenuWidth=this.menuWidth-this.logoWidth- this.sysWidth;
return curMenuWidth;
}
menuUtil.prototype.initMenuItemCheckFunciton=function(){
var tempMenuUtil=this;
$('#main_menu li').click(function (event) {
tempMenuUtil.setMenuItemSeleced($(this));
var curSelect=$(this);
tempMenuUtil.curSelectIndex=curSelect.attr("cindex");
var menuid=curSelect.attr("menuid");
var url="";
if(tempMenuUtil.urlparm[curSelect.attr("menuid")]){
url=tempMenuUtil.urlparm[curSelect.attr("menuid")].url||"";
}
if(url.length<2){
var subSize=tempMenuUtil.loadSubItems();
tempMenuUtil.showMenuChildItem(subSize);
}else{
tempMenuUtil.hideSelectShowMenuItem();
tempMenuUtil.openMenu(curSelect);
}
});
};
/**
* 显示修改二级菜单位置
* @param subSize
*/
menuUtil.prototype.showMenuChildItem=function(subSize){
if(subSize>0){
var curWindowWidth=$(window).width();
var centerPoint=this.logoWidth+(this.curSelectIndex-this.menuShowSartIndex)* this.titleWidth+(this.titleWidth/2);
if(this.leftTip.css("display")=="block"){
centerPoint=centerPoint+25;
}
if((centerPoint-(this.titleWidth/2)+this.menuItemBody.width())<curWindowWidth){
this.menuItemBody.css("left",centerPoint-(this.titleWidth/2)+"px");
}else{
if(centerPoint+(this.menuItemBody.width()/2)<curWindowWidth){
if(centerPoint-(this.menuItemBody.width()/2)<0){
this.menuItemBody.css("left","0px");
}else{
this.menuItemBody.css("left",centerPoint-(this.menuItemBody.width()/2)+"px");
}
}else{
if((centerPoint+(this.titleWidth/2))-this.menuItemBody.width()>0){
this.menuItemBody.css("left",(centerPoint+(this.titleWidth/2))-this.menuItemBody.width()+"px");
}else{
this.menuItemBody.css("left",curWindowWidth-this.menuItemBody.width()+"px");
}
}
}
this.menuItemBody.show();
if($("#main_menu_back")){
$("#main_menu_back").remove();
}
var menubackDiv = $("<div id='main_menu_back' style='width:100%;height:100%;z-index:99;position:absolute;top:0;margin-top:80px;opacity:0.4'></div>");
var curMenu=this;
$(document.body).append(menubackDiv);
menubackDiv.click(function(){
curMenu.menuItemBody.hide();
$("#main_menu li[class='main_menuf']").removeClass("main_menuf");
menubackDiv.remove();
});
}else{
this.menuItemBody.hide();
$("#main_menu_back").remove();
}
}
/**
* 显示一级菜单上面的左或右边的按钮
*/
menuUtil.prototype.initMenuShowTip=function(){
if(this.menuMayShowNumber==0){
this.leftTipShow=false;
this.rightTipShow=false;
}
if(this.menuMayShowNumber>=this.menuLength){
this.leftTipShow=false;
this.rightTipShow=false;
}else{
if((this.menuShowSartIndex+this.menuMayShowNumber)==this.menuLength){
this.leftTipShow=true;
this.rightTipShow=false;
}else{
if(this.menuShowSartIndex==0){
this.leftTipShow=false;
this.rightTipShow=true;
}else{
this.leftTipShow=true;
this.rightTipShow=true;
if((this.menuShowSartIndex+this.menuMayShowNumber)==this.menuLength){
this.leftTipShow=true;
this.rightTipShow=false;
}else{
this.leftTipShow=true;
this.rightTipShow=true;
}
}
}
}
if(this.leftTipShow){this.leftTip.show();}else{this.leftTip.hide();}
if(this.rightTipShow){ this.rightTip.show()}else{this.rightTip.hide();}
if(this.leftTipShow){
this.menuBody.css("margin-left",25);
this.leftTip.show();
if(this.rightTipShow){ this.rightTip.css("margin-left", this.titleWidth*this.menuMayShowNumber+25); }
} else{
this.leftTip.hide()
this.menuBody.css("margin-left",0);
if(this.rightTipShow){
this.rightTip.css("margin-left", this.titleWidth*this.menuMayShowNumber);
}
}
}
menuUtil.prototype.setMenuItemSeleced=function(item){
$("#main_menu li[class='main_menuf']").removeClass("main_menuf");
item.addClass("main_menuf");
this.curSelectItem=item;
}
menuUtil.prototype.initMenuShowTipCheckFunction=function(){
var tempMenuUtil=this;
this.leftTip.mousedown(function(){
$(this).removeClass("main_menu_left"); $(this).addClass("main_menu_left_selected");
});
this.leftTip.mouseup(function(){
$(this).removeClass("main_menu_left_selected"); $(this).addClass("main_menu_left");
});
this.rightTip.mousedown(function(){
$(this).removeClass("main_menu_right"); $(this).addClass("main_menu_right_selected");
});
this.rightTip.mouseup(function(){
$(this).removeClass("main_menu_right_selected"); $(this).addClass("main_menu_right");
});
this.leftTip.click(function (){
tempMenuUtil.moveMenuItemLeft();
});
this.rightTip.click(function(){
tempMenuUtil.moveMenuItemRight();
});
}
menuUtil.prototype.moveMenuItemLeft=function(){
if((this.menuShowSartIndex+this.menuMayShowNumber-1)<this.menuLength){
this.menuItem[this.menuShowSartIndex+this.menuMayShowNumber-1].hide();
}
this.menuShowSartIndex-=1;
if(this.menuShowSartIndex>=0){this.menuItem[this.menuShowSartIndex].show()};
this.hideSelectShowMenuItem();
this.initMenuShowTip();
}
menuUtil.prototype.moveMenuItemRight=function(){
if(this.menuShowSartIndex>=0){this.menuItem[this.menuShowSartIndex].hide();}
this.menuShowSartIndex+=1;
if((this.menuShowSartIndex+this.menuMayShowNumber-1)<this.menuLength){
this.menuItem[this.menuShowSartIndex+this.menuMayShowNumber-1].show();
}
this.hideSelectShowMenuItem();
this.initMenuShowTip();
}
menuUtil.prototype.initWindowResize=function(){
var tempMenuUtil=this;
$(window).resize(function() {
tempMenuUtil.resizeMenu($(window).width());
});
}
menuUtil.prototype.resizeMenu=function(cwidth){
this.menuWidth=cwidth;
this.menuShowSartIndex=0;
this.menuItem=[];
this.initMenuItem();
this.initMenuItemCheckFunciton();
this.initMenuShowTip();
this.hideSelectShowMenuItem();
}
//隐藏显示的二级菜单
menuUtil.prototype.hideSelectShowMenuItem=function(){
this.menuItemBody.hide();
$("#main_menu_back").remove();
$("#main_menu li[class='main_menuf']").removeClass("main_menuf");
}
menuUtil.prototype.showTitle=function(title){
console.info(title+":"+title.length);
if(title.length<9){
return ""
}else{
return title;
}
}
//加载二级菜单
menuUtil.prototype.loadSubItems=function(){
var Items=this.mentuJson[this.curSelectIndex].submenu||[];
var cindex=0;
var parentDiv=$("<div></div>");
var rowHightIndex={};
var leveShowNumber=0;
if(Items.length>0){
this.menuItemBody.empty();
var tempSubLi=[];
for(var i=0;i<Items.length;i++){
var oneItems=Items[i];
var nodetype=Items[i].nodetype||"leaf";
if(i==(Items.length-1)&&nodetype=="leaf"){
cindex+=1;
tempSubLi.push("<li class='main_menu_leaf_li' menuid='"+oneItems.id+"' title='"+this.showTitle(oneItems.menuname)+"'><img src='./Tenwa/HomePage/Skip/Default/image/nav_sanji.png'></img><span class='main_menu_leaf_span'>"+oneItems.menuname+"</span></li>");
var tempUl=$("<ul></ul>");
tempUl.append(tempSubLi);
var menuDiv=this.getMenuItemDiv(cindex);
menuDiv.append(tempUl)
parentDiv.append(menuDiv);
rowHightIndex[cindex]=tempSubLi.length;
tempSubLi=[];
}else{
if(nodetype=="root"){
if(tempSubLi.length>0){
cindex+=1;
var tempUl=$("<ul></ul>");
tempUl.append(tempSubLi);
var menuDiv=this.getMenuItemDiv(cindex);
menuDiv.append(tempUl)
parentDiv.append(menuDiv);
rowHightIndex[cindex]=tempSubLi.length;
tempSubLi=[];
}
cindex+=1;
var tempUl=$("<ul></ul>");
tempUl.append("<li class='main_menu_root_li' title='"+this.showTitle(oneItems.menuname)+"'><img src='./Tenwa/HomePage/Skip/Default/image/nav_erji.png'><span class='main_menu_root_span'>"+oneItems.menuname+"</span></li>");
var subItems=oneItems.submenu||[];
for(var j=0;j<subItems.length;j++){
tempUl.append("<li class='main_menu_leaf_li' menuid='"+subItems[j].id+"' title='"+this.showTitle(subItems[j].menuname)+"'><img src='./Tenwa/HomePage/Skip/Default/image/nav_sanji.png'><span class='main_menu_leaf_span'>"+subItems[j].menuname+"</span></li>");
}
var menuDiv=this.getMenuItemDiv(cindex);
rowHightIndex[cindex]=subItems.length+1;
menuDiv.append(tempUl)
parentDiv.append(menuDiv);
}else{
tempSubLi.push("<li class='main_menu_leaf_li' menuid='"+oneItems.id+"' title='"+this.showTitle(oneItems.menuname)+"'><img src='./Tenwa/HomePage/Skip/Default/image/nav_sanji.png'><span class='main_menu_leaf_span'>"+oneItems.menuname+"</span></li>");
}
}
}
//设置显示的宽度
var d=5;
if(cindex>=5){d=5;}else{d=cindex}
var curWindowWidth=$(window).width();
if((curWindowWidth)<(d*this.secondeWidth+(d-1))){
d=parseInt((curWindowWidth-40)/this.secondeWidth);
leveShowNumber=d;
}else{
leveShowNumber=d;
}
parentDiv.width(leveShowNumber*this.secondeWidth+(leveShowNumber-1)+"px");
this.menuItemBody.append(parentDiv);
this.menuItemBody.width(leveShowNumber* this.secondeWidth+(leveShowNumber)+"px");
}
//计算每一层的高度
var maxIndex=0;
var maxHeightIndex=0;
for(tindex in rowHightIndex){
if(rowHightIndex[tindex]>maxIndex){
maxIndex=rowHightIndex[tindex];
}
if(tindex%leveShowNumber==0 ||tindex==cindex ){
var before=0;
if(tindex<=leveShowNumber){
before=1;
}else{
if(tindex%leveShowNumber==0){before=tindex-leveShowNumber+1;}
else{
if(tindex==cindex){before=tindex-tindex%leveShowNumber+1;}
}
}
for(var j=before ;j<=tindex;j++){rowHightIndex[j]=maxIndex;}
maxHeightIndex=maxHeightIndex+maxIndex;
maxIndex=0;
}
}
this.menuItemBody.find("div").each(function(index,elemnt){
if(index>0){
if((index-1)%leveShowNumber==0){
$(this).removeClass("main_menuitem_boder");
}
$(this).height(rowHightIndex[index]*35+5);
}else{
$(this).height(maxHeightIndex*35)+10;
}
});
var curWindowHeight=$(window).height()-this.titleHight;
if(curWindowHeight<maxHeightIndex*35){
this.menuItemBody.width(( this.menuItemBody.width()+12)+"px");
this.menuItemBody.height((curWindowHeight)+"px");
}else{
this.menuItemBody.height((maxHeightIndex*35+10)+"px");
}
var curMainMenu=this;
this.menuItemBody.find("li[class='main_menu_leaf_li']").click(function(){
curMainMenu.menuItemBody.hide();
$("#main_menu_back").remove();
$("#main_menu li[class='main_menuf']").removeClass("main_menuf");
curMainMenu.openMenu($(this));
});
return cindex;
}
//显示二级菜单时创建显示分组的二级分类
menuUtil.prototype.getMenuItemDiv=function(cindex){
if(cindex>1){
return $("<div class='main_menuitem_boder'></div>");
}else{
return $("<div></div>");
}
}
menuUtil.prototype.openMenu=function(curselect){
var url=this.urlparm[curselect.attr("menuid")].url;
var param=this.urlparm[curselect.attr("menuid")].param;
var tabid=$(window.frames["right"].document).find("#tabs_button_T01");
var title=curselect.text();
var sParas = param+"&_SYSTEM_MENU_FALG=0";
if(tabid.length==0){
AsControl.OpenView("/AppMain/MenuTabContainer.jsp", "isAddMain=true&Title="+title+"&ToDestroyAllComponent=N&Url="+url+"&Paras="+param, "right");
}else{
var tWin=window.frames["right"];
if(typeof tWin.addTabItem == "function"){
var text=title;
var sURL=url;
var sPara=sParas;
tWin.addTabItem(text, sURL,sPara);
}
}
}
menuUtil.prototype.loadUserInfo=function(){
var userHtmlDiv=$("<div id='main_user_info' class='main_user_list_info' style='display:none'></div>");
var userHtmlTable=$("<table height='100px'></table>");
var userInfo=getUserHTMLJson();
var userData=getUserInfo();
for(var i=0;i<userInfo.length;i++){
var temp="<tr ><td class='main_user_table_title'>"+userInfo[i].title+"<i class='"+userInfo[i].image+"'/>:</td>";
temp+="<td class='main_user_table_content'><input id='"+userInfo[i].id+"' ";
if(i<2){ temp+=" readonly " ;}
temp+=" value='"+userData[userInfo[i].id]+"'/></td></tr>";
userHtmlTable.append($(temp));
}
userHtmlTable.append($("<tr><td colspan='2' style='text-align:center'><button type='button' onclick='AsButton.run(this, function(){saveUserInfo();}, event);return false;' >保存</button>&nbsp;&nbsp; <button type='button' onclick='AsButton.run(this, function(){ModifyPass();}, event);return false;' >修改密码</button></td></tr>"));
userHtmlTable.append($("<tr><td class='main_user_table_title'>语言:</td><td ><a href='javascript:void(0);' onclick='changeLang(\"en\");return false;'>英文</a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='changeLang(\"zh\");return false;'>中文</a></td></tr>"));
userHtmlDiv.append(userHtmlTable);
$("#main_sys_user").append(userHtmlDiv);
var curMenu=this
$("#main_sys_user").mouseover(function(){
//关闭显示的二级菜单
curMenu.menuItemBody.hide();
$("#main_menu li[class='main_menuf']").removeClass("main_menuf");
$("#main_user_info").show();
});
$("#main_sys_user").mouseout(function(){
$("#main_user_info").hide();
});
}
function saveUserInfo(){
var email = $("#email").val();
var mobile = $("#mobile").val();
var comptel = $("#comptel").val();
if(email && !/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/.test(email)){
alert(getMessageText("AWES2051")); // Email填写错误
restoreUserInfo();
return;
}
if(mobile && !/^[1][3|5][0-9]{9}$/.test(mobile)){
alert(getMessageText("AWES2052")); // 手机号填写错误!
restoreUserInfo();
return;
}
if(comptel && !/^([0-9]{1,3}-)?([0-9]{2,4}-)?[0-9]{7,11}(-[0-9]{1,5})?$/.test(comptel)){
alert(getMessageText("AWES2053")); // 办公电话填写错误!
restoreUserInfo();
return;
}
var sReturn = AsControl.RunJsp("/AppConfig/ControlCenter/ChangeContactInfo.jsp", "Email="+email+"&Mobile="+mobile+"&Comptel="+comptel);
if(sReturn){
alert(sReturn);
}else{
alert("操作成功!");
}
}
function restoreUserInfo(){
var result =AsControl.RunJsp("/AppConfig/ControlCenter/restoreUserInfo.jsp","");
var $result = $(result);
var param = $result.filter("span").html();
var o = param.split(",");
$("#email").val(o[0]);
$("#mobile").val(o[2]);
$("#comptel").val(o[1]);
}
var mainBodyResize=function(){
this.resizeFirstPageBody();
this.initWindowResize();
}
mainBodyResize.prototype.initWindowResize=function(){
var tempMenuUtil=this;
$(window).resize(function() {
tempMenuUtil.resizeFirstPageBody();
});
}
mainBodyResize.prototype.resizeFirstPageBody=function(){
var curHight=$(document.body)[0].clientHeight;
var curWidth=$(window).width();
var worktiwidth=(curWidth)*3/5;
worktiwidth=worktiwidth.toFixed(2);
var worktipHight=(curHight)*1/2+5;
$("#main_worktip_title_body").width(worktiwidth+"px");
$("#main_worktip_title_body").height(worktipHight+"px");
//设置公告信息的宽度和高度
$("#main_noticetitle_body").width((worktiwidth-360)+"px");
//$("#main_calendartitle_body").width((worktiwidth-5-(worktiwidth-350))+"px");
var otherHight=(curHight-worktipHight-100);
$("#main_noticetitle_body").height((otherHight-20)+"px");
$("#main_calendartitle_body").height((otherHight)+"px");
//设置报表的高度
var reportLeft=parseFloat(worktiwidth)+30;
//$("#main_body_right").css("margin-left",reportLeft+"px");
var reportWidth=(curWidth-50-worktiwidth)+"px";
$("#main_body_right").width(reportWidth);
var reportHeight=(worktipHight-4)/2;
$("#report01").height(reportHeight+"px");
// $("#report01").width(reportWidth);
$("#report02").height(reportHeight+"px");
$("#report02").css("margin-top","10px");
// $("#report02").width(reportWidth);
$("#report03").height(otherHight-20+"px");
$("#report03").css("margin-top","10px");
// $("#report03").width(reportWidth);
// $("#main_body").css("overflow","visible");
}
function changeLang(sLang){
alert(sLang);
AsControl.RunJsp("/Frame/page/sys/tools/ChangeLang.jsp", "Lang="+sLang);
self.location.reload();
}