landui.js 33.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
window.LD = window.LD || {};
LD.util = (function () {
  var empty = function (val) {
    if (val === null || val === undefined || val === '') {
      return true;
    }
    return false;
  };
  var intval = function(value,defaultValue){
    var value = parseInt(value);
    if(isNaN(value)) value = defaultValue;
    return value;
  };
  var floatval = function(value,defaultValue){
    var value = parseFloat(value);
    if(isNaN(value)) value = defaultValue;
    return value;
  };
  //设置COOKIE
  var setCookie = function(name,value,expires,path)
  {
    path = LD.util.empty(path) ? "/" : path;
    expires = parseInt(expires) * 1000;
    if(isNaN(expires))
    {
      document.cookie = name + "=" + escape(value) + "; path="+path;
    }else
    {
      var exp = new Date();
      exp.setTime(exp.getTime() + expires);
      document.cookie = name + "=" + escape(value) + "; path="+path+"; expires=" + exp.toUTCString();
    }
  };
  //获取COOKIE
  var getCookie = function (e) {
    var t = document.cookie;
    var a = t.split("; ");
    for (var n = 0; n < a.length; n++) {
      var r = a[n].split("=");
      if (r[0] == e) return unescape(r[1])
    }
    return ""
  };
  //删除COOKIE
  var delCookie = function(e)
  {
    var t = new Date;
    t.setTime(t.getTime() - 1);
    var a = LD.util.getCookie(e);
    if (a != null) document.cookie = e + "=" + a + "; path=/;expires=" + t.toGMTString()
  };
  //字符串数组转整型数组
  arrayConverInt = function(arr){
    var data = [];
    $.each(arr,function(k,v){
      data.push(parseInt(v));
    });
    return data;
  };
  return {
    empty: empty,
    intval:intval,
    floatval:floatval,
    getCookie : getCookie,
    setCookie:setCookie,
    delCookie:delCookie,
    arrayConverInt:arrayConverInt,
  }
})();

LD.time = (function(){
  //把时间转时间戳
  var strtotime = function(datetime){
    var tmp_datetime = datetime.replace(/:/g,'-');
    tmp_datetime = tmp_datetime.replace(/ /g,'-');
    var arr = tmp_datetime.split("-");
    var now = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4],arr[5]));
    return parseInt(now.getTime()/1000);
  };
  //格式化时间
  var format = function(date,fmt){
    var date = new Date(Date.parse(date.replace(/-/g,"/")));
    var o = {
      'M+': date.getMonth() + 1, //月份
      'd+': date.getDate(), //日
      'h+': date.getHours(), //小时
      'm+': date.getMinutes(), //分
      's+': date.getSeconds(), //秒
      'q+': Math.floor((date.getMonth() + 3) / 3), //季度
      'S': date.getMilliseconds() //毫秒
    };
    if(LD.util.empty(fmt)){
      fmt = 'yyyy-MM-dd hh:mm:ss';
    }
    if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    };
    for (var k in o) {
      if (new RegExp('(' + k + ')').test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
      }
    }
    return fmt;
  };
  //格式化new Date类型
  var formatDate = function(date,format){
    var o = {
      "M+" : date.getMonth()+1, //month
      "d+" : date.getDate(),    //day
      "HH+" : date.getHours(),   //hour
      "i+" : date.getMinutes(), //minute
      "s+" : date.getSeconds(), //second
      "q+" : Math.floor((date.getMonth()+3)/3),  //quarter
      "S" : date.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
      (date.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;
  }
  //获取当前时间戳
  var get = function(){
    return Math.round(new Date().getTime()/1000).toString();
  };
  //将时间戳转化为时间
  var date = function(date,format){
    var date = new Date(date*1000);//如果date为10位不需要乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1);
    var D = '-'+(date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() <10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() <10 ? '0' + date.getSeconds() : date.getSeconds());
    switch (format)
    {
      case 'yyyy-MM-dd':
        return Y+M+D;
      case 'yyyy-MM':
        return Y+M;
        break;
      case 'yyyy-MM-dd HH:mm:ss':
        return Y+M+D+' '+h+m+s;
        break;
    }
  };
  /**
   * 在new date类型上添加时间
   * @param interval  要添加的类型
   * @param number    要添加的数量
   * @param date      要添加的时间
   * @param formmat   要返回的格式
   * @returns {*}
   */
  var add = function(interval,number,date,formmat)
  {
    switch(interval)
    {
      case "y":{
        date.setFullYear(date.getFullYear()+number);
        return LD.time.formatDate(date,formmat);
      }
      case "q":{
        date.setMonth(date.getMonth()+number*3);
        return LD.time.formatDate(date,formmat);
      }
      case "m":{
        date.setMonth(date.getMonth()+number);
        return LD.time.formatDate(date,formmat);
      }
      case "w":{
        date.setDate(date.getDate()+number*7);
        return LD.time.formatDate(date,formmat);
      }
      case "d":{
        date.setDate(date.getDate()+number);
        return LD.time.formatDate(date,formmat);
      }
      case "h":{
        date.setHours(date.getHours()+number);
        return LD.time.formatDate(date,formmat);
      }
      case "i":{
        date.setMinutes(date.getMinutes()+number);
        return LD.time.formatDate(date,formmat);
      }
    }
  };
  return{get:get,strtotime:strtotime,format:format,formatDate:formatDate,date:date,add:add};
})();

