1.0.4 • Published 3 years ago

csw-js v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

csw-js

序列

  1.日期对象--time  
  2.文件方法--file   
  3.前端分页--paging    
  4.防抖与节流--debthe     
  5.正则验证--reg       
  6.拷贝--copy      
  7.cookie存储--cookie      
  8.其他方法--fun    

安装

  npm install csw-js

引入

  1. 局部组件引入:
  import cswJs from "csw-js"
  1. 全局引入:
  // main.js中引入  
  import cswJs from "csw-js"  
  // 挂载到vue原型上  
  Vue.prototype.$cswJs = cswJs;

使用说明

  1. time对象
  ## 获取当前日期时间  
    # time.getTime(type)  
      参数默认:yyyy-MM-dd hh:mm:ss  
      可选:  
      yyyy-MM-dd  
      hh:mm:ss  
      
  ## 分秒格式转时分秒  
    # time.minSsToHourMinSs(mimss)    
      参数格式:min:ss  
      
  ## 时间戳转日期  
    # time.toDate(timeStamp, type)    
      timeStamp   时间戳    
      type        返回时间格式  默认:yyyy-MM-dd hh:mm:ss  
      type可选:   
      yyyy-MM-dd hh:mm    
      yyyy-MM-dd    
      
  ## 日期转时间戳 -- 默认当前时间,时间戳为10位  
    # time.toStamp(date, length)    
      date  时间,默认当前时间  
      type  时间戳长度,默认10位    
      
  ## 获取开始年与结束年之间的年份     
    # time.getYearArr(startYear, endYear)    
      startYear 开始年份 参数为空时为当前年份前3年      
      endYear 结束年份 参数为空时为当前年份      
      
  ## 对比日期大小     
    # time.contrastDate(date1, date2)    
      参数格式:    
        yyyy-MM-dd hh:mm:ss    
        yyyy-MM-dd    
        yyyy/MM/dd hh:mm:ss    
        yyyy/MM/dd    
        返回结果如为true,则是 开始日期 > 结束日期    
        为false则是 开始日期 <= 结束日期    
  1. file对象
  ## img转Blob对象  
    # file.imageToBlob(url, fn)    
      url   图片路径    
      fn    返回一个回调函数,参数是Blob对象    

  ## 转File对象    
    # file.imageToFile(bits, name, type)    
      bits        img/Blob/base64 格式图片    
      name        文件名    
      type(可选)  表示将要放到文件中的内容的 MIME 类型。默认值为 "", 示例  "text/plain"    
      参考:https://developer.mozilla.org/zh-CN/docs/Web/API/File/File      
      
  ## File对象转base64     
    # file.fileToBase64(file)    
      file   File对象    
      示例:    
      async upload(Files) {    
        let res = await file.fileToBase64(Files)    
        if(res.code == 200) {    
          // 成功    
        } else if(res.code == 100) {    
          // 失败    
          console.log(res.msg)     
        }    
      }       
  
  1. 前端分页--paging
  # paging(list, page, page_size)    
    list       默认的一维数组(也就是后台没做分页的数组)    
    page       页码,默认第一页    
    page_size  每页显示条数,默认10条    
    该方法返回一个对象:    
    {    
      list:当前页列表    
      total:总条数    
      totalPage:总页数    
      page:当前页码    
    } 
  1. 防抖与节流--debthe
  ## 防抖    
    # debthe.debounce(fn, delay)   
      fn     函数    
      delay  延迟时间,默认500    
      示例:  
      fnName: fun.debounce(function(res){    
        // 逻辑代码,可传递一个参数      
      })    
    
  ## 节流    
    # debthe.throole(fn, delay)   
      fn     函数    
      delay  延迟时间,默认500    
      示例:     
      fnName: fun.throole(function(res){    
        // 逻辑代码,可传递一个参数      
      })    
  1. 正则验证--reg
  ----------------------验证方法序列----------------------    
  ## 邮箱验证    
    # reg.Email(value, noValueMsg, errValueMsg)      

  ## 手机号验证    
    # reg.Phone(value, noValueMsg, errValueMsg)        

  ## 身份证号码验证    
    # reg.IdCard(value, noValueMsg, errValueMsg)        

  ## 只能包含数字、字母以及下划线    
    # reg.Common(value, noValueMsg, errValueMsg)      

  ## QQ验证    
    # reg.QQ(value, noValueMsg, errValueMsg)           

  ## 金额验证    
    # reg.Money(value, noValueMsg, errValueMsg)    

  ## 统一社会信用代码验证
    # reg.Creditcode(value, noValueMsg, errValueMsg)
     

  ----------------------参数/验证示例----------------------    
   
  ## 参数  
    value        需要验证的字符    
    noValueMsg   空值的提示,可传    
    errValueMsg  验证错误的提示,可传              
      
  ## 验证示例:   
    # 所有验证语法都相同     
    let Email = reg.Email('12345@qq.com', '邮箱不能为空', '邮箱格式错误')   
    if(Email === true){    
      console.log('验证通过')    
    } else {    
      // 传值为空/验证失败,返回提示文字     
      console.log(Email)     
    }       
    
  1. 拷贝--copy
  ## 深拷贝    
    # copy.deep(target)        
      target   需要拷贝的目标对象        
      
  ## 浅拷贝    
    # copy.shallow(target)            
      target   需要拷贝的目标对象     
  
  ## 复制文本    
    # copy.text(content, callback)    
      content   复制的内容    
      callback  回调函数,判断结果,code为200,成功,code为100,失败    
      示例:    
      copy.text('这是复制的内容', function(res){    
        if(res.code == 200){    
          // 复制成功  默认提示 -- 复制成功    
        } else {    
          // 复制失败  默认提示 -- 当前浏览器不支持,请更换浏览器后重试    
        }    
      })     
  1. cookie存储--cookie
  ## 设置cookie    
    # cookie.set("name", "value", {path:'/', expires: 1639612800000})         
      第三个对象,path基本不管,expires传入过期日期时间戳就可以了    
      
  ## 获取cookie    
    # cookie.get("name")       
    
  ## 删除cookie    
    # cookie.remove("name")     
  1. 其他方法--fun
  ## 获取浏览器url参数对象        
    # fun.getUrlParams()           

更新日志

  ## 1.0.0
     方法已全部封装完毕。    

  ## 1.0.1   
     深拷贝/浅拷贝方法与复制文本合并,都列入copy对象。    
     深拷贝:copy.deep(target)     
     浅拷贝:copy.shallow(target)      
     复制文本:copy.text(content, callback)    

  ## 1.0.2
     file对象新增File对象转base64方法:file.fileToBase64(file)

  ## 1.0.21
     优化

  ## 1.0.3
     reg对象新增统一社会信用代码验证
     reg.Creditcode(value, noValueMsg, errValueMsg)

博客地址

一首弦曲献仙音

1.0.4

3 years ago

1.0.3

3 years ago

1.0.21

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.0

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago