在手机调试时打印代码
<script src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script>
<script>
 var vConsole = new VConsole();
 console.log('VConsole is cool');
</script>
import * as date from "./date.js";
/**
* 函数防抖 (只执行最后一次点击)
* @param fn
* @param delay
* @returns {Function}
* @constructor
*/
export const Debounce = (fn, t) => {
let delay = t || 500;
let timer;
console.log(fn)
console.log(typeof fn)
return function () {
let args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
timer = null;
fn.apply(this, args);
}, delay);
}
};
/**
* 函数节流
* @param fn
* @param interval
* @returns {Function}
* @constructor
*/
export const Throttle = (fn, t) => {
let last;
let timer;
let interval = t || 500;
return function () {
let args = arguments;
let now = +new Date();
if (last && now - last < interval) {
clearTimeout(timer);
timer = setTimeout(() => {
last = now;
fn.apply(this, args);
}, interval);
} else {
last = now;
fn.apply(this, args);
}
}
};
/**
* 转换日期格式为2019年11月11日、2019年正月初一
* @param {*} name
* @param {*} value
* @param {*} expiredays
*/ export const getChangeDate = (info, type) => {
let birthInfoText = ''
// 日期互转
const lunar = date.solar2lunar(
parseInt(info.birthDayYear),
parseInt(info.birthDayMonth),
parseInt(info.birthDayDay),
);
console.log(info);
if (type == 2) {
birthInfoText = `农历 ${lunar.lYear||1985}年${lunar.IMonthCn||1}${lunar.IDayCn||1}`;
} else {
birthInfoText = `公历 ${info.birthDayYear||1985}年${info.birthDayMonth||1}月${info.birthDayDay||1}日`;
}
return birthInfoText
} // 存储cookie
export const SetCookie = (name, value, expiredays) => {
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
var cookieVal = name + "=" + encodeURI(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())+ ";path=/";
document.cookie = cookieVal;
} /*读取cookie*/
export const GetCookie = (sKey) => {
sKey = sKey.replace(/([\.\[\]\$])/g, '\\\$1');
var rep = new RegExp(sKey + '=([^;]*)?;', 'i');
var co = document.cookie + ';';
var res = co.match(rep);
if (res) {
return decodeURI(res[1]) || "";
} else {
return null;
}
}; /*删除cookie*/
export const DelCookie = (sKey) => {
SetCookie(sKey,"",-1)
} // 获取参数
export const getQueryString = (name) => {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return "";
}
// 键盘
export const hackScrollTop = (vnode, offsetVal) => {
let target = vnode;
let t = navigator.userAgent;
// 区分组件和DOM
target.offsetTop || (target = vnode.$el);
if (t.indexOf("Android") > -1 || t.indexOf("Adr") > -1) {
document.documentElement.scrollTop = document.body.scrollTop =
target.offsetTop + parseInt(offsetVal);
}
setTimeout(() => {
target.scrollIntoViewIfNeeded();
}, 400);
}
// 定位
export const stackScroll = (vnode, offsetVal) => {
let target = vnode;
let t = navigator.userAgent;
// 区分组件和DOM
target.offsetTop || (target = vnode.$el);
document.documentElement.scrollTop = document.body.scrollTop =
target.offsetTop + parseInt(offsetVal);
setTimeout(() => {
target.scrollIntoViewIfNeeded();
}, 400);
}
// 判断是否是数字
export const isRealNum = (val) => {
// isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
if (val === "" || val == null) {
return false;
}
if (!isNaN(val)) {
return true;
} else {
return false;
}
}
// 判断null NaN undefined
export const isHasValue = (val) => {
if(val){
if (!val) {
return false;
}else if(val=='undefined'||val=='null'||val==' '||val=='NaN'){
return false;
}else{
return true
}
}else{
return false
}
}
//获取QS
export default function (search) {
  const map = Object.create(null);
  if (search[0] === '?') {
    search = search.substring(1);
  }
  const substrs = search.split('&');
  const len = substrs.length;
  for (let index = 0, substr; index < len; index += 1) {
    substr = substrs[index].split('=');
    if (substr[0]) {
      map[substr[0]] = substr[1];
    }
  }
  return map;
};
 

