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.
106 lines
2.1 KiB
106 lines
2.1 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 formateTimes(text, start, end) {
|
|
if (!text) {
|
|
return ''
|
|
}
|
|
if (text.length <= end) {
|
|
return text
|
|
}
|
|
return text.substring(start, end)
|
|
}
|
|
|
|
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 ''
|
|
}
|
|
time = time.replace(getRegExp('-', 'g'), '/')
|
|
var datetime = getDate(time.trim())
|
|
if (getDate().toString().substring(3, 15) === datetime.toString().substring(3, 15)) {
|
|
return time.substring(11, 16)
|
|
} else {
|
|
return formateText(time, 10)
|
|
}
|
|
}
|
|
|
|
function infoColor(time){
|
|
if (isEmpty(time)) {
|
|
return ''
|
|
}
|
|
time = time.replace(getRegExp('-', 'g'), '/')
|
|
var datetime = getDate(time.trim())
|
|
if (getDate().toString().substring(3, 15) === datetime.toString().substring(3, 15)) {
|
|
return 'text-red'
|
|
} else {
|
|
return 'text-black'
|
|
}
|
|
}
|
|
|
|
function checkPrice(price){
|
|
if (isEmpty(price)) {
|
|
return false
|
|
}
|
|
return Number(price) !== 0
|
|
}
|
|
|
|
module.exports = {
|
|
formateDate: formateDate,
|
|
formateText: formateText,
|
|
formateTimes: formateTimes,
|
|
colorText: colorText,
|
|
floatImage: floatImage,
|
|
infoTime: infoTime,
|
|
infoColor: infoColor,
|
|
checkPrice: checkPrice
|
|
}
|