var Util = {
isEmpty : function (val)
{
return $.isArray(val) ? val.length == 0
: ($.isPlainObject(val) ? $.isEmptyObject(val)
: (typeof val == 'undefined' || val === null || val == ''));
},
reloadDataGrid : function (dgid)
{
$('#'+dgid).datagrid('reload');
},
reloadTreeGrid : function (dgid)
{
$('#'+dgid).treegrid('reload');
},
array2Object : function (arr) {
var obj = {};
for(var i = 0, len = arr.length; i < len; i++) {
obj[arr[i].name] = arr[i].value;
}
return obj;
},
formatString : function (/*format, Arg...*/)
{
var str = arguments[0];
if(typeof str !== 'string')
throw 'First argument is not a string object';
if($.isPlainObject(arguments[1])) {
var params = arguments[1];
for (var key in params) {
str = str.replace(new RegExp('%\\{' + key + '\\}%', "gm"), params[key]);
}
} else {
for (var key = 1, len = arguments.length; i < len; ++i) {
str = str.replace(new RegExp('\\{' + (i - 1) + '\\}', 'gm'), arguments[key]);
}
}
return str;
},
getReqParams : function (url)
{
var request = new Object();
url = unescape(url);
var idx = url.indexOf("?");
if(idx != -1)
{
var params = url.substr(idx+1); //获取url中"?"符后的字串
var strs = params.split("&");
for(var i = 0; i < strs.length; i ++)
{
request[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
return request;
},
imagescale : function (img, w, h) {
var ow = img.width,
oh = img.height;
if (ow >= oh) {
img.width = w * ow / oh;
img.height = h;
img.style.marginLeft = '-' + parseInt((img.width - w) / 2) + 'px';
} else {
img.width = w;
img.height = h * oh / ow;
img.style.marginTop = '-' + parseInt((img.height - h) / 2) + 'px';
}
return img;
},
getDeviceTypeIcon : function (type) {
var imgsrc = null;
if(type && type.toString().startsWith('Linux'))
imgsrc = "";
else if(type && type.toString().startsWith('Win32'))
imgsrc = "";
else if(type && type.toString().startsWith('Android'))
imgsrc = "";
else if(type && type.toString().startsWith('LUA'))
imgsrc = "";
else
imgsrc = "";
return imgsrc;
},
decodeStyleStr : function(styleStr){
if(!styleStr)
return null;
var styleArr = [];
var arr0 = styleStr.split(";");
for (var i = arr0.length - 1; i >= 0; i--) {
var arr1 = arr0[i].split(":");
if(arr1[0] && arr1[0].length>0)
styleArr[arr1[0]] = arr1.length>0?arr1[1]:'';
}
return styleArr;
},
encodeStyleArr : function(styleArr){
if(!styleArr)
return '';
var styleStr = '';
for(var name in styleArr){
styleStr += ';'+name+':'+styleArr[name];
}
return styleStr;
},
gcd2: function (a,b){//获取最大公约数
var temp;
while(b != 0){
temp = a % b;
a = b;
b = temp;
}
return a;
},
checkPhone:function(phone){
var phonePatt=/^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\d{8}$/;
if(phonePatt.test(phone)){
return true;
}else {
return false;
}
},
checkEmail:function(email){
var emailPatt=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if(emailPatt.test(email)){
return true;
}else {
return false;
}
},
xorData:function(data,key){
if(key == null || key.length <=0)
return data;
var klen = key.length;
var dlen = data.length;
var ndata = "";
var j = 0;
for (var i = 0; i < dlen; i++){
ndata += String.fromCharCode(data.charCodeAt(i) ^ key.charCodeAt(j));
j++;
if(j>=klen)
j = 0;
}
return ndata;
},
encodeParams:function (params)
{
if(typeof getCookie != 'function'){
console.log('getCookie===='+ typeof getCookie);
return params;
}
var key = getCookie('strkey');
if(params == null || key == null)
return params;
var data = {};
$.each(params,function(k,v){
if(v.name != undefined){
if(typeof v.value == 'string'){
data[v.name] = encodeURI(v.value);
}else{
data[v.name] = v.value;
}
}else{
if(typeof v == 'string'){
data[k] = encodeURI(v);
}else{
data[k] = v;
}
}
})
return {_p:window.btoa(Xxtea.xxtea_encrypt(JSON.stringify(data),key))};
},
MergeArray:function(arr1,arr2){
var _arr = new Array();
for(var i=0;i= ph / h) {
var mw = w * ph / h;
var mh = ph;
} else {
var mw = pw;
var mh = h * pw / w;
}
var ml = (pw - mw) / 2;
var mt = (ph - mh) / 2;
$(obj).css({
width: mw + 'px',
height: mh + 'px',
marginLeft: ml + 'px',
marginTop: mt + 'px'
});
},
parseParams:function(data){
try {
var tempArr = [];
for (var i in data) {
var key = encodeURIComponent(data[i]['name']);
var value = encodeURIComponent(data[i]['value']);
tempArr.push(key + '=' + value);
}
var urlParamsStr = tempArr.join('&');
return urlParamsStr;
} catch (err) {
return '';
}
},
showSplist:function(data,atreedaiv,size)
{
if(size == undefined)
size = 18;
if(data.orient == 'H'){
$.each(data.children, function(index, val) {
if(val.hasOwnProperty('atree') == true){
atreedaiv.append(Util.showSplist(val.atree,$(""),size));
}else {
atreedaiv.append($(""+
""+val.name+""+"
"));
}
});
}else if(data.orient == 'V'){
$.each(data.children, function(index, val) {
if(val.hasOwnProperty('atree') == true){
atreedaiv.append(Util.showSplist(val.atree,$(""),size));
}else {
atreedaiv.append($(""+
""+val.name+""+"
"));
}
});
}else{
return atreedaiv;
}
return atreedaiv;
},
domScale: function(dom,w, h) {
var bw = dom.parent().width();
var bh = dom.parent().height();
dom.css('position','absolute');
if (w >= h) {
if (w > bw) {
dom.width(w + "px");
dom.height(h + "px");
dom.css("transform", "scale(" + (bw / w).toFixed(2) + "," + (bw / w).toFixed(2) + ")");
dom.css("top", "-" + (h - bh) / 2 + "px");
dom.css("left", "-" + (w - w * (bw / w).toFixed(2)) / 2 + "px");
} else {
dom.width("200%");
dom.height("200%");
dom.css("transform", "scale(0.5,0.5)");
dom.css("top", "-50%");
dom.css("left", "-50%");
}
} else {
if (h > bh) {
dom.width(w + "px");
dom.height(h + "px");
dom.css("transform", "scale(" + (bh / h).toFixed(2) + "," + (bh / h).toFixed(2) + ")");
dom.css("top", "-" + (h - h * (bh / h).toFixed(2)) / 2 + "px");
dom.css("left", "-" + (w - bw) / 2 + "px");
} else {
dom.width("200%");
dom.height("200%");
dom.css("transform", "scale(0.5,0.5)");
dom.css("top", "-50%");
dom.css("left", "-50%");
}
}
}
};