更新常用的js工具函数的更多相关文章

  1. 封装一些常用的js工具函数-不定时更新(希望大家积极留言,反馈bug^_^)

    /*华丽------------------------------------------------------------------------------------------------ ...

  2. 常用的js工具函数

    JS选取DOM元素的方法注意:原生JS选取DOM元素比使用jQuery类库选取要快很多1.通过ID选取元素document.getElementById('myid');2.通过CLASS选取元素do ...

  3. js工具函数《转载收藏》

    1.等待所有图片加载 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 var imgObjs = [], count = 0; rotate.prize ...

  4. JS 工具函数 方法(其中js的crc32和php的crc32区别)

    var util = {}; util.indexOf = function (array, item) { for (var i = 0; i < array.length; i++) { i ...

  5. JS工具函数汇总

    备注:http://phpjs.org/  这个站点把PHP常用的方法用js实现了,推荐一下 1.从数组中随机获取几个不重复项 //从一个给定的数组arr中,随机返回num个不重复项 function ...

  6. (总结)工作中常用的js自定义函数——日期时间类

    //设置时间类 var Wsdatatime = function(){ this.today = (new Date()).getTime(); //当前时间 } Wsdatatime.protot ...

  7. JavaScript常用工具函数

    检测数据是不是除了symbol外的原始数据 function isStatic(value) { return ( typeof value === 'string' || typeof value ...

  8. 你要的几个JS实用工具函数(持续更新)

    今天,我们来总结下我们平常使用的工具函数,希望对大家有用.1.封装fetch 源码: /** * 封装fetch函数,用Promise做回调 * @type {{get: (function(*=)) ...

  9. 工作中常用的JS函数整理分享(欢迎大家补充)

    今年在渣X工作整理的常用JS函数 今年来了渣X工作,我所在这个部门分工很奇怪,CSS竟然有专门的人在搞,开发PHP的人员需要处理JS,以至于有时候开发起来不是那么得心应手,感觉把JS和CSS拆开就像是 ...

随机推荐

  1. Sprin Boot2.0之整合Mybatis整合分页插件

    pageHelper PageHelper 是一款好用的开源免费的 Mybatis 第三方物理分页插件 物理分页 支持常见的 12 种数据库.Oracle,MySql,MariaDB,SQLite,D ...

  2. matlab给图片插入说明文字

    text(cluster().center(),cluster().center(),num2str(),'color','k') 格式是text(x,y,'说明文字') x,y代表位置

  3. Linux下查看端口占用情况

    用启动服务的账号登录,然后运行命令: lsof -i:<端口号> 也可使用命令: netstat -apn|grep <端口号> 找到进程号以后,再使用以下命令查看详细信息: ...

  4. OpenCV——PS滤镜 漩涡 vertex

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  5. kettle每天自动发送邮件总结_20161128

    kettle作为java开发的工具,很多功能在目前工作中还用不到,原来它也是支持java代码的,现在用到的也就是它从服务器导数到数据库,然后再进行数据处理的功能. 如何快速学会使用kettle发送邮件 ...

  6. poj3709 K-Anonymous Sequence[贪心+斜率优化dp]

    地址 n个数,可进行把一个数减小的操作,代价为减小的值.现求使数列任意一个数都存在至少k-1个数和他相同,问操作的最小代价. 可以先考虑最小的数,由于只能减,所以必须得至少k-1个数减为最小数,贪心策 ...

  7. javacpp-FFmpeg系列补充:FFmpeg解决avformat_find_stream_info检索时间过长问题

    javacpp-ffmpeg系列: javacpp-FFmpeg系列之1:视频拉流解码成YUVJ420P,并保存为jpg图片 javacpp-FFmpeg系列之2:通用拉流解码器,支持视频拉流解码并转 ...

  8. bzoj 3714 [PA2014]Kuglarz——思路+最小生成树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3714 如果用s[ i ]表示前 i 个的奇偶性,那么c(i_j)表示s[ i-1 ]^s[ ...

  9. poj2299——逆序对

    题目:http://poj.org/problem?id=2299 逆序对,注意树状数组维护后缀和. 代码如下: #include<iostream> #include<cstdio ...

  10. Html5 canvas 元素

    canvas 元素用于在网页上绘制图形. 什么是 Canvas? HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像. 画布是一个矩形区域,您可以控制其每一像素. canv ...