first
This commit is contained in:
30
src/utils/common.js
Normal file
30
src/utils/common.js
Normal file
@ -0,0 +1,30 @@
|
||||
const formatDate = date => {
|
||||
let tempDate = new Date(date)
|
||||
const year = tempDate.getFullYear()
|
||||
const month = tempDate.getMonth() + 1
|
||||
const day = tempDate.getDate()
|
||||
return `${[year, month, day].map(formatNumber).join('-')}`
|
||||
}
|
||||
|
||||
const formatNumber = n => {
|
||||
n = n.toString()
|
||||
return n[1] ? n : `0${n}`
|
||||
}
|
||||
|
||||
const leftCopy = (obj, source) => {
|
||||
let sourceKey = Object.keys(source)
|
||||
if (obj && source) {
|
||||
Object.keys(obj).forEach(key => {
|
||||
if (sourceKey.includes(key)) {
|
||||
obj[key] = source[key] == null ? '' : source[key]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
formatNumber,
|
||||
formatDate,
|
||||
leftCopy,
|
||||
}
|
Reference in New Issue
Block a user