js公共

    //獲取當前日期
    function _getCurDate(){
        var myDate = new Date();
        var year = myDate.getFullYear(); 
        var month = myDate.getMonth()+1;       
        if(month<10){
            month="0"+month;
        }
        var date = myDate.getDate();    
        if(date<10){
            date="0"+date;
        }   
        var curdate = year+"-"+month+"-"+date;
        return curdate;
    }
    //獲取所在年份的第一天
    function _getCurYearFirstDate(){
        var myDate = new Date();
        var year = myDate.getFullYear(); 
        var curdate = year+"-01-01";
        return curdate;
    }
    
    //獲取當前日期和時間
    function _getCurDateTime(){
        var myDate = new Date();
        var year = myDate.getFullYear(); 
        var month = myDate.getMonth()+1;       
        if(month<10){
            month="0"+month;
        }
        var date = myDate.getDate();   
        if(date<10){
            date="0"+date;
        }    
        var curdate = year+"-"+month+"-"+date;
        
        var hour = myDate.getHours();       //獲取當前小時數(0-23)
        if(hour<10){
            hour="0"+hour;
        }
        var min = myDate.getMinutes();     //獲取當前分鐘數(0-59)
        if(min<10){
            min="0"+min;
        }
        var second = myDate.getSeconds();     //獲取當前秒數(0-59)
        if(second<10){
            second="0"+second;
        }
        return curdate+" "+hour+":"+min+":"+second;
    }
    //獲取當前時間戳
    function _timestamp(){
        var getTimestamp=new Date().getTime();
        return getTimestamp;
    }
    
    //獲取當前年月
    function _getCurMonth(){
        var myDate = new Date();
        var year = myDate.getFullYear(); 
        var month = myDate.getMonth()+1;       
        if(month<10){
            month="0"+month;
        }
        var curmonth = year+"-"+month;
        return curmonth;
    }
    
    //獲取所在月份的第一天
    function _getCurMonthFirstDate(){
        var myDate = new Date();
        var year = myDate.getFullYear(); 
        var month = myDate.getMonth()+1;       
        if(month<10){
            month="0"+month;
        }
        var curdate = year+"-"+month+"-01";
        return curdate;
    }
    
    /*獲取本週第一天*/
    function _getCurWeekFirstDay(){
        var curDate = _getCurDate();
        var week = new Date().getDay();//週日爲0
        var lastDate;
        if(week==0){//週日爲0
            lastDate = _addOrMinusDate(curDate,-6);
        }else if(week==1){//週一爲1
            lastDate = _addOrMinusDate(curDate,0);
        }else if(week==2){//週二爲2
            lastDate = _addOrMinusDate(curDate,-1);
        }else if(week==3){//週三爲3
            lastDate = _addOrMinusDate(curDate,-2);
        }else if(week==4){//週四爲4
            lastDate = _addOrMinusDate(curDate,-3);
        }else if(week==5){//週五爲5
            lastDate = _addOrMinusDate(curDate,-4);
        }else if(week==6){//週六爲6
            lastDate = _addOrMinusDate(curDate,-5);
        }
        return lastDate;
    }
    
    /*獲取本週最後一天*/
    function _getCurWeekLastDay(){
        var curDate = _getCurDate();
        var week = new Date().getDay();//週日爲0
        var lastDate;
        if(week==0){//週日爲0
            lastDate = curDate;
        }else if(week==1){//週一爲1
            lastDate = _addOrMinusDate(curDate,6);
        }else if(week==2){//週二爲2
            lastDate = _addOrMinusDate(curDate,5);
        }else if(week==3){//週三爲3
            lastDate = _addOrMinusDate(curDate,4);
        }else if(week==4){//週四爲4
            lastDate = _addOrMinusDate(curDate,3);
        }else if(week==5){//週五爲5
            lastDate = _addOrMinusDate(curDate,2);
        }else if(week==6){//週六爲6
            lastDate = _addOrMinusDate(curDate,1);
        }
        return lastDate;
    }
    /*日期加減天數*/
    function _addOrMinusDate(curDate,days){
        var a = new Date()//不能改爲var a = new Date(curDate),不然周計劃報錯
        a = a.valueOf()
        a = a + days * 24 * 60 * 60 * 1000
        a = new Date(a)
        
        var year = a.getFullYear(); 
        var month = a.getMonth()+1;       
        if(month<10){
            month="0"+month;
        }
        var date = a.getDate();    
        if(date<10){
            date="0"+date;
        }   
        var newdate = year+"-"+month+"-"+date;
        return newdate;
    }css

    String.prototype.replaceAll = function(s1,s2) { 
           return this.replace(new RegExp(s1,"gm"),s2); 
    }
    
    /*判斷字符串字節長度*/
    function gblen(str) {  
        var len = 0;  
        if(str=='undefined'||str==undefined){
            return len;
        }
        
          for (var i=0; i<str.length; i++) {  
            if (str.charCodeAt(i)>127 || str.charCodeAt(i)==94) {  
                   len += 2;  
             }else{  
                   len ++;  
             }  
           }  
          return len;  
    }
    
    /**
        *@ title:清表單內容
        *@ Description:清表單內容
        *@ param:objE:表單對象
        *@ throw 拋出異常
        *@ author:嚴繼勝
        *@ date:2015-12-23
        *@ modify Description 修改內容描述
        *@ modify man:修改人
        *@ modify date:修改時間(yyyy-MM-dd)
    */
    function clearForm(objE){  
        $(objE).find(':input').each(  
            function(){  
                switch(this.type){  
                case 'passsword':  
                case 'select-multiple':  
                case 'select-one':  
                case 'text':  
                case 'textarea':  
                    $(this).val('');  
                    break;  
                case 'checkbox':  
                case 'radio':  
                    this.checked = false;  
                }  
            }     
        );  
    }
    
    /*加載進度條*/
    function _loadProgressBar(info) {  
        $("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");  
        $("<div class=\"datagrid-mask-msg\"></div>").html(info+"。。。").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });  
    }  
    //關閉進度條  
    function _dispalyProgressBar() {  
        $(".datagrid-mask").remove();  
        $(".datagrid-mask-msg").remove();  
    }  
    
     //內容顯示不全解決
    function _setContent(val,row,index){
        if(typeof(val) == "undefined"){
            val = "";
        }
        return '<span title="'+val+'">'+val+'</span>';
    }
    
    
    //合併行
    //調用方式:mergeCellsByField('tt','ITEM_NAME');
    function mergeCellsByField(tableID,colList){
        var ColArray = colList.split(",");
        var tTable = $('#'+tableID);
        var TableRowCnts=tTable.datagrid("getRows").length;
        var tmpA;
        var tmpB;
        var PerTxt = "";
        var CurTxt = "";
        var alertStr = "";
        for (j=ColArray.length-1;j>=0 ;j-- ){
            //當循環至某新的列時,變量復位。
            PerTxt="";
            tmpA=1;
            tmpB=0;
            //從第一行(表頭爲第0行)開始循環,循環至行尾(溢出一位)
            for (i=0;i<=TableRowCnts ;i++ ){
                if (i==TableRowCnts){
                    CurTxt="";
                }else{
                    CurTxt=tTable.datagrid("getRows")[i][ColArray[j]];
                }
                if (PerTxt==CurTxt){
                    tmpA+=1;
                }else{
                    tmpB+=tmpA;
                    tTable.datagrid('mergeCells',{
                        index:i-tmpA,
                        field:ColArray[j],
                        rowspan:tmpA,
                        colspan:null
                    });
                    tmpA=1;
                }
                PerTxt=CurTxt;
            }
        }
    }html

