/**
* @description 用于获取当前日期以及一个月前的日期yyyy-mm-dd格式
*/exportconstonemonth_to_now=()=>{var today =''// 今天var one_month =''// 30天前var res =[]var d =newDate()var m = d.getMonth()var date = d.getDate()var m_text =''var date_text =''if(m===0){if(date <10){
date_text ='-0'+ date
}else{
date_text ='-'+ date
}
one_month =(d.getFullYear()-1)+'-12'+ date_text
}else{if(m <10){
m_text ='-0'+ m
}else{
m_text ='-'+ m
}if(date <10){
date_text ='-0'+ date
}else{
date_text ='-'+ date
}
one_month = d.getFullYear()+ m_text + date_text
}
m = d.getMonth()+1if(m <10){
m_text ='-0'+ m
}else{
m_text ='-'+ m
}
today = d.getFullYear()+ m_text + date_text
res.push(today)
res.push(one_month)return res
}
1.7 时间格式化
/**
* Parse the time to string
* @param {(Object|string|number)} time
* @param {string} cFormat
* @returns {string}
*/exportfunctionparseTime(time, cFormat){if(arguments.length ===0){returnnull}const format = cFormat ||'{y}-{m}-{d} {h}:{i}:{s}'let date
if(typeof time ==='object'){
date = time
}else{if((typeof time ==='string')&&(/^[0-9]+$/.test(time))){
time =parseInt(time)}if((typeof time ==='number')&&(time.toString().length ===10)){
time = time *1000}
date =newDate(time)}const formatObj ={
y: date.getFullYear(),
m: date.getMonth()+1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()}const timeStr = format.replace(/{(y|m|d|h|i|s|a)+}/g,(result, key)=>{let value = formatObj[key]// Note: getDay() returns 0 on Sundayif(key ==='a'){return['日','一','二','三','四','五','六'][value]}if(result.length >0&& value <10){
value ='0'+ value
}return value ||0})return timeStr
}
1.8 截止到本月所有月份时间
用于获取截止到本月所有月份的 中国标准时间格式数组 和 yyyy-mm-dd格式数组
/**
* @description 用于获取截止到本月所有月份的中国标准时间格式数组和yyyy-mm-dd格式数组
*/exportconstmonths_to_now=()=>{var arr_s =[]// 中国标准时间格式数组var arr_n =[]// yyyy-mm-dd格式数组var d =newDate()var datetime =''var s_datetime
var m = d.getMonth()+1for(let i = m; i >0; i--){if(i <10){
datetime = d.getFullYear()+'-0'+ i +'-01'}else{
datetime = d.getFullYear()+'-'+ i +'-01'}
s_datetime =newDate(datetime +' ')
arr_s.push(s_datetime)
arr_n.push(datetime)}return{ arr_s: arr_s, arr_n: arr_n }}
exportfunctionadd(a, b){let c
let d
let e
try{
c = a.toString().split('.')[1].length
}catch(f){
c =0}try{
d = b.toString().split('.')[1].length
}catch(f){
d =0}// eslint-disable-next-linereturn(e = Math.pow(10, Math.max(c, d)),(mul(a, e)+mul(b, e))/ e)}
2.2 减
减法运算
exportfunctionsub(a, b){let c
let d
let e
try{
c = a.toString().split('.')[1].length
}catch(f){
c =0}try{
d = b.toString().split('.')[1].length
}catch(f){
d =0}// eslint-disable-next-linereturn(e = Math.pow(10, Math.max(c, d)),(mul(a, e)-mul(b, e))/ e)}
2.3 乘
乘法运算
exportfunctionmul(a, b){let c =0const d = a.toString()const e = b.toString()try{
c += d.split('.')[1].length
}catch(f){}try{
c += e.split('.')[1].length
}catch(f){}// eslint-disable-next-linereturnNumber(d.replace('.',''))*Number(e.replace('.',''))/ Math.pow(10, c)}
2.4 除
除法运算
exportfunctiondiv(a, b){let c
let d
let e =0let f =0try{
e = a.toString().split('.')[1].length
}catch(g){}try{
f = b.toString().split('.')[1].length
}catch(g){}// eslint-disable-next-linereturn(c =Number(a.toString().replace('.','')), d =Number(b.toString().replace('.','')),mul(c / d, Math.pow(10, f - e)))}
3、通用类
3.1 深度拷贝
/**
* 深度拷贝
* @param {any} data
*/exportfunctiondeepCopy(data){const t =isArray(data)?'array':typeof data
let o
if(t ==='array'){
o =[]}elseif(t ==='object'){
o ={}}else{return data
}if(t ==='array'){for(let i =0; i < data.length; i++){
o.push(deepCopy(data[i]))}}elseif(t ==='object'){for(const i in data){
o[i]=deepCopy(data[i])}}return o
}
/**
* @param {Array} init_range 需要处理的数据
* @description addcondition中c-ntn待提交数据处理
*/exportfunctionc_commit_range_handle(init_range){const res_range ={
min:null,
max:''}const{ min, max }= init_range
if(typeof min ==='object'&&typeof max ==='object'){
res_range.min ='不限'
res_range.max ='不限'}elseif(typeof min !=='object'&&typeof max ==='object'){
res_range.min = min.toString()
res_range.max ='不限'}elseif(typeof min ==='object'&&typeof max !=='object'){
res_range.min ='0'
res_range.max ='不限'}else{
res_range.min = min.toString()
res_range.max = max.toString()}return res_range
}
4.5 ntn组件抛出数据处理
/**
* @param {Array} data 抛到父组件的数据数组
* @description ntn组件抛出数据处理
*/exportfunctionntnData_handle(data){var res ={
content:'',
range:{
min:'',
max:''}}var content =''var left = data[0].toString()var right = data[1].toString()if(left === right && left !==''){// = num
content ='='+ left
}elseif(left ===''&& right ===''){// 不限
left ='不限'
right ='不限'
content ='不限'}elseif(left ===''&& right !==''){// [0, num)
left ='0'
content ='['+ left +','+ right +')'}elseif(left !==''&& right ===''){// [num, 不限)
right ='不限'
content ='['+ left +','+ right +')'}else{// [left, right)
content ='['+ left +','+ right +')'}
res.content = content
res.range.min = left
res.range.max = right
return res
}
4.5 c-ntn组件抛出数据处理
/**
* @param {Array} data 抛到父组件的数据数组
* @description c-ntn组件抛出数据处理
*/exportfunctioncntnData_handle(data){var res ={
content:'',
range:{
min:'',
max:''}}var content =''var left = data[0]===null?null: data[0].toString()var right = data[1]===null?null: data[1].toString()if(left === right && left !==null){// = num
content ='='+ left
}elseif(left ===null&& right ===null){// 不限
left ='不限'
right ='不限'
content ='不限'}elseif(left ===null&& right !==null){// [0, num)
left ='0'
content ='['+ left +','+ right +')'}elseif(left !==null&& right ===null){// [num, 不限)
right ='不限'
content ='['+ left +','+ right +')'}else{// [left, right)
content ='['+ left +','+ right +')'}
res.content = content
res.range.min = left
res.range.max = right
return res
}