LD.tip = (function () {
  //弹出带按纽的提示层
  var alert = function (msg, callback, options) {
    var ico = LD.util.empty(options) || LD.util.empty(options.ico) ? 0 : options.ico;
    var title = LD.util.empty(options) || LD.util.empty(options.title) ? "温馨提示" : options.title;
    callback = $.isFunction(callback) ? callback : "";
    layer.alert(msg, {icon: ico, title: title, area: ['auto', 'auto']}, callback);
  }

  //手机版弹出dialog
  var dialog = function(msg, callback){
    var str = '<div class="js_dialog"><div class="weui-mask"></div><div class="weui-dialog"><div class="weui-dialog__hd"><strong class="weui-dialog__title">温馨提示</strong></div><div class="weui-dialog__bd">'+msg+'</div><div class="weui-dialog__ft"><a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary dialog-btn">确定</a></div></div></div>';
    $('body').append(str);
    $('body').on('click','.dialog-btn',function(){
      $(this).parents('.js_dialog').remove();
      if($.isFunction(callback))
      {
        new callback();
        return;
      }
    })
  };
  //手机版上方弹出成功
  var toptipSuccess = function(msg,url){
    $('.weui_toptips').remove();
    var str = '<div class="weui-toptip toptip_success">'+msg+'</div>';
    $('body').append(str);
    setTimeout(function(){
      $('.weui-toptip').remove();
      if(!LD.util.empty(url))
      {
        window.location.href = url;
      }
    }, 2000);
  };
  //手机版上方弹出失败
  var toptipError = function(msg,url){
    $('.weui_toptips').remove();
    var str = '<div class="weui-toptip toptip_cancel">'+msg+'</div>';
    $('body').append(str);
    setTimeout(function(){
      $('.weui-toptip').remove();
      if(!LD.util.empty(url))
      {
        window.location.href = url;
      }
    }, 2000);
  };

  var loading = function(){
    layer.load(2);
  };
  var unloading = function(){
    closeAll();
  }
  //手机版弹出确定按纽和取消按纽
  var dialogConfirm = function(msg,okBtnText,okCallBack,cancelBtnText,cancelCallBack){
    $('.js_dialog').remove();
    var str = '<div class="js_dialog"><div class="weui-mask"></div><div class="weui-dialog"><div class="weui-dialog__hd"><strong class="weui-dialog__title">温馨提示</strong></div><div class="weui-dialog__bd">'+msg+'</div><div class="weui-dialog__ft"><a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default dialogConfirm-cancel-default">'+cancelBtnText+'</a><a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary dialogConfirm-default">'+okBtnText+'</a></div></div></div>';
    $('body').append(str);
    $('.dialogConfirm-default').click(function(){
      $(this).parents('.js_dialog').remove();
      if($.isFunction(okCallBack))
      {
        new okCallBack();
        return;
      }
    })
    $('body').on('click','.dialogConfirm-cancel-default',function(){
      $(this).parents('.js_dialog').remove();
      if($.isFunction(cancelCallBack))
      {
        new cancelCallBack();
        return;
      }
    });
  }

  //选择操作 传入操作数组
  var actionSheet=function (actionName,arr,callBack) {
    var str = '<div class="action" ><div class="weui-mask weui-actions_mask weui-mask--visible"></div><div class="weui-actionsheet"><div class="weui-actionsheet__title"><p class="weui-actionsheet__title-text">'+actionName+'</p></div><div class="weui-actionsheet__menu">';
    $.each(arr,function (k,v) {
      str+='<div class="weui-actionsheet__cell weui-actionsheet_li" data-key="'+k+'">'+v+'</div>';
    });
    str += '</div><div class="weui-actionsheet__action"><div class="weui-actionsheet__cell weui-actionsheet_cancel">取消</div></div></div></div>';
    $('body').append(str);
    $('.action').on('click','.weui-actionsheet_cancel',function(){
      $('body').find('.action').remove();
    });
    new callBack();
  };

  //弹出简单的提示框
  var msg = function (msg, callback, time) {
    time = LD.util.empty(time) ? 3000 : time;
    callback = $.isFunction(callback) ? callback : "";
    layer.msg(msg, {time: time}, callback);
  }
  var closeAll = function () {
    layer.closeAll();
  }
  //弹出错误警告
  var error = function (msg, callback) {
    alert(msg, callback, {title: '严重错误', ico: 2})
  }
  /**
   * 弹出带提示的对话框
   * @param msg       要提示的话语
   * @param callback  点击确定后的回调函数
   */
  var confirm = function (msg, callback) {
    layer.confirm(msg, {icon: 3, title: '请确认您的操作'}, callback)
  }
  /**
   * 点击弹出隐藏层
   */
  var open = function (options) {
    layer.open({content: options.content, area: options.area, anim: 2, shadeClose: true, title: options.title});
  }

  /**
   * 显示图片
   */
  var showImages = function (imgurl) {
    $('body').append('<img src="'+imgurl+'" id="showimg">');
    $('#showimg').load(function(){
      var width = $('#showimg').width();
      var height = $('#showimg').height();
      var wwidth = window.screen.width;
      var wheight = window.screen.height;
      if(width >= window.screen.width)
      {
        width = wwidth * 0.8;
        height = wheight * 0.8;
      }
      $('#showimg').remove();
      layer.open({
        type: 1,
        content: '<img src="'+imgurl+'">',
        title: false,
        closeBtn: 0,
        shadeClose: true,
        skin: 'layui-layer-nobg',
        area: [width + 'px', height+'px'],
      });
    });
  };
  /**
   * 显示视频
   */
  var showVideo = function (imgurl,videourl) {
    $('body').append('<img src="'+imgurl+'" id="showimg">');
    $('#showimg').load(function(){
      var width = $('#showimg').width();
      var height = $('#showimg').height();
      if(width > 1000) {
        var newWidth = 1000;
        var pl = width / newWidth
        var newHeight = LD.util.intval(height / pl);
        width = newWidth;
        height = newHeight;
      }
      $('#showimg').remove();
      layer.open({
        type: 1,
        content: '<video src="'+videourl+'" autoplay controls loop width="'+width+'" height="'+height+'">',
        title: false,
        closeBtn: 0,
        shadeClose: true,
        skin: 'layui-layer-nobg',
        area: [width + 'px', height+'px'],
      });
    });
  };

  /**
   * 图片点击放大
   */
  var clickImages = function () {
    $("body").on("click",".ld-showimages",function(){
      var imgurl = $(this).attr("src");
      layer.open({
        type: 1,
        content: '<img src="'+imgurl+'" width="300">',
        title: false,
        closeBtn: 0,
        shadeClose: true,
        skin: 'layui-layer-nobg',
      });
    });
  };

  //点击弹出框
  var ldIframe = function () {
    $(document).on('click', '.ld-iframe', function () {
      LD.tip.closeAll();
      var title = !$(this).attr('title') ? false : $(this).attr('title');
      var width = LD.util.empty($(this).data('width')) ? 'auto' : $(this).data('width');
      var height = LD.util.empty($(this).data('height')) ? 'auto' : $(this).data('height');
      var url = $(this).data('url');
      var offset = !$(this).data('offset') ? 'auto' : $(this).data('offset');
      parent.layer.open({type: 2,title: title,offset: offset,area: [width, height],shadeClose: true,anim: 1,content: url});
      return false;
    })
  };

  var contentShow = function(){
    $(document).on('click', '.content-show', function () {
      LD.tip.closeAll();
      var title = !$(this).data('title') ? false : $(this).data('title');
      var content = !$(this).data('content') ? false : $(this).data('content');
      var width = LD.util.empty($(this).data('width')) ? 'auto' : $(this).data('width');
      var height = LD.util.empty($(this).data('height')) ? 'auto' : $(this).data('height');
      if(!content)
      {
        LD.tip.msg("暂无备注信息");
        return false;
      }
      parent.layer.open({content: content, area: [width,height], anim: 2, shadeClose: true, title: title});
      return false;
    })
  };
  return {
    alert: alert,
    dialog: dialog,
    dialogConfirm: dialogConfirm,
    toptipSuccess: toptipSuccess,
    toptipError: toptipError,
    loading: loading,
    unloading: unloading,
    actionSheet:actionSheet,
    msg: msg,
    closeAll: closeAll,
    error: error,
    confirm: confirm,
    open: open,
    ldIframe: ldIframe,
    showImages: showImages,
    showVideo: showVideo,
    clickImages:clickImages,
    contentShow:contentShow
  }
})();