//試運行結果查看的時候合併指標、參數信息
function mergeCellsByField_customer(tableID,colList){
    var ColArray = colList.split(",");
    var tTable = $('#'+tableID);
    var TableRowCnts=tTable.datagrid("getRows").length;
    var tmpA;
    var tmpB;
    var PerTxt = "";
    var CurTxt = "";
    var alertStr = "";
    for (j=ColArray.length-1;j>=0 ;j-- ){
        //當循環至某新的列時,變量復位。
        PerTxt="";
        tmpA=1;
        tmpB=0;
        //從第一行(表頭爲第0行)開始循環,循環至行尾(溢出一位)
        for (i=0;i<=TableRowCnts ;i++ ){
            if (i==TableRowCnts){
                CurTxt="";
            }else{
                CurTxt=tTable.datagrid("getRows")[i][ColArray[j]];
            }
            if (PerTxt==CurTxt){
                tmpA+=1;
            }else{
                tmpB+=tmpA;
                tTable.datagrid('mergeCells',{
                    index:i-tmpA,
                    field:"RECORD_UUID",
                    rowspan:tmpA,
                    colspan:null
                });
                tTable.datagrid('mergeCells',{
                    index:i-tmpA,
                    field:"TARGET_NAME",
                    rowspan:tmpA,
                    colspan:null
                });
                tTable.datagrid('mergeCells',{
                    index:i-tmpA,
                    field:"TARGET_FORMULA",
                    rowspan:tmpA,
                    colspan:null
                });
                tTable.datagrid('mergeCells',{
                    index:i-tmpA,
                    field:"IF_UNUSUAL",
                    rowspan:tmpA,
                    colspan:null
                });
                tmpA=1;
            }
            PerTxt=CurTxt;
        }
    }
}app

function getCount(str1,str2){
  var r=new RegExp(str2,"gi");
  var result = str1.match(r);
  if(result==null||result=='undefined'||result==undefined){
      return 0;
  }else{
       return str1.match(r).length;
  }
}
/*四捨五入*/函數

