/**
* 全(quán)局公用js;每个页(yè)面都(dōu)必须引用!
*
* esung Team 2012
*/
//日志记录
var log = {
disable : false, //是否开启(qǐ)日志(zhì)
logInfos : [],
getTime : function(){
return (new Date()).getTime();
},
info : function(msg, time) {
if(this.disable) return;
//if(this.logInfos.length > 100) this.logInfos = [];
if(time != undefined) msg += " elapsed : " + time + "ms";
this.logInfos.push(time > 100 ? "" + msg + "" : msg);
},
showInfo : function(){
var dialog = $("#_Dialog_Log");
if(!dialog.length){
dialog = $("
").appendTo("body");
}
dialog.dialog({
content : this.logInfos.join("
")
}).dialog("open");
}
};$(function(){
//只读(dú)控件的处理(lǐ)
$("[readonly='true'],[readonly='readonly']").readOnly();
//绑定(dìng)事件
$(window).unbind("keydown.global").bind("keydown.global",function(event){
var keyCode = event.keyCode;
var doPrevent = false;//是否阻制默认行(háng)为
//退格键
if(keyCode == 8){
var d = event.srcElement || event.target;
if (d.tagName.toUpperCase() == 'INPUT' || d.tagName.toUpperCase() == 'TEXTAREA') {
doPrevent = d.readOnly || d.disabled;
}
else
doPrevent = true;
///CTRL+ALT+X调用日志控(kòng)制台
} else if(keyCode == 88 && event.altKey && event.ctrlKey){
log.showInfo();
}
if (doPrevent) event.preventDefault();
});
});// --------【prototype】扩展start-----------------------------------
String.prototype.getByteLength = function() {
var _WJ_ = this.match(/[^\x00-\xff]/ig);
return this.length + (_WJ_ == null ? 0 : _WJ_.length);
};/**
* 数字(zì)格式化为金额,默认保留两位数
* 如:1234.5678 -> 1,234.57
* @param num
* @param n
* @returns
*/
function formatNum(num,n){
n = n || 2;
if(num==null){
num = "";
} else {
num = num.toFixed(n) + "";
}
var intNum = num, decNum = "";
var pointIndex = num.indexOf(".");
if (pointIndex >= 0) {
intNum = num.substring(0, pointIndex);
decNum = num.substring(pointIndex + 1, num.length);
}
var p = /(\d+)(\d{3})/;
while (p.test(intNum)) {
intNum = intNum.replace(p, "$1,$2");
}
if (decNum) {
return intNum + "." + decNum;
} else {
return intNum;
}
}// --------【prototype】扩(kuò)展end-----------------------------------
var SkinUtil = {};SkinUtil.getSkin = function() {
var currSkin = SkinUtil.getCookie("appskin");
if (!currSkin) {
currSkin = "default";
}
var pathName = window.document.locations.pathname;
// 获取(qǔ)工程(chéng)项目跟路径/esung
//if (pathName.indexOf("main.jsp") >= 0) {
if (pathName.indexOf("loginMain.do") >= 0) { //alert(pathName)
document.write('');
}
document.write('');
};SkinUtil.getCookie = function(objName) {// 获取(qǔ)指定名称的cookie的值
var arrStr = document.cookie.split("; ");
for ( var i = 0; i < arrStr.length; i++) {
var temp = arrStr[i].split("=");
if (temp[0] == objName)
return unescape(temp[1]);
}
};SkinUtil.addCookie = function(objName, objValue, objHours) {// 添加cookie
var str = objName + "=" + escape(objValue);
if (objHours > 0) {// 为0时不设(shè)定过期时间,浏览器关闭时cookie自动(dòng)消失
var date = new Date();
var ms = objHours * 3600 * 1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
};
SkinUtil.getSkin();
var $document = $(document);$document.ajaxStart(function(event, request, settings) {
//闪屏效果不佳,先(xiān)去除
/**
if ($("div.dg-mask").length > 0) {
$("div.dg-mask").css({
display : "block"
});
// $("div.dg-mask-msg").css({display:"block"});
} else {
$("").css({
"z-index" : "9999",
"background-color" : "#FFF",
"filter" : "alpha(opacity=50)",
"-moz-opacity" : "0.5",
"-khtml-opacity" : "0.5",
"display" : "block",
"position" : "absolute",
"width" : "100%",
"height" : $(window).height()
}).appendTo("body");
// $("").html("正在处理,请稍候(hòu)。。。").appendTo("body").css({"display":"block","left":($(document.body).outerWidth(true) - 190) / 2,"top":($(window).height() - 45) / 2});
}**/
});
$document.ajaxComplete(function(event, request, settings) {
/**$("div.dg-mask").css({
display : "none"
});**/ var jsonResult=jsonevals(request.responseText);
if(jsonResult){
if(jsonResult.msg!=undefined&&jsonResult.msg.length>0){
$.messager.alert("提示!",jsonResult.msg,"info");
}
if(jsonResult.redirecturl!=undefined&&jsonResult.redirecturl.length>0){
window.locations.href = _ContextPath+jsonResult.redirecturl;
}
} // $("div.dg-mask-msg").css({display:"none"});
});
// --------【皮(pí)肤】封装end-----------------------------------// --------【菜(cài)单】封(fēng)装start---------------------------------
/**
* 初始化系统(tǒng)菜单方(fāng)法(fǎ),扩(kuò)展的jquery方法
* @param options
* @returns options.fn
* @author zhangsm {@link http://www.esung.com 翼星有(yǒu)限公司}
*/
(function($) {
$.extend($.fn, {
initSysMenu : function(options) {
this.each(function() {
var $this = $(this);
var url = $this.attr('url');
var method = $this.attr('method');
$.ajax({
type : 'GET',
url : url,
cache : false,
success : function(response) {
var json = jsonevals(response);
$.each(json, function(key, value) {
var menuId = "menu_" + value.id; //alert(menuId);
var menuPanelId = "childPanel_" + value.id;
if(value.children != null){
$this.append("");
var $children = $("");
spanChild(value.children, $children);
$children.appendTo($this);
$('#' + menuId).menubutton({
menu : '#' + menuPanelId
});
}else{
$this.append("" + value.text + "");
}
//$this.append("");
/*if (value.children != null) {
var $children = $("");
spanChild(value.children, $children);
$children.appendTo($this);
$('#' + menuId).menubutton({
menu : '#' + menuPanelId
});
}*/
});
}
});
});
},
//初始化用户角色信(xìn)息
initUserRoleList : function(options) {
this.each(function() {
var $this = $(this);
var url = $this.attr('url');
//alert(url);
var method = $this.attr('method');
$.ajax({
type : 'GET',
url : url,
cache : false,
success : function(response) {
var $mb1 = $("");
var $menuPanel = $("");
$menuPanel.appendTo($mb1);
$mb1.appendTo($this);
var json = jsonevals(response);
$.each(json, function(key, value) {
var text = value.ROLENAME;
var id = value.ROLEID;
var $node = $("" +text+ "
");
$node.appendTo($menuPanel);
});
$('#mb1').menubutton({
menu : '#menuPanelId'
});
}
});
});
},
// 这段作用是,如果控件为只(zhī)读的,那么颜色为(wéi)黄色,我是想可不可以自(zì)定义设置那(nà)个控(kòng)件只读为黄色,而不是一(yī)切(qiē)都为(wéi)黄色(sè)
readOnly : function(readonly){
var $this = $(this);
readonly = (typeof readonly != "undefined") ? readonly : true;
if(readonly){
//先注释掉 zsm 20160302
$this.addClass("text-readonly");
$this.css("cursor" , "pointer");
} else {
//先注释(shì)掉(diào) zsm 20160302
$this.removeClass("text-readonly");
$this.css("cursor" , "auto");
}
$this.attr("readonly",readonly);
}
});
})(jQuery);function spanChild(childs, parent) {
$.each(childs, function(key, value) {
if (value.children != null) {
var div = $("");
div.append("" + value.text + "");
var $node = $("");
spanChild(value.children, $node);
$node.appendTo(div);
div.appendTo(parent);
} else {
var $node = $("" + value.text + "
");
$node.appendTo(parent);
}
});
}/**
* 将json字符串(chuàn)转出json对象(xiàng)
*
* @param data
* @returns
*/
function jsonevals(data) {
try {
return evals('(' + data + ')');
} catch (e) {
return {};
}
}
function getContentpath() {
var pathName = window.document.locations.pathname;
return pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
}// --------【菜单】封装end-----------------------------------
// ---------【右(yòu)边grid自(zì)适应】--------begin-----------------
$.parser.onComplete = function() {
if (undefined != $('body').attr('class')) {
var $panel = $('body').layout('panel', 'west');
if ($panel) {
$panel.panel({
onCollapse : function() {
var rightPanel = $('body').layout('panel', 'center');
rightPanel.panel('collapse');
rightPanel.panel('expand');
},
onExpand : function() {
var rightPanel = $('body').layout('panel', 'center');
rightPanel.panel('collapse');
rightPanel.panel('expand');
}
});
}
}
};
// ---------【右边grid等自适(shì)应】--------end-------------------/*******************************代码(mǎ)汉化函数(shù)(开始)*********************************/
var _SYS_GROBAL = $(this);
//获(huò)取数据列表
function _loadData(options){
var keyName = options.keyName;
var arrData = _SYS_GROBAL.data(keyName);
if(!arrData){
$.ajax({
type : 'post',
url : options.url,
cache : false,
async : false,
data : options.data,
dataType : 'json',
success : function(data){
_SYS_GROBAL.data(keyName,data);
arrData = data;
}
});
}
return arrData;
}
/**
* 汉化函(hán)数,使用可参考_formatCodeData(codeTypeId,value)
* 参(cān)数(shù)说明
* options = {
* keyName : "CODE_1027" 必录项,缓存(cún)在页(yè)面中的全局变量(liàng),必须唯(wéi)一,建议采用PKUtil.js文件中(zhōng)的(de)new UUID().id;
* url : "/sys/base.do?getCodeInfo" 必录项,远程访问URL
* idField : "value" 必录(lù)项(xiàng),字段的值属性(xìng)名
* textField : "content" 必(bì)录项,字段的文本属性名
* value : "0001" 必录项,字(zì)段的值
* data : {codeTypeId : "1027" } 可(kě)选项,远(yuǎn)程访问的参(cān)数
* }
* @returns
*/
function _formatData(options){
var value = options.value;
var idField = options.idField;
var textField = options.textField;
var data = _loadData(options);
if(data && data.length){
for(var i=0,len=data.length; i> select >> onChange事(shì)件(jiàn)
url : _ContextPath+"/sys/base.do?method=getCodeInfo&codeTypeId="+codeTypeId,
valueField : 'codevalsue',
textField : 'codeName',
onLoadSuccess: function () { //数据加载(zǎi)完毕事件
var data = $(comboboxId).combobox('getData');
if (data.length > 0) {
$(this).combobox('select', data[0].codevalsue);
}
}
});
}/**
* 把输入的字符转为(wéi)大写
* @param obj
*/
function toJsUpperCase(obj)
{
try {
var s = obj.value;
if (trim(s) == "") return;
obj.value = s.toUpperCase();
} catch(e) {
}
}/**
* 去掉字符左边的空格
* @param str
* @returns
*/
function ltrim(str)
{
if (str==null) return null;
var s="";
for (var i=0;i=0;i--)
{
if (str.charAt(i)!=" ")
{
s=str.substring(0,i+1);
break;
}
}
return s;
}/**
* 去掉字符左右边的空格
* @param str
* @returns
*/
function trim(str)
{
return(ltrim(rtrim(str)));
}//---------【扩展函数(shù)】--------end----------
function convert_xml_to_string(xmlObject) {
if (window.ActiveXObject) { // for IE
return xmlObject.xml;
} else {
return (new XMLSerializer()).serializeToString(xmlObject);
}
}//加载图形
function loadChart(controllerURL, swfUrl, renderTo,width,height) {
var dataXML; $.get(controllerURL, function(data) {
if (typeof (data) == "XMLDocument") {
dataXML = convert_xml_to_string(data);
} else {
dataXML = data;
}
var chart = new FusionCharts(swfURL, "ChartId", width, height, "0",
"0");
chart.addParam("wmode","Opaque");
chart.setDataXML(dataXML);
chart.render(renderTo);
});
}
/************************************
* 上传文件(jiàn)列表函数(shù)
* refId:对象ID 必输(shū)项
* module : 模块名称 必输项
* refType:对(duì)象类型(xíng) ,不超过13字符
* 例子:uploadFile({
* refId : xxx
* module : MKT
* refType : MKTCASE
* width : 800
* height : 480
* maximized: true
* exts : "xls,exe" //以(yǐ)逗号隔开
* })
* *************************************************/
function uploadFile(options){
var refId = options.refId;
var refType = options.refType ? options.refType : "DEFAUTTYPE";
var module = options.module ? options.module : "";
var exts = options.exts ? options.exts : "";
var title = options.title ? options.title : "上传文件";
var width = options.width ? options.width : 800;
var height = options.height ? options.height : 400;
var maximized = options.maximized ? options.maximized : false;
var url = _ContextPath + "/jsp/pub/uploadfile/fileUploadList.jsp?refId="+refId+"&refType="+refType+"&module="+module+"&exts="+exts;
var dlgUpload = $("#_DialogUpload");
if(!dlgUpload.length){
var divStr = '';
divStr += '';
divStr += "
";
dlgUpload = $(divStr).appendTo('body');
}
_uploadFrame.locations = url;
dlgUpload.dialog({
title : title,
width : width,
height : height,
maximized : maximized
}).dialog("open");
}
//判断(duàn)文件(jiàn)是否符合(hé)格式
function validateExt(ext,exts){
if(exts == "") return true;
var arrExt = exts.split(",");
for(var i=0,len=arrExt.length; i" +
" ");
//" ");
$('#_iframe').css({
position : "absolute",
"z-index" : 5,
left : $(document).width()/2-100,
top : $(document).height()/2-25,
zoom : 1,
width : 200,
height : 50
});
if(msg==null || msg=="") msg = "邮件正在发送中......";//数据(jù)加载中,请(qǐng)稍候......
$('#_iframe').append(
"" +
"" +
" | "+
" " +msg + " | " +
"
" +
"
"
);
}//----必输项后(hòu)面加星号,combox,显示不正(zhèng)常,所以除(chú)外---begin---
function requiredCss() {
$(document.body).keydown(
function(e) {
var doPrevent = false;
var key = (e.keyCode) || (e.which) || (e.charCode);
if (key == 8) {
var d = e.srcElement || e.target;
if (d.tagName.toUpperCase() == 'INPUT'
|| d.tagName.toUpperCase() == 'TEXTAREA') {
doPrevent = d.readOnly || d.disabled;
}
if (doPrevent) {
e.preventDefault();
}
}
switch(e.keyCode){
case 90 : {//CTRL+ALT+Z调用日志控制台
if(e.altKey && e.ctrlKey){
log.showInfo();
}
}
}
}
); var inputs = $('input[required="true"]');
inputs.each(function() {
var clsName = $(this).attr("class");
if (!clsName || (clsName.indexOf("easyui-combobox") == -1 &&
clsName.indexOf("easyui-combogrid") == -1 &&
clsName.indexOf("easyui-searchbox") == -1 &&
clsName.indexOf("easyui-datetimebox") == -1 &&
clsName.indexOf("easyui-datebox") == -1))
$(this).after(" *");
});
var readonlyIpt = $('[readonly="true"],[readonly="readonly"],[editable="false"]');
readonlyIpt.css('background-color', '#FDFCDE');
}
// ----必输项后面加星号---end---//获得(dé)时间,形(xíng)如:2012-12-03
function getCurrentDate() {
var result;
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; // January is 0! result = today.getFullYear() + "-";
if (mm < 10) {
result += '0' + mm;
} else {
result += mm;
} result += "-";
if (dd < 10) {
result += '0' + dd;
} else {
result += dd;
}
return result;
}
// 获得(dé)时(shí)间,形如:2012-08-10 14:06:59
function getCurrentDateTime() {
var result;
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; // January is 0!
var hh = today.getHours();
var ii = today.getMinutes();
var ss = today.getSeconds();
result = today.getFullYear() + "-";
if (mm < 10) {
result += '0' + mm;
} else {
result += mm;
} result += "-";
if (dd < 10) {
result += '0' + dd;
} else {
result += dd;
}
result += " "; if (hh < 10) {
result += '0' + hh;
} else {
result += hh;
} result += ":";
if (ii < 10) {
result += '0' + ii;
} else {
result += ii;
} result += ":";
if (ss < 10) {
result += '0' + ss;
} else {
result += ss;
}
return result;
}
/**
* 将YYYY-MM-DD或YYYY/MM/DD格(gé)式的(de)日期字符串转换成日期型,可(kě)用来对(duì)日期比(bǐ)较(jiào)大小
*
* @param str
*/
function convertStrToDate(str) {
var arr;
if (str.indexOf('-') > -1) {
arr = str.split('-');
} else if (str.indexOf('/') > -1) {
arr = str.split('/');
} else
return null;
return new Date(arr[0], arr[1], arr[2]);
}//拓(tuò)展js, 用join 代替(tì)+ 速(sù)度加(jiā)快(kuài)
function StringBuffer() {
this._strs = new Array();
}
StringBuffer.prototype.append = function(str) {
this._strs.push(str);
};
StringBuffer.prototype.toString = function() {
return this._strs.join("");
};$.extend($.fn.validatebox.defaults.rules, {
date: {
validator: function(value){
if (value.indexOf("-") > 0) {
var patrn = /^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$/;
return patrn.test(value);
}
},
message: '输入时间格式错误(2012-01-01)'
}
});
String.prototype.format = function() {
var vs = arguments;
return this.replace(/\{(\d+)\}/g, function() { return vs[parseInt(arguments[1])]; });
};
Date.prototype.dateformat = function(formatString) {
with (this) {
return (formatString||"{0}-{1}-{2} {3}:{4}:{5}").format(
getFullYear()
, ("0" + (getMonth()+1)).slice(-2)
, ("0" + getDate()).slice(-2)
, ("0" + getHours()).slice(-2)
, ("0" + getMinutes()).slice(-2)
, ("0" + getSeconds()).slice(-2)
);
}
};
function getWeek(theDay) {
var monday = new Date(theDay.getTime());
var sunday = new Date(theDay.getTime());
monday.setDate(monday.getDate()+1-monday.getDay());
sunday.setDate(sunday.getDate()+7-sunday.getDay());
return {monday:monday, sunday:sunday};
}
/**
* 人员部门下拉框
* @param target, url, isValue,target2
* @author zhangsm {@link http://www.esung.com 翼星有限公司}
*/
function initDepComboTree(target, url, isValue,target2) {
// 基础信息页(yè)面
$(target).combotree(
{
url : url,
panelWidth : 200,
onBeforeExpand : function(node) {
// 通过异(yì)步加载树节点, children保存子节点信(xìn)息
var children = $(target).combotree("tree").tree(
'getChildren', node.target);
// 如果children数量为0,异步加(jiā)载
if (children == 0) {
$(target).combotree("tree").tree("options").url = url
+ "&parentOrgId=" + node.id;
}// end if
},// end onBeforeExpand
onClick : function(node) {
if (!isValue) {
$(target).combotree('setValue', node.text);
}
if (target2){
$(target2).val(node.id);
}
}
});// end departmentName combotree
}