You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.4 KiB
62 lines
1.4 KiB
function formatePrice(price) {
|
|
return Number(parseFloat(price) / 100).toFixed(2)
|
|
}
|
|
|
|
function formateWeight(weight) {
|
|
return Number(parseFloat(weight) / 1000).toFixed(3)
|
|
}
|
|
|
|
function isEmpty(val) {
|
|
return typeof val === 'undefined' || val === '' || val === null
|
|
}
|
|
|
|
function formateDate(datetime) {
|
|
if (isEmpty(datetime)) {
|
|
return ''
|
|
}
|
|
var date = getDate(datetime.trim())
|
|
var today = getDate()
|
|
var dayCode = 24 * 60 * 60 * 1000
|
|
console.log((date.getTime() - today.getTime()) / dayCode)
|
|
var week = ''
|
|
if (date.getTime() === today.getTime()) {
|
|
week = '(今天)'
|
|
} else if (date.getTime() === today.getTime() + dayCode) {
|
|
week = '(明天)'
|
|
} else if (date.getTime() === today.getTime() - dayCode) {
|
|
week = '(昨天)'
|
|
} else if (date.getTime() === today.getTime() + dayCode * 2) {
|
|
week = '(后天)'
|
|
} else {
|
|
week = ['(周日)', '(周一)', '(周二)', '(周三)', '(周四)', '(周五)', '(周六)'][date.getDay()]
|
|
}
|
|
if (isEmpty(week)) {
|
|
week = ''
|
|
}
|
|
return datetime + week
|
|
}
|
|
|
|
function formateText(text, length) {
|
|
if (!text) {
|
|
return ''
|
|
}
|
|
if (text.length <= length) {
|
|
return text
|
|
}
|
|
return text.substring(0, length) + '...'
|
|
}
|
|
|
|
function isVideoUrl(url){
|
|
if(url && url.indexOf('.mp4') >= 0){
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
module.exports = {
|
|
formatePrice: formatePrice,
|
|
formateWeight: formateWeight,
|
|
formateDate: formateDate,
|
|
formateText: formateText,
|
|
isVideoUrl: isVideoUrl
|
|
}
|