function _round(amount,score){
    if(amount!=''){
        return amount.toFixed(score);;
    }
}
/*字符轉日期
 str(格式):2015-01-03 19:10:20
*/
function strToDate(str) {
     var tempStrs = str.split(" ");
     
     var dateStrs = tempStrs[0].split("-");
     var year = parseInt(dateStrs[0],10);
     var month = parseInt(dateStrs[1],10)-1;
     var day = parseInt(dateStrs[2],10);
     var timeStrs = tempStrs[1].split(":");
     var hour = parseInt(timeStrs [0], 10);
     var minute = parseInt(timeStrs[1], 10);
     var second = parseInt(timeStrs[2], 10);
     
     var date = new Date(year, month, day, hour, minute, second);
     return date;
}
/*兩個日期求天數差值
 str(格式):2015-01-03  2015-01-13
*/
function getDays(strDateStart,strDateEnd){
   var strSeparator = "-"; //日期分隔符
   var oDate1;
   var oDate2;
   var iDays;
   oDate1= strDateStart.split(strSeparator);
   oDate2= strDateEnd.split(strSeparator);
   var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
   var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
   iDays = parseInt(Math.abs(strDateS - strDateE ) / 1000 / 60 / 60 /24)//把相差的毫秒數轉換爲天數 
   return iDays ;
}
function forbidBackSpace(e) {
    var ev = e || window.event; //獲取event對象 
    var obj = ev.target || ev.srcElement; //獲取事件源 
    var t = obj.type || obj.getAttribute('type'); //獲取事件源類型 
    //獲取做爲判斷條件的事件類型 
    var vReadOnly = obj.readOnly;
    var vDisabled = obj.disabled;
    //處理undefined值狀況 
    vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
    vDisabled = (vDisabled == undefined) ? true : vDisabled;
    //當敲Backspace鍵時,事件源類型爲密碼或單行、多行文本的, 
    //而且readOnly屬性爲true或disabled屬性爲true的,則退格鍵失效 
    var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
    //當敲Backspace鍵時,事件源類型非密碼或單行、多行文本的,則退格鍵失效 
    var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
    //判斷 
    if (flag2 || flag1) return false;
}ui

//若是提供窗口名稱,則只打開一個窗口,不然每次打開一個新窗口
//to open a new window without status
var winNum=0;
var ObjWin=null;this

//爲了解決xp sp2下不能滾動的問題,將全部的window.open替換成了這個函數
function openwin_xp2(url, winName, type, leftMargin, topMargin, width, height){
  if (type == "fullscreen"){
    return openwin(url,winName, leftMargin, topMargin, width, height);
  }else{
    return openwin(url, winName);
  }
}
//var winName="openWin";
function openwin(URL,winName,leftMargin,topMargin,winWidth,winHeight){
    if(ObjWin!=null && winName!=null){
        ObjWin.close();
    }
    if(winName !=null && leftMargin!=null && topMargin!=null && winWidth !=null && winHeight !=null){
        ObjWin=window.open(URL,winName,"left="+leftMargin+", top="+topMargin+", width="+winWidth+", height="+winHeight+", menu=no, status=no, resizable=no, scrollbars=no");
    }else if(winName !=null && winWidth!=null && winHeight!=null){
        var rossToLeft=(screen.availWidth-winWidth+200)/2;
        var rossToTop=(screen.availHeight-winHeight-4)/2-20;
        ObjWin=window.open(URL,winName,"left="+rossToLeft+", top="+rossToTop+", width="+winWidth+", height="+winHeight+", menu=no, status=no, resizable=no, scrollbars=no");
    }else if(winName !=null && winWidth!=null){
        var rossToLeft=(screen.availWidth-winWidth+200)/2;
        ObjWin=window.open(URL,winName,"left="+rossToLeft+", width="+winWidth+",menu=no, status=no, resizable=no, scrollbars=yes");
    }else if(winName != null){
        var rossToLeft=(screen.availWidth-799)/2;
        var rossToTop=(screen.availHeight-599)/2-20;
        ObjWin=window.open(URL,winName,"left="+rossToLeft+", top="+rossToTop+", width=999,  height=603, menu=no, status=no, resizable=no, scrollbars=yes");
    }else{
          if (winName == null){
            winNum++;
            winName="openWin"+winNum;
                //left+=winNum*20;
                //top_a+=winNum*20;
        }
        var rossToLeft=(screen.availWidth-799)/2;
        var rossToTop=(screen.availHeight-599)/2-20;
        window.open(URL,'_blank',"left="+rossToLeft+", top="+rossToTop+", width=999,  height=603, menu=no, status=no, resizable=no, scrollbars=yes");
    }
    return ObjWin;
}url

//easyui formatter show detail
function easyuiDetailFmt(value,row,index){
    if(value!=null){
        return "<span title='"+value+"'>"+value+"</span>";
    }else{
        return "";
    }
}spa

相關文章
相關標籤/搜索