12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /**
- * 地址栏参数
- */
- function parseQueryString(key) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- (window.location.href).replace(reg, ($0, $1, $2) => {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj[key];
- }
- /**
- * 数值格式化
- */
- function NumberHandle (value,numberDigit) {//数值小数点处理 ①5997;②8.1w;③2489kw;④4.2亿 且保留一位小数
- if(typeof parseFloat(value) === 'number' && !isNaN(value)){
- //判断是否是数值类型
- if((value >= 10000 && value < 10000000) || (value <= -10000 && value > -10000000)){
- return hasDot(value/10000,numberDigit) + 'w'
- }else if((value >= 10000000 && value < 100000000) || (value <= -10000000 && value > -100000000)){
- return hasDot(value/10000000,numberDigit) + 'kw'
- }else if(value >= 100000000 || value <= -100000000){
- return hasDot(value/100000000,numberDigit) + '亿'
- }else{
- return hasDot(value,numberDigit)
- }
- }else{
- return value
- }
- }
- function hasDot(num,numberDigit){
- //有小数点就保留一个小数,没有就直接返回 ,默认保留1位小数
- var num = parseFloat(num)
- var digit = 1;
- if(numberDigit){
- digit = numberDigit
- }
- return (num + '').indexOf('.') != -1 ? num.toFixed(digit) : num;
- }
- /**
- * 日期获取
- */
- function getDay (day,haveHours){
- //day为0表示今天的日期 -1为昨天 haveHours存在表示要时分秒 haveHours:true,false
- var today = new Date();
- var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
- today.setTime(targetday_milliseconds); //注意,这行是关键代码
- var tYear = today.getFullYear();
- var tMonth = today.getMonth();
- var tDate = today.getDate();
- var hours = today.getHours();
- var minutes = today.getMinutes(); //分
- var seconds = today.getSeconds(); //秒
- tMonth = doHandleMonth(tMonth + 1);
- tDate = doHandleMonth(tDate);
- if(haveHours){
- if(day == 0){
- return {
- 'now':tYear+"-"+tMonth+"-"+tDate+' ' + hours + ':' + minutes + ':' + seconds,
- 'zero':tYear+"-"+tMonth+"-"+tDate+' ' + '00:00:00'
- }
- }else{
- return tYear+"-"+tMonth+"-"+tDate+' ' + hours + ':' + minutes + ':' + seconds
- }
- }else{
- return tYear+"-"+tMonth+"-"+tDate
- }
- function doHandleMonth(month){
- var m = month;
- if(month.toString().length == 1){
- m = "0" + month;
- }
- return m;
- }
- }
- module.exports = {
- parseQueryString: parseQueryString,
- NumberHandle: NumberHandle,
- getDay: getDay
- }
|