LD.ajax = (function () {
  /**
   * POST提交数据,解决IE缓存,并且处理默认的错误事件和服务器错误事件
   * @param url         要提交的地址
   * @param data        要提交的数据,json数据
   * @param callback    成功后的回调函数,可以为空
   * @param options     其它参数,目前支持beforeSend和btnObj按纽
   * @param errorCallback     错误回调
   */
  var post = function (url, data, callback, options,errorCallback) {
    var async = true;
    if(options && options.async===false) async = false;
    $.ajax({
      url: url, type: "post", cache: false, dataType: "json", data: data,
      async:async,
      beforeSend: function () {
        if (options && options.beforeSend) {
          new options.beforeSend();
        }
      },
      success: function (data) {
        if (options && options.iframe == true) {
          var windowObj = parent.window;
          var layerObj = parent.LD;
        } else {
          var windowObj = window;
          var layerObj = LD;
        }
        if(data.status == 'j')
        {
          windowObj.location.href = data.url;
          return;
        }
        if (data.status == 'y') {
          if ($.isFunction(callback)) {
            new callback(data);
            return;
          } else {
            var ifrmae = options && options.iframe == true ? true : false;
            if (LD.util.empty(data.info)) {
              windowObj.location.href = data.url;
            } else {
              layerObj.tip.alert(data.info, function () {
                layerObj.tip.closeAll();
                if (data.url == "") {
                  if(ifrmae)
                  {
                    var obj = $('.layadmin-iframe',parent.document);
                    obj.attr('src','?');
                  }else
                  {
                    windowObj.location.reload();
                  }
                } else {
                  if(ifrmae)
                  {
                    var obj = $('.layadmin-iframe',parent.document);
                    obj.attr('src',data.url);
                  }else
                  {
                    windowObj.location.href = data.url;
                  }
                }
              }, {title: '操作成功', ico: 1});
            }
          }
        } else if (data.status == 'n') {
          if ($.isFunction(errorCallback)) {
            new errorCallback(data);
            return;
          }else
          {
            LD.tip.closeAll();
            layerObj.tip.alert(data.info);
          }
        }else if (data.status == 'close') {
          LD.tip.closeAll();
        } else {
          switch (data.status)
          {
            case 'toptipError':
              LD.tip.toptipError(data.info,data.url);
              break;
            case 'toptipSuccess':
              LD.tip.toptipSuccess(data.info,data.url);
              break;
            case 'func':
              var func = eval(data.url);
              new func(data.info);
              break;
            case 'dialog':
              if(data.url==null)
              {
                LD.tip.dialog(data.info,data.url);
              }else
              {
                LD.tip.dialog(data.info,function(){
                  window.location.href = data.url;
                });
              }
              break;
            default:
              LD.tip.msg(data.info);
              break;
          }
        }
        if (data.status != 'y') {
          if (options && options.btnObj) {
            __aformFail(options.btnObj);
          }
        }
      },
      error: function (data) {
        LD.tip.error("严重错误:服务器运行错误");
        if (options && options.btnObj) {
          __aformFail(options.btnObj);
        }
      },
      complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
        if(status=='timeout'){//超时,status还有success,error等值的情况
          LD.tip.error.alert("请求超时");
        }
      }
    });

    function __aformFail(btnObj) {
      btnObj.attr("disabled", false).removeClass('disabled').val('再次提交');
    }
  }
  var clickUrl = function () {
    $(document).on('click', '.ld-ajax-url', function () {
      var url = $(this).data('url');
      var content = $(this).data('content');
      var objtd = $(this).data('td');
      var that = $(this);
      var iframe = $(this).data('iframe');
      //如果没传提示框,则直接提交ajax
      if (LD.util.empty(content)) {
        LD.ajax.post(url,{},'',{
          beforeSend: function () {
            that.attr('disabled', true).addClass('disabled').val('正在提交');
          },iframe:iframe, btnObj: that});
      } else {
        content += "<br />您确定要继续吗?";
        parent.LD.tip.confirm(content, function () {
          parent.LD.tip.closeAll();
          LD.ajax.post(url,{},'',{
            beforeSend: function () {
              that.attr('disabled', true).addClass('disabled').val('正在提交');
            },iframe:iframe, btnObj: that});
        });
      }
    });
  }
  return {
    post: post,
    clickUrl: clickUrl,
  };
})();
//表单处理
LD.validater = (function () {
  /**
   * 表单验证初始化
   * @param option
   */
  var initValidate = function (options) {
    var settings = $.extend(true, {formObj: '.ld-form', btnObj: '.ld-btn', success: '',}, options);
    var $_formObj = $(settings.formObj);
    var $_btnObj = $(settings.btnObj);
    var iframe = $_formObj.data('iframe') ? true : false;
    var tipType = LD.util.intval($_formObj.data('tiptype'),0);
    var optionSuccess = settings.success;
    $_formObj.find("[data-regex]").each(function () {
      checkInput($(this),tipType);
    });
    $_btnObj.unbind().click(function () {
      var flag = true;
      var that = $(this);
      $_formObj.find("[data-regex]").each(function () {
        //如果最上级的div被隐藏了。代表不需要判断
        if ($(this).parents().is(':hidden') === false) {
          if ($(this).data('success') !== true) {
            $(this).trigger('change');
            if (!$(this).hasClass('Validform_success')) {
              flag = false;
            }
          }
        }
      });
      if (flag) {
        var callback = $_formObj.data('callback');
        if(callback)
        {
          var func = eval(callback);
          new func($_formObj.serialize());
          return false;
        }else
        {
          var url = $(this).data('actionurl') ? $(this).data('actionurl') : $_formObj.attr('action');
          LD.ajax.post(url, $_formObj.serialize(), '', {
            beforeSend: function () {
              that.attr('disabled', true).addClass('disabled').val('正在提交');
            },
            btnObj: that,
            iframe: iframe
          })
        }
      }
      return false;
    })
  };
  //某个表单正确的时候,可以调用此方法在旁边赋值
  var successMsg = function (obj, successMsg) {
    if (typeof(successMsg) == "undefined") successMsg = '';
    LD.validater.getNextObj(obj).html(successMsg + addStr).attr('class', '').addClass(successClass);
    obj.removeClass(errorClass).addClass(successClass)
  };
  //某个表单错误的时候,可以调用此方法在旁边赋值
  var errorMsg = function (obj, errorMsg) {
    if (typeof(errorMsg) == "undefined") errorMsg = '';
    LD.validater.getNextObj(obj).html(errorMsg + addStr).attr('class', '').addClass(errorClass);
    obj.removeClass(successClass).addClass(errorClass)
  };
  //表单触发和表单提交共用方法
  var checkInput = function (obj,tipType) {
    var regex = obj.data('regex');
    var tipStr = obj.attr('placeholder');  //要提示的值
    if (regex) {
      var nextObj = LD.validater.getNextObj(obj);
      obj.click(function () {
        if (obj.val().length == 0) {
          var tipmsg = obj.data('nullmsg');
          if (tipmsg) nextObj.html(tipmsg).addClass('validform-tip');
        }
      });
      if (regex != 'custom') {
        obj.bind('input propertychange change', function () {
          var value = obj.val(), className = '';
          if (LD.regex.fromRegex(regex, value)) {
            obj.addClass('Validform_success').removeClass('Validform_error');
            nextObj.html('').removeClass('Validform_wrong').addClass('Validform_right');
          } else {
            var lderrormsg = obj.data('errormsg');
            if (lderrormsg) tipStr = lderrormsg;
            if (LD.util.empty(tipStr)) tipStr = '此项内容不能为空';  //如果还是未获取到错误的提示字符串
            obj.addClass('Validform_error');
            if(tipType==0)
            {
              nextObj.html(tipStr).addClass('Validform_wrong');
            }else
            {
              nextObj.addClass('Validform_wrong');
            }
          }
        });
        //如果为ajax请求
        if (obj.data('ajaxurl')) {
          var changeType = 'blur';
          if (obj.data('ajaxtype')) {
            changeType = obj.data('ajaxtype')
          }
          obj.bind(changeType, function () {
            var url = obj.data('ajaxurl');
            var ajaxCustom = $(this).data('ajaxcustom');
            LD.ajax.post(url,{'param': $(this).val()},function(data){
              if (ajaxCustom) {
                var func = eval(ajaxCustom);
                new func(data);
              } else {
                obj.removeClass('Validform_error').addClass('Validform_success');
                nextObj.html(data.info).removeClass('Validform_wrong Validform_loading').addClass('Validform_right');
              }
            },{
              beforeSend: function () {
                nextObj.html('正在检测信息...' ).removeClass('Validform_right').addClass('Validform_loading');
              }
            },function(data){
              obj.removeClass('Validform_success').addClass('Validform_error');
              nextObj.html(data.info).removeClass('Validform_right Validform_loading').addClass('Validform_wrong');
            });
          })
        }
        //ajax检测结束
      }
    }
  };
  var getNextObj = function (obj) {
    return obj.data('tipid') ? $('#' + obj.data('tipid')) : obj.parent().parent().find('div').last();
  }
  return {
    initValidate: initValidate,
    successMsg: successMsg,
    errorMsg: errorMsg,
    getNextObj: getNextObj,
  };
})();

