纸通宝小程序
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.
 

101 lines
1.9 KiB

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 week = ''
if (date.toString().substring(0, 15) === today.toString().substring(0, 15)) {
week = '(今天)'
} else if (date.getTime() > today.getTime()) {
week = '(明天)'
}
return week + datetime
}
function formateText(text, length) {
if (!text) {
return ''
}
if (text.length <= length) {
return text
}
return text.substring(0, length)
}
function colorText(price) {
if(!price || price == 0){
return 'text-gray'
}
if(price > 0){
return 'text-red'
}
if(price < 0){
return 'text-green'
}
}
function floatImage(price) {
if(!price || price == 0){
return 'text-gray'
}
if(price > 0){
return '/assets/image/icon-up.png'
}
if(price < 0){
return '/assets/image/icon-down.png'
}
}
function infoTime(time){
if (isEmpty(time)) {
return ''
}
var oneday = 24 * 60 * 60 * 1000
time = time.replace(getRegExp('/\s/g', 'g'), '')
var datetime = getDate(time.trim())
var gap = getDate().getTime() - datetime.getTime()
if (gap > oneday) {
return formateText(time, 10)
} else {
return time.substring(11, 16)
}
}
function infoColor(time){
if (isEmpty(time)) {
return ''
}
var oneday = 24 * 60 * 60 * 1000
time = time.replace(getRegExp('/\s/g', 'g'), '')
var datetime = getDate(time.trim())
var gap = getDate().getTime() - datetime.getTime()
if (gap > oneday) {
return 'text-black'
} else {
return 'text-red'
}
}
function checkPrice(price){
if (isEmpty(price)) {
return false
}
return Number(price) !== 0
}
module.exports = {
formateDate: formateDate,
formateText: formateText,
colorText: colorText,
floatImage: floatImage,
infoTime: infoTime,
infoColor: infoColor,
checkPrice: checkPrice
}