//为空,返回trueexportconstisEmpty=(v)=>{switch(typeof v){case'undefined':returntrue;case'string':if(v.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,'').length ==0)returntrue;break;case'boolean':if(!v)returntrue;break;case'number':if(0=== v ||isNaN(v))returntrue;break;case'object':if(null=== v || v.length ===0)returntrue;for(var i in v){returnfalse;}returntrue;}returnfalse;}
2、获取当前时间
//获取当前时间(这个时间还需要处理)exportconstgetCurrentTimes=()=>{const date =newDate();const year = date.getFullYear();const month = date.getMonth()+1;const day = date.getDate();const hour = date.getHours();const minute = date.getMinutes();const second = date.getSeconds();return{detail:{year: year,month: month,day: day,hour:withData(hour),minute:withData(minute),second:withData(second)}}}//时分秒 不足补零varwithData=(num)=>{let param =parseInt(num);return param <10?'0'+ param :''+ param;}
3、将毫秒数转为年月日时分秒
export const convertMsToSeconds = (data) => {
var now = new Date(data);
//获取年份
var year = now.getFullYear();
//获取月份
var month = now.getMonth() + 1;
if (month < 10) {
month = "0" + month;
}
//获取日
var date = now.getDate();
if (date < 10) {
date = "0" + date;
}
//获取小时
var h = now.getHours() < 10 ? '0' + now.getHours() : now.getHours();
//获取分钟
var m = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
//获取秒
var s = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds();
return `${year}-${month}-${date} ${h}:${m}:${s}`
}
//npm install mathjsvar math =require("mathjs")// require()//小数相加精度失真exportconstnumAdd=(num1, num2)=>{let amount=math.add(math.bignumber(num1),math.bignumber(num2))let result = math.number(amount)return result
}//小数相减精度失真exportconstnumSub=(num1, num2)=>{let amount=math.subtract(math.bignumber(num1),math.bignumber(num2))let result = math.number(amount)return result
}//小数相乘精度失真exportconstnumMulti=(num1, num2)=>{let amount=math.multiply(math.bignumber(num1),math.bignumber(num2))let result = math.number(amount)return result
}//小数相除精度失真exportconstnumDiv=(num1, num2)=>{let amount=math.divide(math.bignumber(num1),math.bignumber(num2))let result = math.number(amount)return result
}
6、获取url上以&拼接的参数
exportconstgetQueryVariable=(variable)=>{var query = window.location.search.substring(1);var vars = query.split("&");for(var i =0; i < vars.length; i++){var pair = vars[i].split("=");if(pair[0]== variable){return pair[1];}}return(false);}