js的通用组件

/**
 */
var PublicUtil = {
    //提示框类型
    alertType: {
        warnType: 0,
        okType: 1
    },


    //alert提示框
    alertWindow: function (alertType, title, msg, okBtnText, okFunction) {
        var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
        var dialogId = "dialogWindow_" + randowSuffix;
        var dialogOverlayId = "dialogOverlay_" + randowSuffix;


        var stringBuilder = this.StringBuilder();
        switch (alertType) {
            case this.alertType.okType:
                stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '"  style="display:none;">');
                break;
            case this.alertType.warnType:
                stringBuilder.Append('<div class="dialogWindow warnDialog" id="' + dialogId + '"  style="display:none;">');
                break;
        }


        stringBuilder.Append('<div class="dialogHeader">');
        stringBuilder.Append('    <span class="dialogTitle">' + title + '</span>');
        stringBuilder.Append('    <a href="javascript:void(0);" class="dialogClose"></a>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div class="dialogBody">');
        stringBuilder.Append('    <table cellspacing="0px" border="0px" cellpadding="0px">');
        stringBuilder.Append('        <tr>');
        stringBuilder.Append('            <td><span class="dialogIcon"></span></td>');
        stringBuilder.Append('            <td>');
        stringBuilder.Append('                <span class="dialogMsg">' + msg + '</span>');
        stringBuilder.Append('            </td>');
        stringBuilder.Append('        </tr>');
        stringBuilder.Append('    </table>');
        stringBuilder.Append('    <div class="dialogFooter">');
        stringBuilder.Append('    <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
        stringBuilder.Append('   </div>');
        stringBuilder.Append('    <div style="clear:both;"></div>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div style="clear:both;"></div>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div class="dialog-overlay" id="' + dialogOverlayId + '"   style="display:none;"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe></div>');
        if ($("#" + dialogId).length > 0) {
            $("#" + dialogId).remove();
            $("#" + dialogOverlayId).remove();
        }
        $("body").append(stringBuilder.ToString());
        var zIndex = 999;
        //设置层次关系
        var currentCount = $(".dialogWindow").length + 1;
        zIndex += currentCount;


        $("body").css("overflow", "hidden");
        var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
        var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
        $("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });


        $("#" + dialogOverlayId).css({
            'left': 0, 'top': 0,
            'width': $(document).width(),
            'height': $(document).height(),
            'z-index': zIndex,
            'position': 'absolute'
        })


        $("#" + dialogId + " .dialogClose").click(function () {
            $("#" + dialogId).remove();
            $("#" + dialogOverlayId).remove();
            $("body").css("overflow", "auto");
            $(window).unbind("resize.dialogwindow");
        })
        $("#" + dialogId + " .dialogOK").click(function () {
            if (okFunction != null && okFunction != undefined) {
                okFunction();
            }
            if ($("#" + dialogId).length > 0) {
                $("#" + dialogId + " .dialogClose").click();
            }
        });
        $(window).bind("resize.dialogwindow", function () {
            var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
            var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
            $("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
            $("#" + dialogOverlayId).css({
                'width': $(document).width()
            })
        })
        $("#" + dialogOverlayId).show();
        $("#" + dialogId).show();
    },




    /*内容可以自定义的弹出框  返回框对象
     *title 标题
     *content 弹出框中的内容
     *okBtnText  确定按钮的文字     为空时则不显示该按钮
     *okFunction 确定按钮的事件    无事件就为null
     *cancelBtnText 取消按钮的文字      为空时则不显示该按钮
     *cancelFunc  取消按钮的事件      无事件就为null
     */
    dialogWindow: function (title, content, okBtnText, okFunction, cancelBtnText, cancelFunc) {
        var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
        var dialogId = "dialogWindow_" + randowSuffix;
        var dialogOverlayId = "dialogOverlay_" + randowSuffix;


        var stringBuilder = this.StringBuilder();
        stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
        stringBuilder.Append('<div class="dialogHeader">');
        stringBuilder.Append('    <span class="dialogTitle">' + title + '</span>');
        stringBuilder.Append('    <a href="javascript:void(0);" class="dialogClose"></a>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div class="dialogBody">');
        stringBuilder.Append('    <table cellspacing="0px" border="0px" cellpadding="0px">');
        stringBuilder.Append('        <tr>');
        stringBuilder.Append('            <td>');
        stringBuilder.Append(content);
        stringBuilder.Append('            </td>');
        stringBuilder.Append('        </tr>');
        stringBuilder.Append('    </table>');
        stringBuilder.Append('    <div class="dialogFooter">');
        if (okBtnText != "") {
            stringBuilder.Append('    <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
        }
        if (cancelBtnText != "") {
            stringBuilder.Append('    <input type="button" class="dialogCancel newCancel_Btn" value="' + cancelBtnText + '" />');
        }
        stringBuilder.Append('   </div>');
        stringBuilder.Append('    <div style="clear:both;"></div>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div style="clear:both;"></div>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div class="dialog-overlay"  id="' + dialogOverlayId + '"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe></div>');
        if ($("#" + dialogId).length > 0) {
            $("#" + dialogId).remove();
            $("#" + dialogOverlayId).remove();
        }
        $("body").append(stringBuilder.ToString());
        var zIndex = 999;
        //设置层次关系
        var currentCount = $(".dialogWindow").length + 1;
        zIndex += currentCount;
        $("body").css("overflow", "hidden");
        var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
        var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
        $("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
        
        $("#" + dialogOverlayId).css({
            'left': 0, 'top': 0,
            'width': $(document).width(),
            'height': $(document).height(),
            'z-index': zIndex,
            'position': 'absolute'
        })
        $("#" + dialogId + " .dialogClose").click(function () {
            $("#" + dialogId).remove();
            $("#" + dialogOverlayId).remove();
            $("body").css("overflow", "auto");
            $(window).unbind("resize.dialogwindow");
        })
        $("#" + dialogId + " .dialogOK").click(function () {
            if (okFunction != null && okFunction != undefined) {
                if(okFunction($("#" + dialogId))==false){
                return;
                }
            }
            if ($("#" + dialogId).length > 0) {
                $("#" + dialogId + " .dialogClose").click();
            }
        });
        $("#" + dialogId + " .dialogCancel").click(function () {
            $("#" + dialogId + " .dialogClose").click();
            if (cancelFunc != null && cancelFunc != undefined) {
                cancelFunc();
            }
        });
        $(window).bind("resize.dialogwindow", function () {
            var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
            var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
            $("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
            $("#" + dialogOverlayId).css({
                'width': $(document).width()
            })
        })
        
        //拖动
        var mouse={x:0,y:0};
$("#" + dialogId + " .dialogHeader").mousedown(function (event) {
           var e = window.event || event;
           var offset = $("#" + dialogId).offset();
           mouse.x = e.clientX - offset.left;
           mouse.y = e.clientY - offset.top;
           $(document).bind('mousemove', moveDialog).bind("mouseup",function(){$(document).unbind('mousemove', moveDialog);});
       });
        function moveDialog(event) {
            var e = window.event || event;
            var top = e.clientY - mouse.y;
            var left = e.clientX - mouse.x;
            $("#" + dialogId).css({"top": top, "left": left});
        };
        $("#" + dialogId).show();
        
        return $("#" + dialogId);
    },


    //确定提示框
    confirmWindow: function (alertType, title, msg, okBtnText, okFunction, cancelBtnText, cancelFunc) {
        var randowSuffix = JCPublicUtil.DateFormat(new Date(), "YYYYMMddhhmmss");
        var dialogId = "dialogWindow_" + randowSuffix;
        var dialogOverlayId = "dialogOverlay_" + randowSuffix;


        var stringBuilder = this.StringBuilder();
        switch (alertType) {
            case this.alertType.okType:
                stringBuilder.Append('<div class="dialogWindow" id="' + dialogId + '" style="display:none;">');
                break;
            case this.alertType.warnType:
                stringBuilder.Append('<div class="dialogWindow warnDialog" id="' + dialogId + '"  style="display:none;">');
                break;
        }


        stringBuilder.Append('<div class="dialogHeader">');
        stringBuilder.Append('    <span class="dialogTitle">' + title + '</span>');
        stringBuilder.Append('    <a href="javascript:void(0);" class="dialogClose"></a>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div class="dialogBody">');
        stringBuilder.Append('    <table cellspacing="0px" border="0px" cellpadding="0px">');
        stringBuilder.Append('        <tr>');
        stringBuilder.Append('            <td><span class="dialogIcon"></span></td>');
        stringBuilder.Append('            <td>');
        stringBuilder.Append('                <span class="dialogMsg">' + msg + '</span>');
        stringBuilder.Append('            </td>');
        stringBuilder.Append('        </tr>');
        stringBuilder.Append('    </table>');
        stringBuilder.Append('    <div class="dialogFooter">');
        stringBuilder.Append('    <input type="button" class="dialogOK newOk_Btn" value="' + okBtnText + '" />');
        stringBuilder.Append('    <input type="button" class="dialogCancel newCancel_Btn" value="' + cancelBtnText + '" />');
        stringBuilder.Append('   </div>');
        stringBuilder.Append('    <div style="clear:both;"></div>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div style="clear:both;"></div>');
        stringBuilder.Append('</div>');
        stringBuilder.Append('<div class="dialog-overlay"  id="' + dialogOverlayId + '"   style="display:block;"><iframe frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0); opacity:0;"></iframe></div>');
        if ($("#" + dialogId).length > 0) {
            $("#" + dialogId).remove();
            $("#" + dialogOverlayId).remove();
        }
        $("body").append(stringBuilder.ToString());
        var zIndex = 999;
        //设置层次关系
        var currentCount = $(".dialogWindow").length + 1;
        zIndex += currentCount;


        $("body").css("overflow", "hidden");
        var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
        var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
        $("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });


        $("#" + dialogOverlayId).css({
            'left': 0, 'top': 0,
            'width': $(document).width(),
            'height': $(document).height(),
            'z-index': zIndex,
            'position': 'absolute'
        })


        $("#" + dialogId + " .dialogClose").click(function () {
            $("#" + dialogId).remove();
            $("#" + dialogOverlayId).remove();
            $("body").css("overflow", "auto");
            $(window).unbind("resize.dialogwindow");
        })
        $("#" + dialogId + " .dialogOK").click(function () {
            if (okFunction != null && okFunction != undefined) {
            if(okFunction($("#" + dialogId))==false){
                return;
                }
            }
            if ($("#" + dialogId).length > 0) {
                $("#" + dialogId + " .dialogClose").click();
            }
        });
        $("#" + dialogId + " .dialogCancel").click(function () {
            $("#" + dialogId + " .dialogClose").click();
            if (cancelFunc != null && cancelFunc != undefined) {
                cancelFunc();
            }
        });
        $(window).bind("resize.dialogwindow", function () {
            var top = ($(window).height() - $("#" + dialogId).height()) / 2 + $(document).scrollTop();
            var left = ($(window).width() - $("#" + dialogId).width()) / 2 + $(document).scrollLeft();
            $("#" + dialogId).css({ "z-index": zIndex + 1, "top": top, "left": left });
            $("#" + dialogOverlayId).css({
                'width': $(document).width()
            })
        })
        $("#" + dialogOverlayId).show();
        $("#" + dialogId).show();
    },


    //字符串对象
    StringBuilder: function () {
        //实体对象
        var StringBuilderObj = function (args) {
            this._buffers = [];
            this._length = 0;
            this._splitChar = args.length > 0 ? args[args.length - 1] : '';
            if (args.length > 0) {
                for (var i = 0, iLen = args.length - 1; i < iLen; i++) {
                    this.Append(args[i]);
                }
            }
        }


        //append方法
        StringBuilderObj.prototype.Append = function (str) {
            this._length += str.length;
            this._buffers[this._buffers.length] = str;
        }


        //向对象中添加字符串
        //参数:一个字符串值
        StringBuilderObj.prototype.Add = StringBuilderObj.prototype.append;


        //向对象附加格式化的字符串
        //参数:参数一是预格式化的字符串,如:'{0} {1} {2}'
        //格式参数可以是数组,或对应长度的arguments,
        StringBuilderObj.prototype.AppendFormat = function () {
            if (arguments.length > 1) {
                var TString = arguments[0];
                if (arguments[1] instanceof Array) {
                    for (var i = 0, iLen = arguments[1].length; i < iLen; i++) {
                        var jIndex = i;
                        var re = eval("/\\{" + jIndex + "\\}/g;");
                        TString = TString.replace(re, arguments[1][i]);
                    }
                }
                else {
                    for (var i = 1, iLen = arguments.length; i < iLen; i++) {
                        var jIndex = i - 1;
                        var re = eval("/\\{" + jIndex + "\\}/g;");
                        TString = TString.replace(re, arguments[i]);
                    }
                }
                this.Append(TString);
            }
            else if (arguments.length == 1) {
                this.Append(arguments[0]);
            }
        }


        //字符串长度(相当于ToString()后输出的字符串长度
        StringBuilderObj.prototype.Length = function () {
            if (this._splitChar.length > 0 && (!this.IsEmpty())) {
                return this._length + (this._splitChar.length * (this._buffers.length - 1));
            }
            else {
                return this._length;
            }
        }


        //字符串是否为空
        StringBuilderObj.prototype.IsEmpty = function () {
            return this._buffers.length <= 0;
        }


        //清空
        StringBuilderObj.prototype.Clear = function () {
            this._buffers = [];
            this._length = 0;
        }


        //输出
        //参数:可以指定一个字符串(或单个字符),作为字符串拼接的分隔符
        StringBuilderObj.prototype.ToString = function () {
            if (arguments.length == 1) {
                return this._buffers.join(arguments[1]);
            }
            else {
                return this._buffers.join(this._splitChar);
            }
        }


        return new StringBuilderObj(arguments);
    },


    //时间格式转换
    DateFormat: function (dateObj, format) {
        try {
            /*
             * eg:format="YYYY-MM-dd hh:mm:ss";
             */
            var o = {
                "Y+": dateObj.getFullYear(),
                "M+": dateObj.getMonth() + 1,  //month
                "d+": dateObj.getDate(),     //day
                "h+": dateObj.getHours(),    //hour
                "m+": dateObj.getMinutes(),  //minute
                "s+": dateObj.getSeconds(), //second
                "q+": Math.floor((dateObj.getMonth() + 3) / 3),  //quarter
                "S": dateObj.getMilliseconds() //millisecond
            }


            if (/(Y+)/.test(format)) {
                format = format.replace(RegExp.$1, (dateObj.getFullYear() + "").substr(4 - RegExp.$1.length));
            }


            for (var k in o) {
                if (new RegExp("(" + k + ")").test(format)) {
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
                }
            }
            return format;
        } catch (e) {
            return "";
        }
    },


    //初始化几个模块的事件绑定。
    initModuleFunc: function () {
        $(function () {
            //绑定高级搜索的事件
            if ($("#SearchDiv").length > 0) {
                $("#SearchDiv").click(function (e) { e.stopPropagation(); });


                //高级搜索按钮的事件
                $("#topDivBtn").click(function (e) {
                    if ($("#topDiv").hasClass("TopSearchSelected")) {
                        $("#topDiv").removeClass().addClass("TopSearch");
                        $("#SearchDiv").hide();
                    }
                    else {
                        $("#topDiv").removeClass().addClass("TopSearchSelected");
                        $("#SearchDiv").show();
                    }
                    $(document).bind("click", function () {
                        if ($("#topDiv").hasClass("TopSearchSelected")) {
                            $("#topDiv").removeClass().addClass("TopSearch");
                            $("#SearchDiv").hide();
                        }
                        $(document).unbind("click");
                    })
                    e.stopPropagation();
                });


                //取消高级搜索
                $("#cancelBtn").click(function () { $("#topDivBtn").click(); });
            }




            //绑定列表行的颜色和鼠标移动上去的事件----------------------------------------
            if ($(".cyListContent").length > 0) {
                $(".ListItem").hover(function () { $(this).addClass("selectUL") }, function () { $(this).removeClass("selectUL"); })
                //给列表行的奇数行添加背景颜色
                $(".cyListContent>ul>li:odd").css("background", "#f2f2f2");
            }




            //全选----------------------------------------------
            var cbList = document.getElementsByName("cb");
            var all = document.getElementById("checkAll");
            if (all != null) {
                all.onclick = function () {
                    for (var i = 0; i < cbList.length; i++) {
                        cbList[i].checked = all.checked;
                    }
                };
            }


            //导航选择------------------------------------------------------
            if ($(".daohang").length > 0) {
                $(".daohang>ul>li").click(function () {
                    $(this).parent().find("li").removeClass();
                    $(this).addClass("selectedLi");
                });
            }


            //流程定制-------------------------------------------------------
            $(".listContent").each(function(){
            $(this).find("table tr.listtr:even").addClass("evenTr");
            $(this).find("table tr.listtr:odd").addClass("oddTr");
            $(this).find("table tr.listtr").mouseover(function () {
                    $(this).addClass("selectedTR");
                }).mouseout(function () {
                    $(this).removeClass("selectedTR");
                });
            })
        });
    },


    /*某个字符串中是否包含另一个字符串或者包含另一个字符串以特殊字符分割的字符串,注意英文为英文单词
     * mainStr 为主字符串
     * strContained 被包含的字符串
     * splitMark 被包含字符串的分隔符,如果没有分隔符可以为空字符串
     * 返回实体对象{"isContain":true,"msg":""},true为都包含否则不全部包含或者全部不包含
     * */
    containsStr:function(mainStr,strContained,splitMark){
    var isContain=true;
    var msg="";
    var strArray=new Array();
    if(strContained==""){
    return {"isContain":false,"msg":"0"};
    }
    if(splitMark!=""){
    strArray=strContained.split(splitMark);
    }else{
    strArray.push(strContained);
    }
   
    for(var i=0;i<strArray.length;i++){
    //中文
    if(/[\u4e00-\u9fa5]+/g.test(strArray[i])){
    if(mainStr.indexOf(strArray[i])==-1){
    isContain=false;
    msg+=strArray[i]+"\r\n";
    }
    }else{
    //英文单词
    var regex=new RegExp("\\b"+strArray[i]+"\\b","g");
    if(!regex.test(mainStr)){
    isContain=false;
    msg+=strArray[i]+"\r\n";
    }
    }
    }
   
    return {"isContain":isContain,"msg":msg};
    },
    
    //流程表单模板实体类
    FlowFormTemplate: {
        prefixStr: "flowPropMap['",
        suffixStr: "']",
        fiexNum: 2,
        initFunc: function () {
            //绑定新增列表事件
            $(".addTableRow").not("[disabled]").click(function () {
                JCPublicUtil.FlowFormTemplate._addRow($(this));
            });


            //删除列表
            $(".delTableRow").not("[disabled]").click(function (e) {
                JCPublicUtil.FlowFormTemplate._delRow($(this)[0]);
                e.stopPropagation();
                return false;
            });


            //绑定输入框事件
            $("input[data-calculate-to-variable]").keyup(function () {
                JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
            });




            //样式绑定
            $(".dynamic-form-table-body,.dynamic-form-table-body table").css({ "border-collapse": "collapse", "border": "solid 1px #cccccc" }).attr({ "cellpadding": "0", "cellspacing": "0" });
            $(".dynamic-form-table-body  td,.dynamic-form-table-body  th").css({ "border": "solid 1px #cccccc" });
            $(".delTableRow").html('<img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/delete.png" style="border:0px;"/>');
            $(".addTableRow").html('<img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/add.gif" style="border:0px;"/>');
            $("table[tableType='JCTABLE']").find("thead tr").css({ "background-color": "#cccccc" });




            //控制列表的新增和删除按钮是否显示
            $("table[tableType='JCTABLE']").each(function () {
                var isShowAddBtn = $(this).attr("data-showAddBtn") != undefined && $(this).attr("data-showAddBtn") == "true" ? true : false;
                var isShowDelBtn = $(this).attr("data-showDelBtn") != undefined && $(this).attr("data-showDelBtn") == "true" ? true : false;
                var AddBtns = $(this).find(".addTableRow");
                var DelBtns = $(this).find(".delTableRow");
                if (!isShowAddBtn) {
                    AddBtns.hide();
                }
                if (!isShowDelBtn) {
                    DelBtns.hide();
                }


                if (isShowAddBtn && isShowDelBtn) {
                    $(this).find("tr").each(function () {
                        $(this).find("td:last").hide();
                        $(this).find("th:last").hide();
                    })
                }
                //         var disableAddBtns=$(this).find(".addTableRow:disabled");
                //         var disableDelBtns=$(this).find(".delTableRow:disabled");
                //         //存在没作用的新增按钮
                //         if(disableAddBtns.length>0){
                //         if(!isShowAddBtn){
                //         $(this).find(".addTableRow").hide();
                //         }
                //         }
                //        
                //         //存在没作用删除按钮
                //         if(disableDelBtns.length>0){
                //         if(!isShowDelBtn){
                //         $(this).find(".delTableRow").hide();
                //         }
                //         }
                //        
                //         //如果两者都存在,就隐藏最后一列
                //         if(disableAddBtns.length>0&&disableDelBtns.length>0){
                //         $(this).find("tr").each(function(){
                //         $(this).find("td:last").hide();
                //         $(this).find("th:last").hide();
                //         })
                //         }






            })


        },


        //新增列表事件
        _addRow: function (obj) {
            var prefix = this.prefixStr;
            var suffix = this.suffixStr;
            var tr = obj.closest("tr").clone(true);
            var table = obj.closest("table['tabletype'='JCTABLE']");
            var currentRowNum = $('input[name="' + prefix + table.attr("name") + '_HiddenField' + suffix + '"]');
            var maxRowNum = table.attr("data-maxRowNum");
            if (isNaN(Number(maxRowNum))) {
                maxRowNum = 20;
            }


            if (Number(currentRowNum.val()) >= maxRowNum) {
                alert("最多只能添加" + maxRowNum + "行!");
                return;
            }
            //给控件名称加上序号
            tr.find('[name^="' + prefix + '"]').each(function () {
                var name = $(this).attr("name").replace(prefix, "").replace(suffix, "");
                name = name + "_" + currentRowNum.val();
                $(this).attr("name", prefix + name + suffix);
                $(this).val("");
                //同时修改操作目标名称
                if ($(this).attr("data-calculate-to-variable") != undefined) {
                    var calculateTo = $(this).attr("data-calculate-to-variable");
                    //如果他的计算值在同一行内,则修改属性值
                    if (tr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
                        $(this).attr("data-calculate-to-variable", calculateTo + "_" + currentRowNum.val())
                    }




                    //添加计算事件
                    $(this).keyup(function () {
                        JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
                    })
                }
            });
            var isShowDelBtn = table.attr("data-showDelBtn") != undefined && table.attr("data-showDelBtn") == "true" ? true : false;
            if (isShowDelBtn) {
                //添加删除按钮
                tr.children("td:last").html('<a href="javascript:void(0);" class="delTableRow" οnclick="JCPublicUtil.FlowFormTemplate._delRow(this);return false;"><img src="' + JCPublicUtil.Location.getRootPath() + '/images/funcation_ico/delete.png" style="border:0px;"/></a>');
            } else {
                tr.children("td:last").html("");
            }
            table.children("tbody").find("tr.JCTABLE_Row:last").after(tr);
            currentRowNum.val(table.find(".JCTABLE_Row").length);
        },


        //删除行 同时重新计算
        _delRow: function (delObj) {
            var prefix = this.prefixStr;
            var suffix = this.suffixStr;
            var tr = $(delObj).closest("tr");
            var table = $(delObj).closest("table['tabletype'='JCTABLE']");
            var dataCalculateToVariable = tr.find("[data-calculate-to-variable]");
            dataCalculateToVariable.each(function (index) {
                var calculateTo = $(this).attr("data-calculate-to-variable");
                //如果他的计算值在同一行内,则不重新计算
                if (tr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
                    if (index == dataCalculateToVariable.length - 1) {
                        removeTr(tr);
                    }
                    return true;
                } else {
                    $(this).val("");
                    JCPublicUtil.FlowFormTemplate.calculateOperate($(this)[0]);
                    if (index == dataCalculateToVariable.length - 1) {
                        removeTr(tr);
                    }
                }
            })


            table.find('input[name="' + prefix + table.attr("name") + '_HiddenField' + suffix + '"]').val(table.find(".JCTABLE_Row").length);


            //移除行私有方法 trObj jquery对象
            function removeTr(trObj) {
                var controls = trObj.find('[name^="' + prefix + '"]');
                if (controls.length > 0) {
                    var inputName = controls.eq(0).attr("name").replace(prefix, "").replace(suffix, "");
                    var index = parseInt(inputName.split("_")[1], 10);
                    var nextAllTr = trObj.nextAll();
                    //修改即将删除行后的所有行name值
                    nextAllTr.each(function (i) {
                        if ($(this).hasClass("JCTABLE_Row")) {
                            var currentTr = $(this);
                            //给控件名称加上序号
                            $(this).find('[name^="' + prefix + '"]').each(function () {
                                var name = $(this).attr("name").replace(prefix, "").replace(suffix, "");
                                name = name.split("_")[0];
                                name = name + "_" + (index + i);
                                $(this).attr("name", prefix + name + suffix);
                                //同时修改操作目标名称
                                if ($(this).attr("data-calculate-to-variable") != undefined) {
                                    var calculateTo = $(this).attr("data-calculate-to-variable");
                                    //如果他的计算值在同一行内,则修改属性值
                                    if (currentTr.find('[name="' + prefix + calculateTo + suffix + '"]').length > 0) {
                                        calculateTo = calculateTo.split("_")[0];
                                        $(this).attr("data-calculate-to-variable", calculateTo + "_" + (index + i))
                                    }
                                }
                            });
                        }
                    });
                    trObj.remove();
                }
            }
        },


        //计算事件
        //currentObj是dom对象
        calculateOperate: function (currentObj) {
            var prefix = this.prefixStr;
            var suffix = this.suffixStr;
            if ($(currentObj).attr("data-calculate-to-variable") != undefined) {
                var calculateTo = $(currentObj).attr("data-calculate-to-variable");
                var calculateOp = $(currentObj).attr("calculate-op");
                var resultStr = "";
                switch (calculateOp) {
                    case "plus":
                        var sum = 0;
                        var fixedCount = 0;
                        $("input[data-calculate-to-variable='" + calculateTo + "']").each(function () {
                            var valStr = $.trim($(this).val());
                            if (valStr != "" && !isNaN(Number(valStr))) {
                                sum += Number(valStr);
                                if (valStr.indexOf(".") != -1) {
                                    var tempCount = valStr.split(".")[1].length;
                                    if (tempCount > fixedCount) {
                                        fixedCount = tempCount;
                                    }
                                }
                            }
                        })
                        resultStr = sum.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
                        break;
                    case "minus":
                        var minusResult = 0;
                        var fixedCount = 0;
                        $("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
                            var valStr = $.trim($(this).val());
                            if (valStr != "" && !isNaN(Number(valStr))) {
                                if (i == 0) {
                                    minusResult = Number(valStr);
                                } else {
                                    minusResult -= Number(valStr);
                                }


                                if (valStr.indexOf(".") != -1) {
                                    var tempCount = valStr.split(".")[1].length;
                                    if (tempCount > fixedCount) {
                                        fixedCount = tempCount;
                                    }
                                }
                            }
                        })
                        resultStr = minusResult.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
                        break;
                    case "multiply":
                        var product = 0;
                        $("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
                            var valStr = $.trim($(this).val());
                            if (valStr != "" && !isNaN(Number(valStr))) {
                                if (i == 0) {
                                    product = Number(valStr);
                                } else {
                                    product *= Number(valStr);
                                }
                            }
                        })
                        resultStr = product.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
                        break;
                    case "divide":
                        var divideResult = 0;
                        $("input[data-calculate-to-variable='" + calculateTo + "']").each(function (i) {
                            var valStr = $.trim($(this).val());
                            if (valStr != "" && !isNaN(Number(valStr))) {
                                if (i == 0) {
                                    divideResult = Number(valStr);
                                } else if (Number(valStr) != 0) {
                                    divideResult /= Number(valStr);
                                }
                            }
                        })
                        resultStr = divideResult.toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
                        break;
                    case "toUpper":
                        var toUpperStr = JCPublicUtil.NumberFormat.numberToChinese($(currentObj).val());
                        if (toUpperStr != "error") {
                            resultStr = toUpperStr;
                        }
                        break;
                    case "average":
                        var sum = 0;
                        var num = 0;
                        $("input[data-calculate-to-variable='" + calculateTo + "']").each(function () {
                            var valStr = $.trim($(this).val());
                            if (valStr != "" && !isNaN(Number(valStr))) {
                                sum += Number(valStr);
                                num++;
                            }
                        })
                        if (num != 0) {
                            resultStr = (sum / num).toFixed(JCPublicUtil.FlowFormTemplate.fiexNum);
                        }
                        break;
                }


                var resultInput = $('input[name="' + prefix + calculateTo + suffix + '"]')
                resultInput.val(resultStr);
                //如果计算结果的输入框也有计算要求则计算
                if (resultInput.attr("data-calculate-to-variable") != undefined) {
                    JCPublicUtil.FlowFormTemplate.calculateOperate(resultInput[0]);
                }
            }
        },


        //验证表单
        validateForm: function () {
            var result = true;
            $("input[regexstr]").not("[disabled]").not("[readonly]").each(function () {
                var regStr = $(this).attr("regexstr");
                if (regStr == "") { return true; }
                var regex = new RegExp(regStr);
                var valueStr = $(this).val();
                //去掉逗号后是数字的,则获取去掉逗号后的值来验证
                var tempValue = valueStr.replace(/,/g, "");
                if (JCPublicUtil.NumberFormat.testNumber(tempValue) == true) {
                    valueStr = tempValue;
                }
                if (!regex.test(valueStr)) {
                    $(this).attr("style", "border:solid 1px red;");
                    result = false;
                    $(this).focus();
                } else {
                    $(this).removeAttr("style");
                }
            });
            return result;
        }


    },


    //数字格式化
    NumberFormat: {
        //以某个分隔符分开
        splitMarkFormat: function (numberStr, fixedNumber, markStr) {
            if (isNaN(Number(numberStr))) {
                return "";
            }
            fixedNumber = fixedNumber > 0 && fixedNumber <= 20 ? fixedNumber : 2;
            numberStr = parseFloat((numberStr + "").replace(/[^\d\.-]/g, "")).toFixed(fixedNumber) + "";
            var l = numberStr.split(".")[0].split("").reverse(),
            r = numberStr.split(".")[1];
            t = "";
            for (i = 0; i < l.length; i++) {
                t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? markStr : "");
            }
            return t.split("").reverse().join("") + "." + r;
        },




        //移除分割符号
        removeSplitMark: function (str) {
            return str.replace(/[^\d\.-]/g, "");
        },


        //数字转中文大写
        numberToChinese: function (n) {
            if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
                return "error";
            var unit = "仟佰拾亿仟佰拾万仟佰拾圆角分", str = "";
            n += "00";
            var p = n.indexOf('.');
            if (p >= 0)
                n = n.substring(0, p) + n.substr(p + 1, 2);
            unit = unit.substr(unit.length - n.length);
            for (var i = 0; i < n.length; i++)
                str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
            str = str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(
    /零(万|亿|圆)/g, "$1").replace(/(亿)万|(壹拾)/g, "$1$2").replace(
    /^圆零?|零分/g, "").replace(/圆$/g, "圆整");
            return str;
        },


        //验证是否是数字或浮点型数字
        testNumber: function (numberStr) {
            if (/^-?(0|[1-9]\d*)(\.\d+)?$/.test(numberStr)) {
                return true;
            } else {
                return false;
            }
        },
        
        //保留几位有效数字
        toFixed:function(numStr,fixnum){
        if (!isNaN(Number(numberStr))) {
        if(numStr.indexOf(".")!=-1){
        var numStrSplitArray=numStr.split(".");
        if(numStrSplitArray[1].length>fixnum){
        return numStrSplitArray[0]+"."+numStrSplitArray[1].substr(0,fixnum);
        }
        }
        }
        return numStr;
        }


    },


    //地址相关类  http://localhost:8080/JC/
    Location: {
        getRootPath: function () {
            var strFullPath = window.document.location.href;
            var strPath = window.document.location.pathname;
            var pos = strFullPath.indexOf(strPath);
            var prePath = strFullPath.substring(0, pos);
            var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
            return (prePath + postPath);
        }
    },
    
    //触摸屏的的相关事件
    touchScreen:{
    //鼠标滚动界面
    mouseScroll:function(){
    var x=0,y=0,isDown=false,top=0,left=0;//记录鼠标点击的坐标
    $(document).mousedown(function(e){
      x=e.clientX;
      y=e.clientY;  
      top=$(document).scrollTop();
      left=$(document).scrollLeft();
      isDown=true;
    }).mousemove(function(e){
       if(isDown){
        var offsetX=e.clientX-x;
         var offsetY=e.clientY-y;
         $(document).scrollTop(top+offsetY*-1);
         $(document).scrollLeft(left+offsetX*-1);
       }
    }).mouseup(function(){
          isDown=false;
      })
      
      
      //禁止选中文字
      $("body").css({"-moz-user-select":"none","-webkit-user-select":"none","user-select":"none"});
      $("html").css({"overflow":"hidden"});
      //禁止出现滚动条
      $("body").attr("scroll","no");
      //禁用右键
      $(document).bind("contextmenu",function(e){return false;}).bind("selectstart",function(e){return false;});  
      }
    },
   
     Ajax:function(url,method,data,successFunc,errorFunc,timeout,cache,datatype){
    $.ajax({
     type: method,
     url: url,
     data: data,
     timeout:timeout,
     cache:cache,
     dataType:datatype,
     success: successFunc,
     error:errorFunc
    });
    }
};


//初始化操作
PublicUtil.initModuleFunc();



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值