LD.upload = (function () {
  var init = function () {
    //初始化所有图片的鼠标放上去显示删除和查看
    $('.upload-pic li img').each(function () {
      $(this).after(getDisplayDeleteStr());
    })
    imageMouse();
    //图片上传
    $('.ld-upload-thumb').each(function (k, v) {
      var size = !$(this).data('size') ? '2MB' : $(this).data('size');
      var filters = {
        mime_types: [ //只允许上传图片和zip文件
          {title: "图片文件", extensions: "jpg,png,gif,jpeg"},
        ],
        max_file_size: size, //最大只能上传400kb的文件
      };
      var formName = $(this).data('form-name');
      var multi_selection = $(this).data('type') == 'imageFig' ? true : false;
      var options = {
        id: $(this).attr('id'),
        filters: filters,
        url:$(this).data('url'),
        username:$(this).data('username'),
        time:$(this).data('time'),
        token:$(this).data('token'),
        multi_selection: multi_selection,
        successCallBack: function (obj, data) {
          var successObj = obj.parent().find('.upload-pic');
          successObj.find('.progress').remove();
          var str = getDisplayDeleteStr();
          if (multi_selection) {
            successObj.append('<li><img src="' + data.info + '"/><input type="hidden" name="post' + formName + '[]" value="' + data.info + '"/>' + str + '</li>');
          } else {
            successObj.html('<li><img src="' + data.info + '" width="92" height="92" /><input type="hidden" name="post' + formName + '[]" value="' + data.info + '"/>' + str + '</li>');
          }
        }
      }
      initUpload(options);
    });
    //文件上传
    $(".ld-upload-file").each(function (k, v) {
      //初始化显示
      var id = $(this).attr('id');
      var size = !$(this).attr('size') ? '500mb' : $(this).attr('size');
      var filters = {
        mime_types: [
          {title: "EXCEL文件", extensions: "xls,xlsx,mp4,mp3"},
        ],
        max_file_size: size, //最大只能上传400kb的文件
      };
      var multi_selection = false;
      var options = {
        id: id,
        size: size,
        filters: filters,
        url:$(this).data('url'),
        username:$(this).data('username'),
        time:$(this).data('time'),
        token:$(this).data('token'),
        multi_selection: multi_selection,
        successCallBack: function (obj, data) {
          var successObj = obj.parent().find('.upload-file');
          successObj.find('.progress').remove();
          successObj.html('<li style="line-height: 30px;margin: 0 0 10px;"><span class="file-route"><a href="' + data.info + '" target="_blank">' + data.name + '</a></span><span class="fa-del" style="color: #059fff;margin-left: 20px;cursor: pointer;">删除</span><input type="hidden" name="post[' + id + '][]" value="' + data.info + '|' + data.name + '" readonly></li>');
        },
      };
      initUpload(options);
    })
  }
  //图片时,鼠标放上去删除和查看的html代码
  var getDisplayDeleteStr = function () {
    var str = '<div class="file-panel"><i class="fa fa-trash-o" style="display: none;"></i><i class="fa fa-search-plus" style="display: none;"></i></div>';
    return str;
  };
  //鼠标滑过图片的事件
  var imageMouse = function () {
    $('.upload-pic').on('mouseenter', 'li', function () {
      $(this).find('.file-panel').css({height: 30}).find('i').show();
    });
    $('.upload-pic').on('mouseleave', 'li', function () {
      $(this).find('.file-panel').css({height: 0}).find('i').hide();
    });
    //删除图片
    $('.upload-pic').on('click', '.fa-trash-o', function () {
      var obj = $(this);
      LD.tip.confirm('您确定要删除此图片吗', function () {
        LD.tip.closeAll();
        obj.parents('li').remove();
      });
    });
    //删除文件
    $('.upload-file').on('click', '.fa-del', function () {
      var obj = $(this);
      LD.tip.confirm('您确定要删除此文件吗', function () {
        LD.tip.closeAll();
        obj.parents('li').remove();
      });
    });
    //查看图片
    $('.upload-pic').on('click', '.fa-search-plus', function () {
      var imgUrl = $(this).parents('li').find('img').attr('src');
      parent.LD.tip.showImages(imgUrl);
    })
  };
  //初始化上传组件
  //初始化上传组件
  var initUpload = function (options) {
    var browse_button = options.id;
    var size = options.size;
    var successCallBack = options.successCallBack;
    var url = options.url;
    var uploader = new plupload.Uploader({
      runtimes: 'html5,flash,silverlight,html4',
      browse_button: browse_button,
      url: url,
      file_data_name: 'file',
      multi_selection: options.multi_selection,
      flash_swf_url: "plugins/plupload/Moxie.swf"/*tpa=https://yl.hnla.cn/static/js/plugins/plupload/Moxie.swf*/,
      filters: options.filters,
      multipart_params: {
        'username': options.username,
        'time': options.time,
        'token': options.token,
      },
      init: {
        FilesAdded: function (up, file) {
          var obj = $(up.settings.browse_button[0]);
          obj.attr('disabled', true).val('正在上传');
          uploader.start();
        },
        UploadProgress: function (up, file) {  //进度条
          var percent = file.percent;
          var obj = $(up.settings.browse_button[0]);
          obj.parent().find('.layui-progress').show().html("<div class='layui-progress-bar' style='width: "+percent+"%;'><span class='layui-progress-text'>"+percent+"%</span></div>");
        },
        FileUploaded: function (up, b, data) {
          var obj = $(up.settings.browse_button[0]);
          obj.parent().find('.layui-progress').html('').hide();
          obj.attr('disabled', false).val('上传文件');
          var data = $.parseJSON(data.response);
          if (data.status == 'y') {
            data.name = b.name;
            new successCallBack(obj, data);
            return false;
          } else {
            LD.tip.alert(data.info);
          }
        },
        Error: function (up, err) {
          var obj = $(up.settings.browse_button[0]);
          obj.parent().find('.layui-progress').html('').hide();
          obj.attr('disabled', false).val('上传文件');
          if (err.code == -602) {
            LD.tip.alert('不能重复');
            return false;
          }
          if (err.message == 'File size error.') {
            LD.tip.alert('文件大小超出上限');
          } else {
            if (err.status !== 200) {
              LD.tip.error("上传服务器异常,请联系我们!");
            }
          }
        }
      }
    });
    uploader.init();
  };
  return {
    init: init,
  }
})();

LD.regex = {
  domain: function (str) {
    regexStr = '^[\u4e00-\u9fa5A-Za-z0-9\-]+$';
    return LD.regex.test(regexStr, str);
  },
  //判断数字(含小数)
  n: function (str) {
    regexStr = '^[0-9]+.?[0-9]*$';
    return LD.regex.test(regexStr, str);
  },
  //判断是否为整数
  d: function (str) {
    regexStr = '^-?\\d+$';
    return LD.regex.test(regexStr, str);
  },
  //判断是否为整数
  int: function (str) {
    regexStr = '^([1-9][0-9]*)$';
    return LD.regex.test(regexStr, str);
  },
  //判断是否为整数
  int0: function (str) {
    regexStr = '^([0]|[1-9][0-9]*)$';
    return LD.regex.test(regexStr, str);
  },
  //判断手机号
  mobile: function (str) {
    regexStr = '^0?(13|15|16|18|14|17|19)[0-9]{9}$';
    return LD.regex.test(regexStr, str);
  },
  //判断手机号
  email: function (str) {
    regexStr = '^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$';
    return LD.regex.test(regexStr, str);
  },
  //钱
  money: function (str) {
    regexStr = /^(([1-9]\d*)(\.\d{1,2})?)$|(0\.0?([1-9]\d?))$/;
    return LD.regex.test(regexStr, str);
  },
  //钱含0
  money0: function (str) {
    regexStr = /^(([0]|[1-9]\d*)(\.\d{1,2})?)$|(0\.0?([1-9]\d?))$/;
    return LD.regex.test(regexStr, str);
  },
  //图片
  thumb: function (str) {
    regexStr = /^(([1-9]\d*)(\.\d{1,2})?)$|(0\.0?([1-9]\d?))$/;
    return LD.regex.test(regexStr, str);
  },
  //时间
  datetime: function (str) {
    regexStr =  /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;
    return LD.regex.test(regexStr, str);
  },
  test: function (regexStr, value) {
    var patt1 = new RegExp(regexStr);
    return patt1.test(value);
  },
  fromRegex: function (regexStr, value) {
    switch (regexStr) {
      case 'd':
        return LD.regex.d(value);
        break;
      case 'int':
        return LD.regex.int(value);
        break;
      case 'int0':
        return LD.regex.int0(value);
        break;
      case 'mobile':
        return LD.regex.mobile(value);
        break;
      case 'email':
        return LD.regex.email(value);
        break;
      case '*':
        return !LD.util.empty(value);
        break;
      case 'thumb':
        return LD.regex.thumb(value);
        break;
      case 'money':
        return LD.regex.money(value);
        break;
      case 'money0':
        return LD.regex.money0(value);
        break;
      case 'datetime':
        return LD.regex.datetime(value);
        break;
    }
  }
};