• 收藏一些常用的methods


    获取url 参数值
    getQueryString: function (name) {   let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");   let r = window.location.search.substr(1).match(reg);   if (r != null) return unescape(r[2]);     return null; },
     
    深度拷贝  
    copyDeep: function (obj) { let copy; if (typeof obj === 'object') { copy = aa(obj); } function aa(oo) { try { let c; if (!isNaN(oo.length)) { c = []; for (let i in oo) { let o = oo[i]; if (typeof o === 'object') c.push(aa(o)); else c.push(o); } } else { c = {}; for (let i in oo) { c[i] = oo[i]; } } return c; } catch (e) { return null; } } return copy; },
    全局提示框  
    myTips: function myTips(type, data) { let fullDom = approach.fullscreenElement(); if (!document.getElementById('warning')) { if(!fullDom) { $('body').append('<div id="warning"></div>'); } else if(fullDom && fullDom.id === 'vsAgainst') { $('#vsAgainst').append('<div id="warning"></div>'); } } let tip = ""; switch (type) { case "success": tip = $("<div class='successBox clearfix showBox'><p>" + data + "</p></div>"); break; case "warning": tip = $("<div class='warningBox clearfix showBox'><p>" + data + "</p></div>"); break; } $("#warning").append(tip); setTimeout(function () { tip.remove(); }, 4000); },
    分页查询
    pageSet: function (wholePage, page) { if (wholePage == 1) { return ""; } else if (wholePage <= 9) { var pages = ""; for (var i = 1; i <= wholePage; i++) { if (i == page) { pages += "<a data-page='" + i + "' class='now'>" + i + "</a>"; } else { pages += "<a data-page='" + i + "'>" + i + "</a>"; } } return "<a class='f' data-page='" + (page == 1 ? 1 : page - 1) + "'></a>" + pages + "<a class='l' data-page='" + (page == wholePage ? wholePage : page + 1) + "'></a>"; } else { var pages1 = "", pages2 = ""; if (page <= 3) { for (var i = 1; i < 5; i++) { if (i == page) { pages1 += "<a data-page='" + i + "' class='now'>" + i + "</a>"; } else { pages1 += "<a data-page='" + i + "'>" + i + "</a>"; } } for (var i = wholePage - 3; i <= wholePage; i++) { pages2 += "<a data-page='" + i + "'>" + i + "</a>"; } return "<a class='f' data-page='" + (page == 1 ? 1 : page - 1) + "'></a>" + pages1 + "<span>...</span>" + pages2 + "<a class='l' data-page='" + (page == wholePage ? wholePage : page + 1) + "'></a>" } else if (page > 3 && page < wholePage - 5) { for (var i = page - 1; i <= page + 1; i++) { if (i == page) { pages1 += "<a data-page='" + i + "' class='now'>" + i + "</a>"; } else { pages1 += "<a data-page='" + i + "'>" + i + "</a>"; } } for (var i = wholePage - 2; i <= wholePage; i++) { pages2 += "<a data-page='" + i + "'>" + i + "</a>"; } return "<a class='f' data-page='" + (page == 1 ? 1 : page - 1) + "'></a><a data-page='1'>1</a><span>...</span>" + pages1 + "<span>...</span>" + pages2 + "<a class='l' data-page='" + (page == wholePage ? wholePage : page + 1) + "'></a>" } else { for (var i = wholePage - 6; i <= wholePage; i++) { if (i == page) { pages2 += "<a data-page='" + i + "' class='now'>" + i + "</a>"; } else { pages2 += "<a data-page='" + i + "'>" + i + "</a>"; } } return "<a class='f' data-page='" + (page == 1 ? 1 : page - 1) + "'></a><a data-page='1'>1</a><span>...</span>" + pages2 + "<a class='l' data-page='" + (page == wholePage ? wholePage : page + 1) + "'></a>" } } },
    //判断空对象
      isEmptyObject: function (e) {
        let t;
        for (t in e)
          return !1;
        return !0
      },
        //url转为base64编码
          convertImgToBase64: function (url, callback, outputFormat) {
            url+='?random='+Math.random();
            let canvas = document.createElement("CANVAS"),
              ctx = canvas.getContext("2d"),
              img = new Image();
            img.crossOrigin = "";
            // img.setAttribute("crossOrigin", "anonymous");
            img.onload = function () {
              canvas.height = img.height;
              canvas.width = img.width;
              ctx.drawImage(img, 0, 0);
              var dataURL = canvas.toDataURL(outputFormat || "image/png");
              callback.call(this, dataURL);
              canvas = null;
            };
            img.src = url;
          },
    

      

         //将base64编码转换为Blob
          convertBase64UrlToBlob: function (urlData) {
            let bytes = window.atob(urlData.split(",")[1]); //去掉url的头,并转换为byte
            //处理异常,将ascii码小于0的转换为大于0
            let ab = new ArrayBuffer(bytes.length);
            let ia = new Uint8Array(ab);
            for (let i = 0; i < bytes.length; i++) {
              ia[i] = bytes.charCodeAt(i);
            }
            return new Blob([ab], {type: "image/jpeg", filename: "upload.jpg"});
          },
    

      

  • 相关阅读:
    一些问题
    为什么Python在列表,元组和字典的末尾允许使用逗号?
    #!/bin/bash
    gitbook 入门教程之小白都能看懂的 Gitbook 插件开发全流程
    go 学习笔记之10 分钟简要理解 go 语言闭包技术
    gitbook 入门教程之还在搞公众号互推涨粉?gitbook 集成导流工具,轻轻松松躺增粉丝!
    go 学习笔记之仅仅需要一个示例就能讲清楚什么闭包
    go 学习笔记之学习函数式编程前不要忘了函数基础
    go 学习笔记之无心插柳柳成荫的接口和无为而治的空接口
    go 学习笔记之万万没想到宠物店竟然催生出面向接口编程?
  • 原文地址:https://www.cnblogs.com/lisiyang/p/8127422.html
Copyright © 2020-2023  润新知