var Utils = function() {
this.Tools;
this.ui;
};
Utils = new Utils();
Utils.prototype.Tools = {
year:'',
month:'',
day:'',
week:'',
time:'',
hours:'',
minute:'',
second:'',
weeks:['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
/**
* 获取当前用户使用的浏览器类型
* @returns
*/
browserVersion:function(){
var explorer = window.navigator.userAgent;
if (explorer.indexOf("MSIE") >= 0) {// ie10及以下
var b_version = navigator.appVersion;
var version = b_version.split(";");
version = version[1].replace(/[ ]/g, "");
version = version.split('MSIE')[1];
browser = 'IE:' + version;
} else if (explorer.indexOf("Firefox") >= 0) {// Firefox
browser = 'Firefox';
} else if (explorer.indexOf("Chrome") >= 0) {// Chrome
browser = 'Chrome';
} else if (explorer.indexOf("Opera") >= 0) {// Opera
browser = 'Opera';
} else if (explorer.indexOf("Safari") >= 0) {// Safari
browser = 'Safari';
} else if (explorer.indexOf("Trident/7.0") >= 0) {// IE11
browser = 'IE:10.0以上';
}
return borwser;
},
strFormatDate : function(param) {
var months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Setp','Oct','Nov','Dec'];
var weeks=['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
var date=param.split(" ");
var browser= new Utils().browserVersion();
if(browser=='Chrome'||browser=='Firefox'||browser=='IE:10.0以上'){
this.year=date[3];
this.month=months[date[1]];
this.day=date[2];
this.time=date[4];
this.week=date[weeks[0]];
return this.year+"年"+this.month+"月"+this.day+"日 "+this.time;
}else if(browser=='IE:10'||browser=='IE:9'||browser=='IE:8'){
this.year=date[5];
this.month=months[date[1]];
this.day=date[2];
this.time=date[3];
this.week=date[weeks[0]];
return this.year+"年"+this.month+"月"+this.day+"日 "+this.time;
}
},
/**
*
* @param date
* @returns {String}
*/
DateFormatDate:function(date){
this.year=date.getFullYear();
this.month=date.getMonth()+1;
this.day=date.getDate();
this.hours=date.getHours();
this.minute=date.getMinutes();
this.second=date.getSeconds();
this.week=date.getDay();
return this.year+"年"+this.month+"月"+this.day+"日 "+this.hours+":"+this.minute+":"+this.second+" 星期"+this.weeks[this.week];
},
/**
* 解决浏览器地址栏乱码问题
* @param strParame 参数名称
* @returns
*/
formatUrlParam:function(strParame){
var args = new Object();
var query = location.search.substring(1); // Get query string
var pairs = query.split("&"); // Break at ampersand
for ( var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); // Look for "name=value"
if (pos == -1)
continue; // If not found, skip
var argname = pairs[i].substring(0, pos); // Extract the name
var value = pairs[i].substring(pos + 1); // Extract the value
value = decodeURIComponent(value); // Decode it, if needed
args[argname] = value; // Store as a property
}
return args[strParame]; // Return the object
},
/**
* 获取选中复选框的值
* @param checkBoxName checkbox的name
* @returns {String}
*/
multipleChoiceCheckBox:function(checkBoxName){
var content='';
var serids =document.getElementsByName(checkBoxName);
for(var i=0;i<serids.length;i++){
if(serids[i].checked){
content+=serids[i].value+",";
}
}
content=content.substr(0,content.length-1);
return content;
},
/**
* 复选框--反选
* @param checkBoxName checkbox的name
* @param parentName 控制反选按钮的id
*/
reverseFlotationCheckBox:function(checkBoxName,parentName)
var bool=$("#"+parentName).attr("checked");
var serids =document.getElementsByName(checkBoxName);
if(bool){
for(var i=0;i<serids.length;i++){
serids[i].checked=true;
}
}else{
for(var i=0;i<serids.length;i++){
serids[i].checked=false;
}
}
},
/**
* 复选框--全选
* @param checkBoxName checkbox的name
* @param parentName 控制反选按钮的id
*/
checkAllCheckBox:function(checkBoxName,parentName){
var serids =document.getElementsByName(checkBoxName);
var bool=$("#"+parentName).attr("checked");
if(bool){
for(var i=0;i<serids.length;i++){
serids[i].checked=true;
}
}else{
for(var i=0;i<serids.length;i++){
serids[i].checked=false;
}
}
},
addOption:function(id,path,defaultValue){
//给select添加选项
$("#"+id).empty();
$.ajax({
url: path,
type: "POST",
data:'type=gfType',
dataType: "json",
async: false,
success: function(results) {
for(var i=0;i<results.length;i++) {
if(results[i].id == defaultValue) {
html += "<option value='" + results[i].id + "' selected>" + results[i].codename + "</option>";
} else {
html += "<option value='" + results[i].id + "'>" + results[i].codename + "</option>";
}
}
$("#"+id).append(html);
},
error: function(e) {
YMLib.Tools.showPrompt("!-logo", "系统错误!请联系管理员!", 5000);
}
});
},
/**
*获取字符串字节数
*/
GetStringByteLength:function(val){
var Zhlength=0;// 全角
var Enlength=0;// 半角
for(var i=0;i<val.length;i++){
if(val.substring(i, i + 1).match(/[^\x00-\xff]/ig) != null)
Zhlength+=1;
else
Enlength+=1;
}
// 返回当前字符串字节长度
return (Zhlength*2)+Enlength;
},
//js实现返回顶部
BackToTop:function(){
$("body,html").animate({scrollTop:0},1000);
},
/**
*复制到粘贴板
*/
copyToShearPlate:function(){
$('.content').click(function(){
$(this).select();
});
//设置swf路径
ZeroClipboard.setMoviePath("ZeroClipboard.swf");
//创建对象
var clip = new ZeroClipboard.Client();
//设置手型
clip.setHandCursor(true);
//绑定按钮(目标对象id)
clip.glue('copy_btn');
//复制内容
clip.addEventListener( "mouseOver", function(client) {
client.setText($('#content').text());
});
//复制成功后的提示
clip.addEventListener( "complete", function(){
alert("copyed successful");
});
},
/**
*判断是否是正确的url地址
*/
IsURL:function(str_url) {
var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
"?(([0-9a-z_!~*'().= $%-] : )?[0-9a-z_!~*'().= $%-] @)?" //ftp的user@
"(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
"|" // 允许IP和DOMAIN(域名)
"([0-9a-z_!~*'()-] \.)*" // 域名- www.
"([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
"[a-z]{2,6})" // first level domain- .com or .museum
"(:[0-9]{1,4})?" // 端口- :80
"((/?)|" // a slash isn't required if there is no file name
"(/[0-9a-z_!~*'().;?:@= $,%#-] ) /?)$";
var re=new RegExp(strRegex);
//re.test()
if (re.test(str_url)){
return (true);
}else{
return (false);
}
},
setValueUeditor:function(){
//当editor创建完毕,给editor设置内容
UE.getEditor('solution').ready(function(){
UE.getEditor('solution').setContent(obj.solution);
});
}
};
Utils.prototype.ui = {
/*
*拼接表格
* @param source 格式如下:
{
"qlmc":"桥梁名称",
"qldm":"桥梁代码",
"qlzxzh":"桥梁中心桩号",
"qlkjfl":"桥梁跨径分类",
"xzqhbm":"行政区划编码",
"lxmc":"路线名称",
"lxbm":"路线代码"
}
* @param tableId 表格id
* @param path 请求地址
*
*/
joinTable:function(source,tableId,path){
field="[[{field: 'ck', checkbox: true},";
var source=data.data;
for(var key in source){
field+="{field: '"+key+"', title:'"+source[key]+"', width: 100, align: 'center'},";
}
field=field.substr(0,field.length-1);
field+="]]";
field = eval(field);
$('#'+tableId).datagrid({
border: false,
fit: true,
fitColumns: true,
rownumbers: true,
pagination: true,
striped: true,
singleSelect: false,
selectOnCheck: true,
checkOnSelect: true,
url: path,
columns:field
});
},
/*
*表格自适应高度
* @param tb_div table 所在div的id
* @param tableId table id
* @param path 请求地址
*
*/
autoHeight:function(tb_div,tableId,path){
var pageSize=Math.floor($('#'+tb_div).height()/40)-1;
$('#'+tableId).datagrid({
fit : true,
fitColumns : true,
loadMsg : '正在加载数据,请稍候...',
url : path,
rownumbers : true,
autoRowHeight : false,
striped : true,
pagination : true,
pageSize : pageSize,
pageList : [ pageSize, pageSize*2, pageSize*3 ],
rowStyler:function(index,row){
return "height:50px;line-height:50px";
}
});
}
}
//正则 去除目标对象中的图片
//return param.replace(/\<img([^>]*)>/gim,"");
//去除目标对象的前后空格
//.replace(/^\s+|\s+$/g, '')
//邮箱验证方法
//if(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value)){
//flag=true;
//}
//手机号和座机的验证方法
//if((/^1[3|5|8]\d{9}$/.test(value)) || (/^0\d{2,3}-?\d{7,8}$/.test(value))){
//flag=true;
//}
//清除指定字符中的html标签
//describe = datas[i].describe.replace(/<[^>].*?>/g,'');
//判断指定字符串是否包含汉字
//(/[\u4e00-\u9fa5]+/).test(describe)
/**
* 通过restClient将url转换成json数据.
*
* @param url 需要转换的url
* @return 返回json
*/
//public String parseServiceUri(String url){
//RestClient client = new RestClient();
// HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
// String path = request.getContextPath();
// String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
// org.apache.wink.client.Resource resource = client.resource("http://192.168.0.250:6080/"+url);
//org.apache.wink.client.Resource resource = client.resource(url);
//String response = resource.accept(MediaType.APPLICATION_JSON).get(String.class);
//return response;
}
//参数乱码
//new String(((String)map.get("name")).getBytes("ISO-8859-1"), "UTF-8")