工具记录

135 阅读1分钟

1.获取日期范围,可用于日历组件选则时间范围联动

   dayjs().format('YYYY-MM-DD')    // 或者    dayjs().startOf('day').format('YYYY-MM-DD')     // 获取本周,会有问题    dayjs().day('1').format('YYYY-MM-DD') // 周一    dayjs().day('7').format('YYYY-MM-DD') // 周日     // 获取本月    dayjs().startOf('month').format('YYYY-MM-DD') // 本月第一天    dayjs().endOf('month').format('YYYY-MM-DD') // 本月最后一天     // 获取本年    dayjs().startOf('year')..format('YYYY-MM-DD') // 今年第一天    dayjs().endOf('year')..format('YYYY-MM-DD') // 今年最后一天

2.时间戳转化为时分秒

   handleTime(time) {      const h = parseInt(time / 3600)      const minute = parseInt(time / 60 % 60)      const second = Math.ceil(time % 60)      const hours = h < 10 ? '0' + h : h      const formatSecond = second > 59 ? 59 : second      return [hours, minute, formatSecond]    }

3.金额的正则验证,保留两位小数

  penaltyAmount: [          {            pattern: /^(([1-9]{1}\d{0,9})|(0{1}))(\.\d{1,2})?$/,            message: "请输入合法的金额数字,最多两位小数",            trigger: "blur",          },        ],

4.处理删除最后一页无数据

 let deleteAfterPage = Math.ceil((this.total - 1) / 5)          let currentPage = this.currentPage > deleteAfterPage ? deleteAfterPage : this.currentPage          this.currentPage = currentPage < 1 ? 1 : currentPage            this.serchFn();

5.图片自适应

-object-fit

6.地图鼠标穿透

point-evetns

7.按比例缩放

width:1920px
height:1080px
transform:(1920/x,1080/y),//x为适配的分辨率的宽度,y为高度
trannsform-origin:top left
overflow:hidden

8.下载监听下载中的状态和下载完成时的状态

  //填写你的下载时加载的操作   const load=(ref)=>{    ref.$el.style='background-color:#E6A23C'  }  //下载完成后触发,用来关闭提示框const disLoad=(ref)=>{    ref.$el.style='background-color:#909399'  }  // 下载使用的方法    export const downloadClient=(url,ref)=> {    load(ref);    var xhr = new XMLHttpRequest();    xhr.open('get', url, true);    // 也可用POST方式    xhr.responseType = "blob";    xhr.onload = function () {      if (this.status === 200) {        var blob = this.response;        console.log(blob,'blob');        if (navigator.msSaveBlob == null) {          var a = document.createElement('a');          var headerName = xhr.getResponseHeader("Content-disposition");          a.download = decodeURIComponent(headerName).substring(20);          a.href = URL.createObjectURL(blob);          var body=document.getElementsByTagName('body')[0]        //   console.log(body,'body')          body.appendChild(a);    // 修复firefox中无法触发click          a.click();          URL.revokeObjectURL(a.href);          var aTag=document.getElementsByTagName('a')[0]          aTag.remove()        } else {          navigator.msSaveBlob(blob, decodeURIComponent(headerName).substring(20));        }      }      disLoad(ref);    };    xhr.send()  };

9.列表滚动播放插件,类似新闻列表竖向轮播

vue-seamless-scroll

9.cesium底图存在的情况下,更换纯色底图

map.viewer.imageryLayers.get(0).show = false;
//全局替换底色